From 1304ca29f78e6630a7f988907a2275ffd61badb1 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 9 Nov 2017 23:18:10 +0700 Subject: [PATCH] Fixed links to Errors tab from Information tab (Summary). --- public/assets/js/build-plugins/summary.js | 2 +- src/PHPCensor/Controller/BuildController.php | 4 ++-- src/PHPCensor/Store/BuildErrorStore.php | 10 +++++----- src/PHPCensor/Store/BuildStore.php | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/public/assets/js/build-plugins/summary.js b/public/assets/js/build-plugins/summary.js index d6e50a4d..a38fb8ed 100644 --- a/public/assets/js/build-plugins/summary.js +++ b/public/assets/js/build-plugins/summary.js @@ -59,7 +59,7 @@ var SummaryPlugin = ActiveBuild.UiPlugin.extend({ duration = data.started ? ((data.ended || Math.floor(Date.now() / 1000)) - data.started) : '-'; var pluginName = Lang.get(plugin); - if ('test' === stage && 2 < data.status) { + if (0 < data.errors) { pluginName = '' + Lang.get(plugin) + ''; } tbody.append( diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index 5e9a68e4..fc2350c9 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -189,8 +189,8 @@ class BuildController extends Controller $errorView->build = $build; $errorView->errors = $errors['items']; - $data['errors'] = (integer)$errorStore->getErrorTotalForBuild($build->getId(), $plugin, $severity); - $data['errors_total'] = (integer)$errorStore->getErrorTotalForBuild($build->getId()); + $data['errors'] = $errorStore->getErrorTotalForBuild($build->getId(), $plugin, $severity); + $data['errors_total'] = $errorStore->getErrorTotalForBuild($build->getId()); $data['error_html'] = $errorView->render(); return $data; diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/PHPCensor/Store/BuildErrorStore.php index c37fc44c..05bcc6eb 100644 --- a/src/PHPCensor/Store/BuildErrorStore.php +++ b/src/PHPCensor/Store/BuildErrorStore.php @@ -137,12 +137,11 @@ class BuildErrorStore extends Store * @param string $plugin * @param integer $severity * - * @return array + * @return integer */ public function getErrorTotalForBuild($buildId, $plugin = null, $severity = null) { - $query = 'SELECT COUNT(*) AS {{total}} FROM {{build_error}} - WHERE {{build_id}} = :build'; + $query = 'SELECT COUNT(*) AS {{total}} FROM {{build_error}} WHERE {{build_id}} = :build'; if ($plugin) { $query .= ' AND {{plugin}} = :plugin'; } @@ -162,9 +161,10 @@ class BuildErrorStore extends Store if ($stmt->execute()) { $res = $stmt->fetch(\PDO::FETCH_ASSOC); - return $res['total']; + + return (integer)$res['total']; } else { - return []; + return 0; } } diff --git a/src/PHPCensor/Store/BuildStore.php b/src/PHPCensor/Store/BuildStore.php index 8c9197b2..868249e6 100644 --- a/src/PHPCensor/Store/BuildStore.php +++ b/src/PHPCensor/Store/BuildStore.php @@ -425,9 +425,23 @@ class BuildStore extends Store if ($stmt->execute()) { $rtn = $stmt->fetchAll(\PDO::FETCH_ASSOC); + /** @var \PHPCensor\Store\BuildErrorStore $errorStore */ + $errorStore = Factory::getStore('BuildError'); + $rtn = array_reverse($rtn); - $rtn = array_map(function ($item) { + $rtn = array_map(function ($item) use ($key, $errorStore, $buildId) { $item['meta_value'] = json_decode($item['meta_value'], true); + if ('plugin-summary' === $key) { + foreach ($item['meta_value'] as $stage => $stageData) { + foreach ($stageData as $plugin => $pluginData) { + $item['meta_value'][$stage][$plugin]['errors'] = $errorStore->getErrorTotalForBuild( + $buildId, + $plugin + ); + } + } + } + return $item; }, $rtn);