From eb55474ff40ba322a7efc7296eb50f1d1faf700b Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 10 Dec 2017 11:51:48 +0700 Subject: [PATCH] New label fixes. --- src/PHPCensor/Builder.php | 2 +- src/PHPCensor/Store/BuildErrorStore.php | 13 +++++++++---- src/PHPCensor/Store/BuildErrorWriter.php | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index 20ec48bd..16c15bce 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -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()); } /** diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/PHPCensor/Store/BuildErrorStore.php index 2a62a81c..f6f14c93 100644 --- a/src/PHPCensor/Store/BuildErrorStore.php +++ b/src/PHPCensor/Store/BuildErrorStore.php @@ -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; diff --git a/src/PHPCensor/Store/BuildErrorWriter.php b/src/PHPCensor/Store/BuildErrorWriter.php index 4ad68097..b104613a 100644 --- a/src/PHPCensor/Store/BuildErrorWriter.php +++ b/src/PHPCensor/Store/BuildErrorWriter.php @@ -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) {