示例#1
0
 /**
  * @todo a "previous build" is actually any build with the same host and with a status of "running"
  *       or not: we might need to be able to find a previousBuild by multiple criterias. For example
  *       when we want to approximate the time a build will take based on previous builds, a previous
  *       build is actually the previous build "running" or "obsolete" with the same branch and project
  *
  * @param Build   $build
  * @param boolean $demo
  *
  * @return null|App\Model\Build
  */
 public function findPreviousBuild(Build $build, $demo = false)
 {
     if ($build->isDemo() && $demo) {
         return $this->findPreviousDemoBuild($build);
     }
     $query = $this->createQueryBuilder('b')->select()->where('b.project = ?1')->andWhere('b.ref = ?2')->andWhere('b.status IN(?3)')->setParameters([1 => $build->getProject()->getId(), 2 => $build->getRef(), 3 => [Build::STATUS_RUNNING, Build::STATUS_OBSOLETE]])->setMaxResults(1)->orderBy('b.createdAt', 'DESC')->getQuery();
     try {
         return $query->getSingleResult();
     } catch (NoResultException $e) {
         return null;
     }
 }