diff --git a/Classes/Bootstrap.php b/Classes/Bootstrap.php index ecfb784..0cd8a89 100644 --- a/Classes/Bootstrap.php +++ b/Classes/Bootstrap.php @@ -1,5 +1,4 @@ get(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class); } @@ -22,6 +21,6 @@ class ExtensionConfiguration implements ExtensionConfigurationInterface */ public function get($extensionKey) { - return $this->_base()->get($extensionKey); + return $this->base()->get($extensionKey); } } diff --git a/Classes/Compatibility/ExtensionConfigurationInterface.php b/Classes/Compatibility/ExtensionConfigurationInterface.php index d12ccd3..f62ab2d 100644 --- a/Classes/Compatibility/ExtensionConfigurationInterface.php +++ b/Classes/Compatibility/ExtensionConfigurationInterface.php @@ -1,8 +1,7 @@ = 8000000) { + } elseif (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) { $container->registerImplementation( ExtensionConfigurationInterface::class, Version87\ExtensionConfiguration::class diff --git a/Classes/Compatibility/Version87/ExtensionConfiguration.php b/Classes/Compatibility/Version87/ExtensionConfiguration.php index 86814fa..6ff91af 100644 --- a/Classes/Compatibility/Version87/ExtensionConfiguration.php +++ b/Classes/Compatibility/Version87/ExtensionConfiguration.php @@ -10,4 +10,4 @@ class ExtensionConfiguration implements ExtensionConfigurationInterface { return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); } -} \ No newline at end of file +} diff --git a/Classes/Configuration/ConfigurationContainer.php b/Classes/Configuration/ConfigurationContainer.php index 4fd4fcc..4a93730 100644 --- a/Classes/Configuration/ConfigurationContainer.php +++ b/Classes/Configuration/ConfigurationContainer.php @@ -63,14 +63,14 @@ class ConfigurationContainer implements ConfigurationContainerInterface public function get(string $path) { $value = ArrayUtility::getValueByPath($this->settings, $path, '.'); - + if ($value === null) { throw new InvalidArgumentException( 'The given configuration option "' . $path . '" does not exist.', InvalidArgumentException::OPTION_DOES_NOT_EXIST ); } - + return $value; } @@ -80,12 +80,9 @@ class ConfigurationContainer implements ConfigurationContainerInterface */ public function getIfExists(string $path) { - try - { + try { return ArrayUtility::getValueByPath($this->settings, $path, '.'); - } - catch (\Exception $exception) - { + } catch (\Exception $exception) { return null; } } diff --git a/Classes/Domain/Index/AbstractIndexer.php b/Classes/Domain/Index/AbstractIndexer.php index 861c17a..a6a8946 100644 --- a/Classes/Domain/Index/AbstractIndexer.php +++ b/Classes/Domain/Index/AbstractIndexer.php @@ -1,5 +1,4 @@ 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'); @@ -84,24 +83,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); $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()]); @@ -109,26 +108,25 @@ 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 { $offset = 0; $limit = $this->getLimit(); - + while (($records = $this->getRecords($offset, $limit)) !== []) { yield $records; $offset += $limit; } } - - + /** * @param array $record * @@ -137,12 +135,17 @@ abstract class AbstractIndexer implements IndexerInterface protected function prepareRecord(array &$record) { try { - $indexingConfiguration = $this->configuration->getIfExists('indexing.' . $this->identifier . '.dataProcessing'); - + $indexingConfiguration = $this->configuration->getIfExists( + 'indexing.' . $this->identifier . '.dataProcessing' + ); + if (!empty($indexingConfiguration) && is_array($indexingConfiguration)) { foreach ($indexingConfiguration as $configuration) { - $record = $this->dataProcessorService->executeDataProcessor($configuration, $record, - $this->identifier); + $record = $this->dataProcessorService->executeDataProcessor( + $configuration, + $record, + $this->identifier + ); } } } catch (\Exception $e) { @@ -154,11 +157,10 @@ abstract class AbstractIndexer implements IndexerInterface throw $e; } } - + $this->handleAbstract($record); } - - + /** * @param array $record * @@ -167,11 +169,12 @@ abstract class AbstractIndexer implements IndexerInterface protected function handleAbstract(array &$record) { $record['search_abstract'] = ''; - + try { - - $indexConfiguration = $this->configuration->getIfExists('indexing.' . $this->identifier . '.abstractFields'); - + $indexConfiguration = $this->configuration->getIfExists( + 'indexing.' . $this->identifier . '.abstractFields' + ); + $fieldsToUse = GeneralUtility::trimExplode(',', $indexConfiguration); if ($fieldsToUse === []) { return; @@ -192,7 +195,7 @@ abstract class AbstractIndexer implements IndexerInterface } } } - + /** * Returns the limit to use to fetch records. */ @@ -201,16 +204,16 @@ abstract class AbstractIndexer implements IndexerInterface // 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; }