コード例 #1
0
ファイル: Storage.php プロジェクト: havvg/Sismo
 public function updateProject(Project $project)
 {
     $stmt = $this->db->prepare('INSERT OR REPLACE INTO project (slug, name, repository, branch, command, url_pattern) VALUES (:slug, :name, :repository, :branch, :command, :url_pattern)');
     $stmt->bindValue(':slug', $project->getSlug(), SQLITE3_TEXT);
     $stmt->bindValue(':name', $project->getName(), SQLITE3_TEXT);
     $stmt->bindValue(':repository', $project->getRepository(), SQLITE3_TEXT);
     $stmt->bindValue(':branch', $project->getBranch(), SQLITE3_TEXT);
     $stmt->bindValue(':command', $project->getCommand(), SQLITE3_TEXT);
     $stmt->bindValue(':url_pattern', $project->getUrlPattern(), SQLITE3_TEXT);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to save project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     // related commits
     $stmt = $this->db->prepare('SELECT sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug ORDER BY build_date DESC LIMIT 100');
     $stmt->bindValue(':slug', $project->getSlug(), SQLITE3_TEXT);
     if (false === ($results = $stmt->execute())) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to get latest commit for project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     $commits = array();
     while ($result = $results->fetchArray(\SQLITE3_ASSOC)) {
         $commits[] = $this->createCommit($project, $result);
     }
     $project->setCommits($commits);
     // project building?
     $stmt = $this->db->prepare('SELECT COUNT(*) AS count FROM `commit` WHERE slug = :slug AND status = "building"');
     $stmt->bindValue(':slug', $project->getSlug(), SQLITE3_TEXT);
     $building = false;
     if (false !== ($result = $stmt->execute())) {
         if (false !== ($result = $result->fetchArray(\SQLITE3_ASSOC))) {
             if ($result['count'] > 0) {
                 $building = true;
             }
         }
     }
     $project->setBuilding($building);
 }
コード例 #2
0
ファイル: ProjectTest.php プロジェクト: rouffj/Sismo
 public function testUrlPattern()
 {
     $project = new Project('Twig Local');
     $project->setUrlPattern('https://github.com/fabpot/Twig/commit/%commit%');
     $this->assertEquals('https://github.com/fabpot/Twig/commit/%commit%', $project->getUrlPattern());
 }
コード例 #3
0
ファイル: PdoStorage.php プロジェクト: hyperlator/Sismo
 /**
  * Create or update the information of a project.
  *
  * If the project is already available, the information of the existing project will be updated.
  *
  * @param Project $project The project to create or update.
  *
  * @return StorageInterface $this
  */
 public function updateProject(Project $project)
 {
     $stmt = $this->db->prepare('SELECT COUNT(*) FROM project WHERE slug = :slug');
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to verify existence of project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     if ($stmt->fetchColumn(0)) {
         $stmt = $this->db->prepare('UPDATE project SET slug = :slug, name = :name, repository = :repository, branch = :branch, command = :command, url_pattern = :url_pattern WHERE slug = :slug');
     } else {
         $stmt = $this->db->prepare('INSERT INTO project (slug, name, repository, branch, command, url_pattern) VALUES (:slug, :name, :repository, :branch, :command, :url_pattern)');
     }
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     $stmt->bindValue(':name', $project->getName(), \PDO::PARAM_STR);
     $stmt->bindValue(':repository', $project->getRepository(), \PDO::PARAM_STR);
     $stmt->bindValue(':branch', $project->getBranch(), \PDO::PARAM_STR);
     $stmt->bindValue(':command', $project->getCommand(), \PDO::PARAM_STR);
     $stmt->bindValue(':url_pattern', $project->getUrlPattern(), \PDO::PARAM_STR);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to save project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     // related commits
     $stmt = $this->db->prepare('SELECT sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug ORDER BY `status` = "building" DESC, build_date DESC LIMIT 100');
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to get latest commit for project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     $commits = array();
     while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $commits[] = $this->createCommit($project, $result);
     }
     $project->setCommits($commits);
     // project building?
     $stmt = $this->db->prepare('SELECT COUNT(*) AS count FROM `commit` WHERE slug = :slug AND status = "building"');
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     $building = false;
     if ($stmt->execute() and intval($stmt->fetchColumn(0))) {
         $building = true;
     }
     $project->setBuilding($building);
 }