mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 21:36: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
|
<?php
|
||||||
|
|
||||||
namespace Codappix\SearchCore;
|
namespace Codappix\SearchCore;
|
||||||
|
|
||||||
use Codappix\SearchCore\Compatibility\ExtensionConfigurationInterface;
|
use Codappix\SearchCore\Compatibility\ExtensionConfigurationInterface;
|
||||||
|
@ -25,4 +24,4 @@ class Bootstrap
|
||||||
ExtensionConfigurationInterface::class
|
ExtensionConfigurationInterface::class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Codappix\SearchCore\Compatibility;
|
namespace Codappix\SearchCore\Compatibility;
|
||||||
|
|
||||||
use Codappix\SearchCore\Bootstrap;
|
use Codappix\SearchCore\Bootstrap;
|
||||||
|
@ -9,7 +8,7 @@ class ExtensionConfiguration implements ExtensionConfigurationInterface
|
||||||
/**
|
/**
|
||||||
* @return object|\TYPO3\CMS\Core\Configuration\ExtensionConfiguration
|
* @return object|\TYPO3\CMS\Core\Configuration\ExtensionConfiguration
|
||||||
*/
|
*/
|
||||||
protected function _base()
|
private function base()
|
||||||
{
|
{
|
||||||
return Bootstrap::getObjectManager()->get(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class);
|
return Bootstrap::getObjectManager()->get(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +21,6 @@ class ExtensionConfiguration implements ExtensionConfigurationInterface
|
||||||
*/
|
*/
|
||||||
public function get($extensionKey)
|
public function get($extensionKey)
|
||||||
{
|
{
|
||||||
return $this->_base()->get($extensionKey);
|
return $this->base()->get($extensionKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Codappix\SearchCore\Compatibility;
|
namespace Codappix\SearchCore\Compatibility;
|
||||||
|
|
||||||
interface ExtensionConfigurationInterface
|
interface ExtensionConfigurationInterface
|
||||||
{
|
{
|
||||||
public function get($extensionKey);
|
public function get($extensionKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Codappix\SearchCore\Compatibility;
|
namespace Codappix\SearchCore\Compatibility;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -43,7 +42,7 @@ class ImplementationRegistrationService
|
||||||
ExtensionConfigurationInterface::class,
|
ExtensionConfigurationInterface::class,
|
||||||
ExtensionConfiguration::class
|
ExtensionConfiguration::class
|
||||||
);
|
);
|
||||||
} else if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
|
} elseif (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 8000000) {
|
||||||
$container->registerImplementation(
|
$container->registerImplementation(
|
||||||
ExtensionConfigurationInterface::class,
|
ExtensionConfigurationInterface::class,
|
||||||
Version87\ExtensionConfiguration::class
|
Version87\ExtensionConfiguration::class
|
||||||
|
|
|
@ -10,4 +10,4 @@ class ExtensionConfiguration implements ExtensionConfigurationInterface
|
||||||
{
|
{
|
||||||
return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]);
|
return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,14 +63,14 @@ class ConfigurationContainer implements ConfigurationContainerInterface
|
||||||
public function get(string $path)
|
public function get(string $path)
|
||||||
{
|
{
|
||||||
$value = ArrayUtility::getValueByPath($this->settings, $path, '.');
|
$value = ArrayUtility::getValueByPath($this->settings, $path, '.');
|
||||||
|
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'The given configuration option "' . $path . '" does not exist.',
|
'The given configuration option "' . $path . '" does not exist.',
|
||||||
InvalidArgumentException::OPTION_DOES_NOT_EXIST
|
InvalidArgumentException::OPTION_DOES_NOT_EXIST
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,12 +80,9 @@ class ConfigurationContainer implements ConfigurationContainerInterface
|
||||||
*/
|
*/
|
||||||
public function getIfExists(string $path)
|
public function getIfExists(string $path)
|
||||||
{
|
{
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return ArrayUtility::getValueByPath($this->settings, $path, '.');
|
return ArrayUtility::getValueByPath($this->settings, $path, '.');
|
||||||
}
|
} catch (\Exception $exception) {
|
||||||
catch (\Exception $exception)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Codappix\SearchCore\Domain\Index;
|
namespace Codappix\SearchCore\Domain\Index;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -34,28 +33,28 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
* @var ConnectionInterface
|
* @var ConnectionInterface
|
||||||
*/
|
*/
|
||||||
protected $connection;
|
protected $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConfigurationContainerInterface
|
* @var ConfigurationContainerInterface
|
||||||
*/
|
*/
|
||||||
protected $configuration;
|
protected $configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $identifier = '';
|
protected $identifier = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Codappix\SearchCore\DataProcessing\Service
|
* @var \Codappix\SearchCore\DataProcessing\Service
|
||||||
* @inject
|
* @inject
|
||||||
*/
|
*/
|
||||||
protected $dataProcessorService;
|
protected $dataProcessorService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \TYPO3\CMS\Core\Log\Logger
|
* @var \TYPO3\CMS\Core\Log\Logger
|
||||||
*/
|
*/
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject log manager to get concrete logger from it.
|
* Inject log manager to get concrete logger from it.
|
||||||
*
|
*
|
||||||
|
@ -65,18 +64,18 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
{
|
{
|
||||||
$this->logger = $logManager->getLogger(__CLASS__);
|
$this->logger = $logManager->getLogger(__CLASS__);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIdentifier(string $identifier)
|
public function setIdentifier(string $identifier)
|
||||||
{
|
{
|
||||||
$this->identifier = $identifier;
|
$this->identifier = $identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(ConnectionInterface $connection, ConfigurationContainerInterface $configuration)
|
public function __construct(ConnectionInterface $connection, ConfigurationContainerInterface $configuration)
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->configuration = $configuration;
|
$this->configuration = $configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAllDocuments()
|
public function indexAllDocuments()
|
||||||
{
|
{
|
||||||
$this->logger->info('Start indexing');
|
$this->logger->info('Start indexing');
|
||||||
|
@ -84,24 +83,24 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
if ($records === null) {
|
if ($records === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($records as &$record) {
|
foreach ($records as &$record) {
|
||||||
$this->prepareRecord($record);
|
$this->prepareRecord($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->debug('Index records.', [$records]);
|
$this->logger->debug('Index records.', [$records]);
|
||||||
$this->connection->addDocuments($this->getDocumentName(), $records);
|
$this->connection->addDocuments($this->getDocumentName(), $records);
|
||||||
}
|
}
|
||||||
$this->logger->info('Finish indexing');
|
$this->logger->info('Finish indexing');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexDocument(string $identifier)
|
public function indexDocument(string $identifier)
|
||||||
{
|
{
|
||||||
$this->logger->info('Start indexing single record.', [$identifier]);
|
$this->logger->info('Start indexing single record.', [$identifier]);
|
||||||
try {
|
try {
|
||||||
$record = $this->getRecord((int)$identifier);
|
$record = $this->getRecord((int)$identifier);
|
||||||
$this->prepareRecord($record);
|
$this->prepareRecord($record);
|
||||||
|
|
||||||
$this->connection->addDocument($this->getDocumentName(), $record);
|
$this->connection->addDocument($this->getDocumentName(), $record);
|
||||||
} catch (NoRecordFoundException $e) {
|
} catch (NoRecordFoundException $e) {
|
||||||
$this->logger->info('Could not index document. Try to delete it therefore.', [$e->getMessage()]);
|
$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');
|
$this->logger->info('Finish indexing');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$this->logger->info('Start deletion of index.');
|
$this->logger->info('Start deletion of index.');
|
||||||
$this->connection->deleteIndex($this->getDocumentName());
|
$this->connection->deleteIndex($this->getDocumentName());
|
||||||
$this->logger->info('Finish deletion.');
|
$this->logger->info('Finish deletion.');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRecordGenerator(): \Generator
|
protected function getRecordGenerator(): \Generator
|
||||||
{
|
{
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
$limit = $this->getLimit();
|
$limit = $this->getLimit();
|
||||||
|
|
||||||
while (($records = $this->getRecords($offset, $limit)) !== []) {
|
while (($records = $this->getRecords($offset, $limit)) !== []) {
|
||||||
yield $records;
|
yield $records;
|
||||||
$offset += $limit;
|
$offset += $limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $record
|
* @param array $record
|
||||||
*
|
*
|
||||||
|
@ -137,12 +135,17 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
protected function prepareRecord(array &$record)
|
protected function prepareRecord(array &$record)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$indexingConfiguration = $this->configuration->getIfExists('indexing.' . $this->identifier . '.dataProcessing');
|
$indexingConfiguration = $this->configuration->getIfExists(
|
||||||
|
'indexing.' . $this->identifier . '.dataProcessing'
|
||||||
|
);
|
||||||
|
|
||||||
if (!empty($indexingConfiguration) && is_array($indexingConfiguration)) {
|
if (!empty($indexingConfiguration) && is_array($indexingConfiguration)) {
|
||||||
foreach ($indexingConfiguration as $configuration) {
|
foreach ($indexingConfiguration as $configuration) {
|
||||||
$record = $this->dataProcessorService->executeDataProcessor($configuration, $record,
|
$record = $this->dataProcessorService->executeDataProcessor(
|
||||||
$this->identifier);
|
$configuration,
|
||||||
|
$record,
|
||||||
|
$this->identifier
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -154,11 +157,10 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->handleAbstract($record);
|
$this->handleAbstract($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $record
|
* @param array $record
|
||||||
*
|
*
|
||||||
|
@ -167,11 +169,12 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
protected function handleAbstract(array &$record)
|
protected function handleAbstract(array &$record)
|
||||||
{
|
{
|
||||||
$record['search_abstract'] = '';
|
$record['search_abstract'] = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$indexConfiguration = $this->configuration->getIfExists(
|
||||||
$indexConfiguration = $this->configuration->getIfExists('indexing.' . $this->identifier . '.abstractFields');
|
'indexing.' . $this->identifier . '.abstractFields'
|
||||||
|
);
|
||||||
|
|
||||||
$fieldsToUse = GeneralUtility::trimExplode(',', $indexConfiguration);
|
$fieldsToUse = GeneralUtility::trimExplode(',', $indexConfiguration);
|
||||||
if ($fieldsToUse === []) {
|
if ($fieldsToUse === []) {
|
||||||
return;
|
return;
|
||||||
|
@ -192,7 +195,7 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the limit to use to fetch records.
|
* Returns the limit to use to fetch records.
|
||||||
*/
|
*/
|
||||||
|
@ -201,16 +204,16 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
// TODO: Make configurable.
|
// TODO: Make configurable.
|
||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
abstract protected function getRecords(int $offset, int $limit);
|
abstract protected function getRecords(int $offset, int $limit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NoRecordFoundException If record could not be found.
|
* @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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue