New label fixes.

This commit is contained in:
Dmitry Khomutov 2017-12-10 11:51:48 +07:00
parent 6fcfa3668a
commit eb55474ff4
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
3 changed files with 22 additions and 11 deletions

View file

@ -118,7 +118,7 @@ class Builder implements LoggerAwareInterface
);
$this->interpolator = new BuildInterpolator();
$this->buildErrorWriter = new BuildErrorWriter($this->build->getId());
$this->buildErrorWriter = new BuildErrorWriter($this->build->getProjectId(), $this->build->getId());
}
/**

View file

@ -270,22 +270,27 @@ class BuildErrorStore extends Store
/**
* Check if a build error is new.
*
* @param string $hash
* @param integer $projectId
* @param string $hash
*
* @return boolean
*/
public function getIsNewError($hash)
public function getIsNewError($projectId, $hash)
{
$query = 'SELECT COUNT(*) AS {{total}} FROM {{build_error}} WHERE {{hash}} = :hash';
$query = '
SELECT COUNT(*) AS {{total}} FROM {{build_error}} AS be
LEFT JOIN {{build}} AS b ON be.build_id = b.id
WHERE be.hash = :hash AND b.project_id = :project';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':project', $projectId);
$stmt->bindValue(':hash', $hash);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
return (0 === $res['total']);
return (0 === (integer)$res['total']);
}
return true;

View file

@ -17,6 +17,11 @@ class BuildErrorWriter
*/
protected $buildId;
/**
* @var integer
*/
protected $projectId;
/**
* @var array
*/
@ -30,14 +35,15 @@ class BuildErrorWriter
protected $bufferSize;
/**
* BuildErrorWriter constructor.
*
* @param int $buildId
* @param integer $projectId
* @param integer $buildId
*/
public function __construct($buildId)
public function __construct($projectId, $buildId)
{
$this->bufferSize = (integer)Config::getInstance()->get('php-censor.build.writer_buffer_size', 500);
$this->buildId = $buildId;
$this->projectId = $projectId;
$this->buildId = $buildId;
}
/**
@ -85,7 +91,7 @@ class BuildErrorWriter
'line_end' => !is_null($lineEnd) ? (int)$lineEnd : null,
'create_date' => $createdDate->format('Y-m-d H:i:s'),
'hash' => $hash,
'is_new' => (integer)$errorStore->getIsNewError($hash),
'is_new' => $errorStore->getIsNewError($this->projectId, $hash) ? 1 : 0,
];
if (count($this->errors) >= $this->bufferSize) {