Skip to content
Permalink
Browse files

Add support for marking errors as new.

  • Loading branch information...
Dan Cryer
Dan Cryer committed Oct 27, 2017
1 parent 358fc7c commit 2a99f10a24340109042eb1d603171cea5e42aee5
@@ -0,0 +1,36 @@
<?php
use Phinx\Migration\AbstractMigration;
class ErrorHash extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$errors = $this->table('build_error');
$errors->addColumn('hash', 'string', ['limit' => 32, 'null' => true, 'default' => null]);
$errors->addColumn('is_new', 'boolean');
$errors->save();
}
}
@@ -42,6 +42,8 @@ class BuildErrorBase extends Model
'severity' => null,
'message' => null,
'created_date' => null,
'hash' => null,
'is_new' => null,
);
/**
@@ -58,6 +60,8 @@ class BuildErrorBase extends Model
'severity' => 'getSeverity',
'message' => 'getMessage',
'created_date' => 'getCreatedDate',
'hash' => 'getHash',
'is_new' => 'getIsNew',
// Foreign key getters:
'Build' => 'getBuild',
@@ -77,6 +81,8 @@ class BuildErrorBase extends Model
'severity' => 'setSeverity',
'message' => 'setMessage',
'created_date' => 'setCreatedDate',
'hash' => 'setHash',
'is_new' => 'setIsNew',
// Foreign key setters:
'Build' => 'setBuild',
@@ -135,6 +141,16 @@ class BuildErrorBase extends Model
'type' => 'datetime',
'default' => null,
),
'hash' => array(
'type' => 'varchar',
'length' => 32,
'default' => null,
),
'is_new' => array(
'type' => 'tiynint',
'length' => 1,
'default' => 0,
),
);
/**
@@ -270,6 +286,30 @@ public function getCreatedDate()
return $rtn;
}
/**
* Get the value of Hash / hash.
*
* @return string
*/
public function getHash()
{
$rtn = $this->data['hash'];
return $rtn;
}
/**
* Get the value of IsNew / is_new.
*
* @return string
*/
public function getIsNew()
{
$rtn = $this->data['is_new'] ? true : false;
return $rtn;
}
/**
* Set the value of Id / id.
*
@@ -444,6 +484,45 @@ public function setCreatedDate($value)
$this->_setModified('created_date');
}
/**
* Set the value of Hash / hash.
*
* Must not be null.
* @param $value string
*/
public function setHash($value)
{
$this->_validateNotNull('Hash', $value);
$this->_validateString('Hash', $value);
if ($this->data['hash'] === $value) {
return;
}
$this->data['hash'] = $value;
$this->_setModified('hash');
}
/**
* Set the value of IsNew / is_new.
*
* Must not be null.
* @param $value bool
*/
public function setIsNew($value)
{
$value = ($value == true) ? 1 : 0;
if ($this->data['is_new'] === $value) {
return;
}
$this->data['is_new'] = $value;
$this->_setModified('is_new');
}
/**
* Get the Build model for this BuildError by Id.
*
@@ -241,6 +241,7 @@ public function reportError(
$error->setFile($file);
$error->setLineStart($lineStart);
$error->setLineEnd($lineEnd);
$error->hash();
return Factory::getStore('BuildError')->save($error);
}
@@ -6,7 +6,9 @@
namespace PHPCI\Model;
use b8\Store\Factory;
use PHPCI\Model\Base\BuildErrorBase;
use PHPCI\Store;
/**
* BuildError Model
@@ -60,4 +62,17 @@ public function getSeverityClass()
return 'default';
}
}
public function hash()
{
$hash = $this->getPlugin() . '|' . $this->getFile() . '|' . $this->getLineStart();
$hash .= '|' . $this->getLineEnd() . '|' . $this->getSeverity() . '|' . $this->getMessage();
$this->setHash(md5($hash));
/** @var Store\BuildErrorStore $errorStore */
$errorStore = Factory::getStore('BuildError');
$this->setIsNew($errorStore->getIsNewError($this->getHash()));
}
}
@@ -77,4 +77,24 @@ public function getErrorTotalForBuild($buildId)
return array();
}
}
/**
* Check if a build error is new.
*/
public function getIsNewError($hash)
{
$query = 'SELECT COUNT(*) AS total FROM build_error
WHERE `hash` = :errorhash';
$stmt = Database::getConnection('read')->prepare($query);
$stmt->bindValue(':errorhash', $hash, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
return $res['total'] == 0;
} else {
return true;
}
}
}
@@ -12,6 +12,11 @@ foreach ($errors as $error):
?>

<tr class="bg-<?php print $error->getSeverityClass(); ?>">
<td>
<?php if ($error->getIsNew()): ?>
<span class="label label-danger">New</span>
<?php endif; ?>
</td>
<td>
<span class="label label-<?php print $error->getSeverityClass(); ?>">
<?php print Lang::get($error->getSeverityString()); ?>
@@ -141,6 +141,7 @@
<table class="errors-table table table-hover dataTable">
<thead>
<tr>
<th></th>
<th>Severity</th>
<th>Plugin</th>
<th>File</th>
Oops, something went wrong.

0 comments on commit 2a99f10

Please sign in to comment.
You can’t perform that action at this time.