From f936d1f7c598e16b0b9efdba129ba0bce97c525f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20So=CC=88lch?= Date: Thu, 18 Oct 2018 11:56:22 +0200 Subject: [PATCH 1/2] [TASK] remove dblegacy --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 94d01dc..37e9e07 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,7 @@ "require": { "php": ">=7.0.0", "typo3/cms-core": ">= 7.6.0 < 10.0.0", - "ruflin/elastica": "~3.2", - "friendsoftypo3/typo3db-legacy": "^1.1.1" + "ruflin/elastica": "~3.2" }, "require-dev": { "phpunit/phpunit": "~6.4.4", From 0a9cdd5dce12c97e17ae8e989b2c0ec6fcc15118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20So=CC=88lch?= Date: Thu, 18 Oct 2018 15:21:25 +0200 Subject: [PATCH 2/2] [TASK] bugfixes and error removal --- .../Configuration/ConfigurationContainer.php | 12 +- Classes/Domain/Index/AbstractIndexer.php | 108 ++++++++++++------ ext_localconf.php | 7 +- 3 files changed, 83 insertions(+), 44 deletions(-) diff --git a/Classes/Configuration/ConfigurationContainer.php b/Classes/Configuration/ConfigurationContainer.php index aaf0ebb..aab35d9 100644 --- a/Classes/Configuration/ConfigurationContainer.php +++ b/Classes/Configuration/ConfigurationContainer.php @@ -20,8 +20,10 @@ namespace Codappix\SearchCore\Configuration; * 02110-1301, USA. */ +use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Core\Utility\ArrayUtility; +use TYPO3\CMS\Extbase\Utility\DebuggerUtility; /** * Container of all configurations for extension. @@ -60,8 +62,8 @@ class ConfigurationContainer implements ConfigurationContainerInterface */ public function get(string $path) { - $value = ArrayUtility::getValueByPath($this->settings, $path); - + $value = ArrayUtility::getValueByPath($this->settings, $path, '.'); + if ($value === null) { throw new InvalidArgumentException( 'The given configuration option "' . $path . '" does not exist.', @@ -78,6 +80,10 @@ class ConfigurationContainer implements ConfigurationContainerInterface */ public function getIfExists(string $path) { - return ArrayUtility::getValueByPath($this->settings, $path); + try { + return ArrayUtility::getValueByPath($this->settings, $path, '.'); + } catch (MissingArrayPathException $exception) { + return null; + } } } diff --git a/Classes/Domain/Index/AbstractIndexer.php b/Classes/Domain/Index/AbstractIndexer.php index b22c011..47459b0 100644 --- a/Classes/Domain/Index/AbstractIndexer.php +++ b/Classes/Domain/Index/AbstractIndexer.php @@ -1,4 +1,5 @@ logger = $logManager->getLogger(__CLASS__); } - + public function setIdentifier(string $identifier) { $this->identifier = $identifier; } - + public function __construct(ConnectionInterface $connection, ConfigurationContainerInterface $configuration) { $this->connection = $connection; $this->configuration = $configuration; } - + public function indexAllDocuments() { $this->logger->info('Start indexing'); @@ -81,24 +84,24 @@ abstract class AbstractIndexer implements IndexerInterface if ($records === null) { break; } - + foreach ($records as &$record) { $this->prepareRecord($record); } - + $this->logger->debug('Index records.', [$records]); $this->connection->addDocuments($this->getDocumentName(), $records); } $this->logger->info('Finish indexing'); } - + public function indexDocument(string $identifier) { $this->logger->info('Start indexing single record.', [$identifier]); try { - $record = $this->getRecord((int) $identifier); + $record = $this->getRecord((int)$identifier); $this->prepareRecord($record); - + $this->connection->addDocument($this->getDocumentName(), $record); } catch (NoRecordFoundException $e) { $this->logger->info('Could not index document. Try to delete it therefore.', [$e->getMessage()]); @@ -106,47 +109,70 @@ abstract class AbstractIndexer implements IndexerInterface } $this->logger->info('Finish indexing'); } - + public function delete() { $this->logger->info('Start deletion of index.'); $this->connection->deleteIndex($this->getDocumentName()); $this->logger->info('Finish deletion.'); } - - protected function getRecordGenerator() : \Generator + + protected function getRecordGenerator(): \Generator { $offset = 0; $limit = $this->getLimit(); - + while (($records = $this->getRecords($offset, $limit)) !== []) { yield $records; $offset += $limit; } } - + + + /** + * @param array $record + * + * @throws \Exception + */ protected function prepareRecord(array &$record) { try { - foreach ($this->configuration->get('indexing.' . $this->identifier . '.dataProcessing') as $configuration) { - $record = $this->dataProcessorService->executeDataProcessor($configuration, $record, $this->identifier); + $indexingConfiguration = $this->configuration->get('indexing.' . $this->identifier . '.dataProcessing'); + + if (!empty($indexingConfiguration) && is_array($indexingConfiguration)) { + foreach ($indexingConfiguration as $configuration) { + $record = $this->dataProcessorService->executeDataProcessor($configuration, $record, + $this->identifier); + } + } + } catch (\Exception $e) { + if ($e instanceof InvalidArgumentException) { + // Nothing to do + } elseif ($e instanceof MissingArrayPathException) { + // Nothing to do + } else { + throw $e; } - } catch (InvalidArgumentException $e) { - // Nothing to do. } - + $this->handleAbstract($record); } - + + + /** + * @param array $record + * + * @throws \Exception + */ protected function handleAbstract(array &$record) { $record['search_abstract'] = ''; - + try { - $fieldsToUse = GeneralUtility::trimExplode( - ',', - $this->configuration->get('indexing.' . $this->identifier . '.abstractFields') - ); + + $indexConfiguration = $this->configuration->get('indexing.' . $this->identifier . '.abstractFields'); + + $fieldsToUse = GeneralUtility::trimExplode(',', $indexConfiguration); if ($fieldsToUse === []) { return; } @@ -156,29 +182,35 @@ abstract class AbstractIndexer implements IndexerInterface break; } } - } catch (InvalidArgumentException $e) { - return; + } catch (\Exception $e) { + if ($e instanceof InvalidArgumentException) { + return; + } elseif ($e instanceof MissingArrayPathException) { + return; + } else { + throw $e; + } } } - + /** * Returns the limit to use to fetch records. */ - protected function getLimit() : int + protected function getLimit(): int { // TODO: Make configurable. return 50; } - + /** * @return array|null */ abstract protected function getRecords(int $offset, int $limit); - + /** * @throws NoRecordFoundException If record could not be found. */ - abstract protected function getRecord(int $identifier) : array; - - abstract protected function getDocumentName() : string; + abstract protected function getRecord(int $identifier): array; + + abstract protected function getDocumentName(): string; } diff --git a/ext_localconf.php b/ext_localconf.php index 810b3eb..2d900a0 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -42,12 +42,13 @@ call_user_func( \Codappix\SearchCore\Compatibility\ImplementationRegistrationService::registerImplementations(); + // API does make use of object manager, therefore use GLOBALS $extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get($extensionKey); - + if ($extensionConfiguration === false - || !isset($extensionConfiguration['disable.']['elasticsearch']) - || $extensionConfiguration['disable.']['elasticsearch'] !== '1' + || !isset($extensionConfiguration['disable']['elasticsearch']) + || $extensionConfiguration['disable']['elasticsearch'] !== '1' ) { \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class) ->registerImplementation(