From 49db1a26bae7a0998bb81f2e3dd2a62037a2c86d Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 27 Apr 2016 16:40:55 +0100 Subject: [PATCH] Make sure we always show the correct error count on the build errors tab. --- PHPCI/Controller/BuildController.php | 2 +- PHPCI/Store/BuildErrorStore.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index f68a739c..df8778f7 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -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'); diff --git a/PHPCI/Store/BuildErrorStore.php b/PHPCI/Store/BuildErrorStore.php index 815a4d18..c2d32468 100644 --- a/PHPCI/Store/BuildErrorStore.php +++ b/PHPCI/Store/BuildErrorStore.php @@ -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(); + } + } }