Fixed BuildFactory::getBuildById. Issue #162.

This commit is contained in:
Dmitry Khomutov 2018-03-08 23:20:05 +07:00
parent 3b3557b8b5
commit 2bbdd8c393
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
3 changed files with 12 additions and 19 deletions

View file

@ -13,18 +13,16 @@ use PHPCensor\Model\Build;
class BuildFactory class BuildFactory
{ {
/** /**
* @param $buildId * @param integer $buildId
* *
* @throws \Exception * @return Build|null
*
* @return Build
*/ */
public static function getBuildById($buildId) public static function getBuildById($buildId)
{ {
$build = Factory::getStore('Build')->getById($buildId); $build = Factory::getStore('Build')->getById($buildId);
if (empty($build)) { if (empty($build)) {
throw new \Exception('Build ID ' . $buildId . ' does not exist.'); return null;
} }
return self::getBuild($build); return self::getBuild($build);

View file

@ -62,13 +62,9 @@ class BuildController extends Controller
$severity = null; $severity = null;
} }
try { $build = BuildFactory::getBuildById($buildId);
$build = BuildFactory::getBuildById($buildId);
} catch (\Exception $ex) {
$build = null;
}
if (empty($build)) { if (!$build) {
throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
} }
@ -246,7 +242,7 @@ class BuildController extends Controller
$copy = BuildFactory::getBuildById($buildId); $copy = BuildFactory::getBuildById($buildId);
$project = b8\Store\Factory::getStore('Project')->getByPrimaryKey($copy->getProjectId()); $project = b8\Store\Factory::getStore('Project')->getByPrimaryKey($copy->getProjectId());
if (empty($copy) || $project->getArchived()) { if (!$copy || $project->getArchived()) {
throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
} }
@ -271,7 +267,7 @@ class BuildController extends Controller
$build = BuildFactory::getBuildById($buildId); $build = BuildFactory::getBuildById($buildId);
if (empty($build)) { if (!$build) {
throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
} }
@ -348,10 +344,10 @@ class BuildController extends Controller
public function ajaxMeta($buildId) public function ajaxMeta($buildId)
{ {
$build = BuildFactory::getBuildById($buildId); $build = BuildFactory::getBuildById($buildId);
$key = $this->getParam('key', null); $key = $this->getParam('key', null);
$numBuilds = $this->getParam('num_builds', 1); $numBuilds = $this->getParam('num_builds', 1);
$data = null; $data = null;
if ($key && $build) { if ($key && $build) {
$data = $this->buildStore->getMeta($key, $build->getProjectId(), $buildId, $build->getBranch(), $numBuilds); $data = $this->buildStore->getMeta($key, $build->getProjectId(), $buildId, $build->getBranch(), $numBuilds);

View file

@ -96,9 +96,8 @@ class BuildWorker
$this->logger->addInfo('Received build #'.$jobData['build_id'].' from Beanstalkd'); $this->logger->addInfo('Received build #'.$jobData['build_id'].' from Beanstalkd');
try { $build = BuildFactory::getBuildById($jobData['build_id']);
$build = BuildFactory::getBuildById($jobData['build_id']); if (!$build) {
} catch (\Exception $ex) {
$this->logger->addWarning('Build #' . $jobData['build_id'] . ' does not exist in the database.'); $this->logger->addWarning('Build #' . $jobData['build_id'] . ' does not exist in the database.');
$this->pheanstalk->delete($job); $this->pheanstalk->delete($job);
continue; continue;