Added filtration for errors by severity and plugin. Issue #85.

This commit is contained in:
Dmitry Khomutov 2017-10-29 21:26:43 +07:00
commit 42888630e7
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
8 changed files with 253 additions and 36 deletions

View file

@ -61,18 +61,27 @@ class BuildErrorStore extends Store
* @param integer $buildId
* @param integer $limit
* @param integer $offset
* @param string $plugin
* @param integer $severity
*
* @return array
*
* @throws HttpException
*/
public function getByBuildId($buildId, $limit = null, $offset = 0)
public function getByBuildId($buildId, $limit = null, $offset = 0, $plugin = null, $severity = null)
{
if (is_null($buildId)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id ORDER BY plugin, severity';
$query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id';
if ($plugin) {
$query .= ' AND {{plugin}} = :plugin';
}
if (null !== $severity) {
$query .= ' AND {{severity}} = :severity';
}
$query .= ' ORDER BY plugin, severity';
if (null !== $limit) {
$query .= ' LIMIT :limit';
}
@ -81,6 +90,12 @@ class BuildErrorStore extends Store
}
$stmt = Database::getConnection()->prepareCommon($query);
$stmt->bindValue(':build_id', $buildId);
if ($plugin) {
$stmt->bindValue(':plugin', $plugin, \PDO::PARAM_STR);
}
if (null !== $severity) {
$stmt->bindValue(':severity', (integer)$severity, \PDO::PARAM_INT);
}
if (null !== $limit) {
$stmt->bindValue(':limit', (integer)$limit, \PDO::PARAM_INT);
}
@ -108,17 +123,31 @@ class BuildErrorStore extends Store
* Gets the total number of errors for a given build.
*
* @param integer $buildId
* @param string $plugin
* @param integer $severity
*
* @return array
*/
public function getErrorTotalForBuild($buildId)
public function getErrorTotalForBuild($buildId, $plugin = null, $severity = null)
{
$query = 'SELECT COUNT(*) AS {{total}} FROM {{build_error}}
WHERE {{build_id}} = :build';
if ($plugin) {
$query .= ' AND {{plugin}} = :plugin';
}
if (null !== $severity) {
$query .= ' AND {{severity}} = :severity';
}
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId, \PDO::PARAM_INT);
if ($plugin) {
$stmt->bindValue(':plugin', $plugin, \PDO::PARAM_STR);
}
if (null !== $severity) {
$stmt->bindValue(':severity', (integer)$severity, \PDO::PARAM_INT);
}
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
@ -127,4 +156,62 @@ class BuildErrorStore extends Store
return [];
}
}
/**
* @param integer $buildId
*
* @return array
*/
public function getKnownPlugins($buildId)
{
$query = 'SELECT DISTINCT {{plugin}} from {{build_error}} WHERE {{build_id}} = :build';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return $item['plugin'];
};
$rtn = array_map($map, $res);
return $rtn;
} else {
return [];
}
}
/**
* @param integer $buildId
* @param string $plugin
*
* @return array
*/
public function getKnownSeverities($buildId, $plugin = '')
{
$query = 'SELECT DISTINCT {{severity}} from {{build_error}} WHERE {{build_id}} = :build';
if ($plugin) {
$query .= ' AND {{plugin}} = :plugin';
}
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId);
if ($plugin) {
$stmt->bindValue(':plugin', $plugin);
}
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return (integer)$item['severity'];
};
$rtn = array_map($map, $res);
return $rtn;
} else {
return [];
}
}
}