mirror of
https://github.com/Codappix/search_core.git
synced 2024-12-23 03:16:10 +01:00
Fix CGL issues
Do not introduce unnecessary changes into pull request for TYPO3 CMS 9 update. * Trim trailing whitespace. * Do not introduce blank line before namespace definition with this pull request. * Add posix new line at end of file.
This commit is contained in:
parent
5acdd91865
commit
c940ac4497
7 changed files with 46 additions and 50 deletions
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore;
|
||||
|
||||
use Codappix\SearchCore\Compatibility\ExtensionConfigurationInterface;
|
||||
|
@ -25,4 +24,4 @@ class Bootstrap
|
|||
ExtensionConfigurationInterface::class
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore\Compatibility;
|
||||
|
||||
use Codappix\SearchCore\Bootstrap;
|
||||
|
@ -9,7 +8,7 @@ class ExtensionConfiguration implements ExtensionConfigurationInterface
|
|||
/**
|
||||
* @return object|\TYPO3\CMS\Core\Configuration\ExtensionConfiguration
|
||||
*/
|
||||
protected function _base()
|
||||
private function base()
|
||||
{
|
||||
return Bootstrap::getObjectManager()->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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore\Compatibility;
|
||||
|
||||
interface ExtensionConfigurationInterface
|
||||
{
|
||||
public function get($extensionKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore\Compatibility;
|
||||
|
||||
/*
|
||||
|
@ -43,7 +42,7 @@ class ImplementationRegistrationService
|
|||
ExtensionConfigurationInterface::class,
|
||||
ExtensionConfiguration::class
|
||||
);
|
||||
} else if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
|
||||
} elseif (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
|
||||
$container->registerImplementation(
|
||||
ExtensionConfigurationInterface::class,
|
||||
Version87\ExtensionConfiguration::class
|
||||
|
|
|
@ -10,4 +10,4 @@ class ExtensionConfiguration implements ExtensionConfigurationInterface
|
|||
{
|
||||
return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore\Domain\Index;
|
||||
|
||||
/*
|
||||
|
@ -34,28 +33,28 @@ abstract class AbstractIndexer implements IndexerInterface
|
|||
* @var ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
|
||||
/**
|
||||
* @var ConfigurationContainerInterface
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $identifier = '';
|
||||
|
||||
|
||||
/**
|
||||
* @var \Codappix\SearchCore\DataProcessing\Service
|
||||
* @inject
|
||||
*/
|
||||
protected $dataProcessorService;
|
||||
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Core\Log\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
|
||||
/**
|
||||
* Inject log manager to get concrete logger from it.
|
||||
*
|
||||
|
@ -65,18 +64,18 @@ abstract class AbstractIndexer implements IndexerInterface
|
|||
{
|
||||
$this->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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue