mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 20:36:10 +01:00
Merge branch 'feature/update-9' of github.com:bergwerk/search_core into feature/update-9
# Conflicts: # Classes/Configuration/ConfigurationContainer.php
This commit is contained in:
commit
6a697133bb
4 changed files with 80 additions and 50 deletions
|
@ -23,6 +23,7 @@ namespace Codappix\SearchCore\Configuration;
|
|||
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.
|
||||
|
@ -61,12 +62,9 @@ class ConfigurationContainer implements ConfigurationContainerInterface
|
|||
*/
|
||||
public function get(string $path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ArrayUtility::getValueByPath($this->settings, $path);
|
||||
}
|
||||
catch (MissingArrayPathException $exception)
|
||||
{
|
||||
$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
|
||||
|
@ -82,7 +80,7 @@ class ConfigurationContainer implements ConfigurationContainerInterface
|
|||
{
|
||||
try
|
||||
{
|
||||
return ArrayUtility::getValueByPath($this->settings, $path);
|
||||
return ArrayUtility::getValueByPath($this->settings, $path, '.');
|
||||
}
|
||||
catch (\Exception $exception)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore\Domain\Index;
|
||||
|
||||
/*
|
||||
|
@ -23,6 +24,8 @@ namespace Codappix\SearchCore\Domain\Index;
|
|||
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
||||
use Codappix\SearchCore\Configuration\InvalidArgumentException;
|
||||
use Codappix\SearchCore\Connection\ConnectionInterface;
|
||||
use TYPO3\CMS\Core\Exception;
|
||||
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
abstract class AbstractIndexer implements IndexerInterface
|
||||
|
@ -96,7 +99,7 @@ abstract class AbstractIndexer implements IndexerInterface
|
|||
{
|
||||
$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);
|
||||
|
@ -114,7 +117,7 @@ abstract class AbstractIndexer implements IndexerInterface
|
|||
$this->logger->info('Finish deletion.');
|
||||
}
|
||||
|
||||
protected function getRecordGenerator() : \Generator
|
||||
protected function getRecordGenerator(): \Generator
|
||||
{
|
||||
$offset = 0;
|
||||
$limit = $this->getLimit();
|
||||
|
@ -125,28 +128,51 @@ abstract class AbstractIndexer implements IndexerInterface
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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,15 +182,21 @@ abstract class AbstractIndexer implements IndexerInterface
|
|||
break;
|
||||
}
|
||||
}
|
||||
} catch (InvalidArgumentException $e) {
|
||||
} 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;
|
||||
|
@ -178,7 +210,7 @@ abstract class AbstractIndexer implements IndexerInterface
|
|||
/**
|
||||
* @throws NoRecordFoundException If record could not be found.
|
||||
*/
|
||||
abstract protected function getRecord(int $identifier) : array;
|
||||
abstract protected function getRecord(int $identifier): array;
|
||||
|
||||
abstract protected function getDocumentName() : string;
|
||||
abstract protected function getDocumentName(): string;
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue