BUGFIX: Handle missing configuration in hook

* Don't break if no configuration exists, instead improve logging.
This commit is contained in:
Daniel Siepmann 2017-01-12 14:21:41 +01:00
parent 24deb93b4f
commit 1878209b51
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
2 changed files with 33 additions and 8 deletions

View file

@ -40,6 +40,7 @@ class ConfigurationContainer implements ConfigurationContainerInterface
* Inject settings via ConfigurationManager.
*
* @param ConfigurationManagerInterface $configurationManager
* @throws NoConfigurationException
*/
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
{
@ -49,7 +50,7 @@ class ConfigurationContainer implements ConfigurationContainerInterface
'search'
);
if ($this->settings === null) {
$this->settings = [];
throw new NoConfigurationException('Could not fetch configuration.', 1484226842);
}
}

View file

@ -20,6 +20,8 @@ namespace Leonmrni\SearchCore\Hook;
* 02110-1301, USA.
*/
use Leonmrni\SearchCore\Configuration\NoConfigurationException;
use Leonmrni\SearchCore\Domain\Service\DataHandler as OwnDataHandler;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler;
use TYPO3\CMS\Core\Log\LogManager;
@ -27,7 +29,6 @@ use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use Leonmrni\SearchCore\Domain\Service\DataHandler as OwnDataHandler;
/**
* Wrapper for TYPO3 Hooks to internal API.
@ -55,8 +56,13 @@ class DataHandler implements Singleton
{
$this->dataHandler = $dataHandler;
if ($this->dataHandler === null) {
try {
$this->dataHandler = GeneralUtility::makeInstance(ObjectManager::class)
->get(OwnDataHandler::class);
} catch (NoConfigurationException $e) {
// We have no configuration. That's fine, hooks will not be
// executed due to check for existing DataHandler.
}
}
$this->logger = $logger;
@ -76,8 +82,8 @@ class DataHandler implements Singleton
*/
public function processCmdmap_deleteAction($table, $uid)
{
if (! $this->shouldProcessTable($table)) {
$this->logger->debug('Delete not processed, cause table is not allowed.', [$table]);
if (! $this->shouldProcessHookForTable($table)) {
$this->logger->debug('Delete not processed.', [$table, $uid]);
return false;
}
@ -98,8 +104,8 @@ class DataHandler implements Singleton
*/
public function processDatamap_afterDatabaseOperations($status, $table, $uid, array $fieldArray, CoreDataHandler $dataHandler)
{
if (! $this->shouldProcessTable($table)) {
$this->logger->debug('Database update not processed, cause table is not allowed.', [$table]);
if (! $this->shouldProcessHookForTable($table)) {
$this->logger->debug('Database update not processed.', [$table, $uid]);
return false;
}
@ -124,6 +130,24 @@ class DataHandler implements Singleton
return false;
}
/**
* @param string $table
* @return bool
*/
protected function shouldProcessHookForTable($table)
{
if ($this->dataHandler === null) {
$this->logger->debug('Datahandler could not be setup.');
return false;
}
if (! $this->shouldProcessTable($table)) {
$this->logger->debug('Table is not allowed.', [$table]);
return false;
}
return true;
}
/**
* @param string $table
* @return bool