Skip to content

Commit

Permalink
Merge branch 'add-error-type-to-is-exists-check' into 1.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Feb 12, 2018
2 parents 693ff47 + e14212e commit d610996
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions spec/Handler/Writer/DbSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
allow($resultSet)->toReceive('current')->andReturn(null);
allow(TableGateway::class)->toReceive('selectWith')->with($select)->andReturn($resultSet);

$actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri');
$actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri', 'E_NOTICE');
expect($actual)->toBe(false);

});
Expand Down Expand Up @@ -117,7 +117,7 @@
);
allow(TableGateway::class)->toReceive('selectWith')->with($select)->andReturn($resultSet);

$actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri');
$actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri', 'E_NOTICE');
expect($actual)->toBe(false);

});
Expand All @@ -143,7 +143,7 @@
);
allow(TableGateway::class)->toReceive('selectWith')->with($select)->andReturn($resultSet);

$actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri');
$actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri', 'E_NOTICE');
expect($actual)->toBe(true);

});
Expand Down
8 changes: 5 additions & 3 deletions src/Handler/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,20 @@ public function setServerRequestandRequestUri(ServerRequestInterface $request)
* @param int $errorLine
* @param string $errorMessage
* @param string $url
* @param string $errorType
*
* @throws RuntimeException when cannot connect to DB in the first place
*
* @return bool
*/
private function isExists($errorFile, $errorLine, $errorMessage, $url)
private function isExists($errorFile, $errorLine, $errorMessage, $url, $errorType)
{
$writers = $this->logger->getWriters()->toArray();
foreach ($writers as $writer) {
if ($writer instanceof Db) {
try {
$handlerWriterDb = new Writer\Db($writer, $this->configLoggingSettings, $this->logWritersConfig);
if ($handlerWriterDb->isExists($errorFile, $errorLine, $errorMessage, $url)) {
if ($handlerWriterDb->isExists($errorFile, $errorLine, $errorMessage, $url, $errorType)) {
return true;
}
break;
Expand Down Expand Up @@ -288,7 +289,8 @@ public function handleErrorException($e)
$collectedExceptionData['errorFile'],
$collectedExceptionData['errorLine'],
$collectedExceptionData['errorMessage'],
$this->serverUrl.$this->requestUri
$this->serverUrl.$this->requestUri,
$collectedExceptionData['errorType']
)
) {
return;
Expand Down
23 changes: 13 additions & 10 deletions src/Handler/Writer/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public function __construct(
* @param int $errorLine
* @param string $errorMessage
* @param string $errorUrl
* @param string $errorType
*
* @return bool
*/
public function isExists($errorFile, $errorLine, $errorMessage, $errorUrl)
public function isExists($errorFile, $errorLine, $errorMessage, $errorUrl, $errorType)
{
// db definition
$reflectionProperty = new ReflectionProperty($this->dbWriter, 'db');
Expand All @@ -60,20 +61,22 @@ public function isExists($errorFile, $errorLine, $errorMessage, $errorUrl)
$table = $writerConfig['options']['table'];

// columns definition
$timestamp = $writerConfig['options']['column']['timestamp'];
$message = $writerConfig['options']['column']['message'];
$file = $writerConfig['options']['column']['extra']['file'];
$line = $writerConfig['options']['column']['extra']['line'];
$url = $writerConfig['options']['column']['extra']['url'];
$timestamp = $writerConfig['options']['column']['timestamp'];
$message = $writerConfig['options']['column']['message'];
$file = $writerConfig['options']['column']['extra']['file'];
$line = $writerConfig['options']['column']['extra']['line'];
$url = $writerConfig['options']['column']['extra']['url'];
$error_type = $writerConfig['options']['column']['extra']['error_type'];

$tableGateway = new TableGateway($table, $db, null, new ResultSet());
$select = $tableGateway->getSql()->select();
$select->columns([$timestamp]);
$select->where([
$message => $errorMessage,
$line => $errorLine,
$url => $errorUrl,
$file => $errorFile,
$message => $errorMessage,
$line => $errorLine,
$url => $errorUrl,
$file => $errorFile,
$error_type => $errorType,
]);
$select->order($timestamp.' DESC');
$select->limit(1);
Expand Down

0 comments on commit d610996

Please sign in to comment.