Skip to content

Commit 404f3d2

Browse files
committed
[BUGFIX] Add check for database availability, resolves #6
1 parent 8b091be commit 404f3d2

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2018-02-18 Francois Suter <[email protected]>
2+
3+
* Added check for database availability, resolves #6
4+
15
2017-05-29 Francois Suter <[email protected]>
26

37
* Verified compatibility with TYPO3 8 LTS

Classes/Domain/Repository/EntryRepository.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ class EntryRepository implements SingletonInterface
5454
*/
5555
protected $numberOfRows = null;
5656

57+
/**
58+
* EntryRepository constructor.
59+
*
60+
* @throws \UnexpectedValueException
61+
*/
62+
public function __construct()
63+
{
64+
if ($this->getDatabaseConnection() === null) {
65+
throw new \UnexpectedValueException(
66+
'Database connection could not be established',
67+
1518984773
68+
);
69+
}
70+
}
71+
5772
/**
5873
* Returns all available records in the log table.
5974
*

Classes/Writer/DatabaseWriter.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,27 @@ class DatabaseWriter extends AbstractWriter
3333
* DatabaseWriter constructor.
3434
*
3535
* @param Logger $logger
36+
* @throws \UnexpectedValueException
3637
*/
3738
public function __construct($logger)
3839
{
3940
parent::__construct($logger);
40-
$this->entryRepository = GeneralUtility::makeInstance(EntryRepository::class);
41-
$this->entryRepository->setExtensionConfiguration(
42-
$this->logger->getExtensionConfiguration()
43-
);
41+
try {
42+
$this->entryRepository = GeneralUtility::makeInstance(EntryRepository::class);
43+
$this->entryRepository->setExtensionConfiguration(
44+
$this->logger->getExtensionConfiguration()
45+
);
46+
}
47+
catch (\Exception $e) {
48+
throw new \UnexpectedValueException(
49+
sprintf(
50+
'Database writer is not available (Error: %s, Code: %s)',
51+
$e->getMessage(),
52+
$e->getCode()
53+
),
54+
1518984907
55+
);
56+
}
4457
}
4558

4659
/**

0 commit comments

Comments
 (0)