Make sure we always show the correct error count on the build errors tab.

This commit is contained in:
Dan Cryer 2016-04-27 16:40:55 +01:00
parent 77e9710d09
commit 49db1a26ba
No known key found for this signature in database
GPG key ID: 6030CBA5FE342813
2 changed files with 24 additions and 1 deletions

View file

@ -180,7 +180,7 @@ class BuildController extends \PHPCI\Controller
$errorView->build = $build;
$errorView->errors = $errors;
$data['errors'] = count($errors);
$data['errors'] = $errorStore->getErrorTotalForBuild($build->getId());
$data['error_html'] = $errorView->render();
$data['since'] = (new \DateTime())->format('Y-m-d H:i:s');

View file

@ -54,4 +54,27 @@ class BuildErrorStore extends BuildErrorStoreBase
return array();
}
}
/**
* Gets the total number of errors for a given build.
* @param $buildId
* @param string $since date string
* @return array
*/
public function getErrorTotalForBuild($buildId)
{
$query = 'SELECT COUNT(*) AS total FROM build_error
WHERE build_id = :build';
$stmt = Database::getConnection('read')->prepare($query);
$stmt->bindValue(':build', $buildId, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
return $res['total'];
} else {
return array();
}
}
}