Merge branch 'feature-meta-fix'
This commit is contained in:
commit
260911d62d
|
@ -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 = '<a href="' + window.APP_URL + 'build/view/' + ActiveBuild.buildId + '?plugin=' + plugin + '#errors">' + Lang.get(plugin) + '</a>';
|
||||
}
|
||||
tbody.append(
|
||||
|
|
|
@ -53,7 +53,7 @@ abstract class Store
|
|||
$manualWheres = [],
|
||||
$whereType = 'AND'
|
||||
) {
|
||||
$query = 'SELECT * FROM {{' . $this->tableName . '}}';
|
||||
$query = 'SELECT * FROM {{' . $this->tableName . '}}';
|
||||
$countQuery = 'SELECT COUNT(*) AS {{count}} FROM {{' . $this->tableName . '}}';
|
||||
|
||||
$wheres = [];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class BuildMetaStore extends Store
|
|||
public function getById($id, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($id)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
throw new HttpException('id passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM {{build_meta}} WHERE {{id}} = :id LIMIT 1';
|
||||
|
@ -66,6 +66,38 @@ class BuildMetaStore extends Store
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $buildId
|
||||
* @param string $key
|
||||
*
|
||||
* @return null|BuildMeta
|
||||
*
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function getByKey($buildId, $key)
|
||||
{
|
||||
if (is_null($buildId)) {
|
||||
throw new HttpException('buildId passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
if (!$key) {
|
||||
throw new HttpException('key passed to ' . __FUNCTION__ . ' cannot be empty.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM {{build_meta}} WHERE {{build_id}} = :build_id AND {{meta_key}} = :meta_key LIMIT 1';
|
||||
$stmt = Database::getConnection()->prepareCommon($query);
|
||||
$stmt->bindValue(':build_id', $buildId);
|
||||
$stmt->bindValue(':meta_key', $key);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new BuildMeta($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple BuildMeta by BuildId.
|
||||
*
|
||||
|
@ -83,7 +115,6 @@ class BuildMetaStore extends Store
|
|||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
|
||||
$query = 'SELECT * FROM {{build_meta}} WHERE {{build_id}} = :build_id LIMIT :limit';
|
||||
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
|
||||
$stmt->bindValue(':build_id', $buildId);
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
namespace PHPCensor\Store;
|
||||
|
||||
use b8\Database;
|
||||
use b8\Store\Factory;
|
||||
use PHPCensor\Model\Build;
|
||||
use b8\Exception\HttpException;
|
||||
use PHPCensor\Model\BuildMeta;
|
||||
use PHPCensor\Store;
|
||||
|
||||
/**
|
||||
|
@ -245,7 +247,7 @@ class BuildStore extends Store
|
|||
*/
|
||||
public function getAllProjectsLatestBuilds($limit_by_project = 5, $limit_all = 10)
|
||||
{
|
||||
// dont fetch log field - contain many data
|
||||
// don't fetch log field - contain many data
|
||||
$query = '
|
||||
SELECT
|
||||
{{id}},
|
||||
|
@ -393,7 +395,7 @@ class BuildStore extends Store
|
|||
$query = 'SELECT bm.build_id, bm.meta_key, bm.meta_value
|
||||
FROM {{build_meta}} AS {{bm}}
|
||||
LEFT JOIN {{build}} AS {{b}} ON b.id = bm.build_id
|
||||
WHERE bm.meta_key = :key AND b.project_id = :projectId';
|
||||
WHERE bm.meta_key = :key AND b.project_id = :projectId';
|
||||
|
||||
// If we're getting comparative meta data, include previous builds
|
||||
// otherwise just include the specified build ID:
|
||||
|
@ -423,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);
|
||||
|
||||
|
@ -445,24 +461,20 @@ class BuildStore extends Store
|
|||
* @param integer $buildId
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function setMeta($buildId, $key, $value)
|
||||
{
|
||||
$cols = '{{build_id}}, {{meta_key}}, {{meta_value}}';
|
||||
$query = 'INSERT INTO {{build_meta}} ('.$cols.') VALUES (:buildId, :key, :value)';
|
||||
|
||||
$stmt = Database::getConnection('read')->prepareCommon($query);
|
||||
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
|
||||
$stmt->bindValue(':buildId', (int)$buildId, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(':value', $value, \PDO::PARAM_STR);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
/** @var BuildMetaStore $store */
|
||||
$store = Factory::getStore('BuildMeta');
|
||||
$meta = $store->getByKey($buildId, $key);
|
||||
if (is_null($meta)) {
|
||||
$meta = new BuildMeta();
|
||||
$meta->setBuildId($buildId);
|
||||
$meta->setMetaKey($key);
|
||||
}
|
||||
$meta->setMetaValue($value);
|
||||
|
||||
$store->save($meta);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue