diff --git a/Classes/Access/RootlineElementFormatException.php b/Classes/Access/RootlineElementFormatException.php index ade937a738..3a0ce0e23b 100644 --- a/Classes/Access/RootlineElementFormatException.php +++ b/Classes/Access/RootlineElementFormatException.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\Access; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; /** * Signals a wrong format for the access definition of a page or the content. diff --git a/Classes/ConnectionManager.php b/Classes/ConnectionManager.php index ad0863e89e..d9e8d2ad99 100644 --- a/Classes/ConnectionManager.php +++ b/Classes/ConnectionManager.php @@ -20,12 +20,12 @@ use ApacheSolrForTypo3\Solr\Domain\Site\Exception\UnexpectedTYPO3SiteInitializationException; use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository as PagesRepositoryAtExtSolr; use ApacheSolrForTypo3\Solr\System\Solr\Node; use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection; use ApacheSolrForTypo3\Solr\System\Util\SiteUtility; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Site\Entity\Site as Typo3Site; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/ContentObject/Classification.php b/Classes/ContentObject/Classification.php index 786cdae186..2ca88f2c61 100644 --- a/Classes/ContentObject/Classification.php +++ b/Classes/ContentObject/Classification.php @@ -17,7 +17,7 @@ use ApacheSolrForTypo3\Solr\Domain\Index\Classification\Classification as ClassificationItem; use ApacheSolrForTypo3\Solr\Domain\Index\Classification\ClassificationService; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject; diff --git a/Classes/Controller/Backend/Search/AbstractModuleController.php b/Classes/Controller/Backend/Search/AbstractModuleController.php index 0444b40321..30a0b4091e 100644 --- a/Classes/Controller/Backend/Search/AbstractModuleController.php +++ b/Classes/Controller/Backend/Search/AbstractModuleController.php @@ -19,11 +19,11 @@ use ApacheSolrForTypo3\Solr\Domain\Site\Exception\UnexpectedTYPO3SiteInitializationException; use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; -use ApacheSolrForTypo3\Solr\IndexQueue\Queue; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; +use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface; use ApacheSolrForTypo3\Solr\System\Mvc\Backend\Service\ModuleDataStorageService; use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection as SolrCoreConnection; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Backend\Template\Components\Menu\Menu; use TYPO3\CMS\Backend\Template\ModuleTemplate; @@ -65,7 +65,7 @@ public function __construct( protected readonly SiteRepository $siteRepository, protected readonly SiteFinder $siteFinder, protected readonly ConnectionManager $solrConnectionManager, - protected Queue $indexQueue, + protected QueueInterface $indexQueue, protected ?int $selectedPageUID = null, ) { $this->selectedPageUID = $selectedPageUID ?? 0; diff --git a/Classes/Controller/Backend/Search/IndexQueueModuleController.php b/Classes/Controller/Backend/Search/IndexQueueModuleController.php index 5c7e813de1..4f5ce9a2af 100644 --- a/Classes/Controller/Backend/Search/IndexQueueModuleController.php +++ b/Classes/Controller/Backend/Search/IndexQueueModuleController.php @@ -17,8 +17,10 @@ use ApacheSolrForTypo3\Solr\Backend\IndexingConfigurationSelectorField; use ApacheSolrForTypo3\Solr\Domain\Index\IndexService; +use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueInitializationService; use ApacheSolrForTypo3\Solr\Domain\Site\Exception\UnexpectedTYPO3SiteInitializationException; use ApacheSolrForTypo3\Solr\IndexQueue\Queue; +use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface; use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\Exception as DBALException; use Psr\Http\Message\ResponseInterface; @@ -32,11 +34,26 @@ /** * Index Queue Module * + * @todo: Support all index queues in actions beside "initializeIndexQueueAction" and + * "resetLogErrorsAction" + * * @author Ingo Renner */ class IndexQueueModuleController extends AbstractModuleController { - public function setIndexQueue(Queue $indexQueue): void + protected array $enabledIndexQueues; + + protected function initializeAction(): void + { + parent::initializeAction(); + + $this->enabledIndexQueues = $this->getIndexQueues(); + if (!empty($this->enabledIndexQueues)) { + $this->indexQueue = $this->enabledIndexQueues[Queue::class] ?? reset($this->enabledIndexQueues); + } + } + + public function setIndexQueue(QueueInterface $indexQueue): void { $this->indexQueue = $indexQueue; } @@ -71,6 +88,11 @@ protected function canQueueSelectedSite(): bool if ($this->selectedSite === null || empty($this->solrConnectionManager->getConnectionsBySite($this->selectedSite))) { return false; } + + if (!isset($this->indexQueue)) { + return false; + } + $enabledIndexQueueConfigurationNames = $this->selectedSite->getSolrConfiguration()->getEnabledIndexQueueConfigurationNames(); if (empty($enabledIndexQueueConfigurationNames)) { return false; @@ -105,25 +127,38 @@ public function initializeIndexQueueAction(): ResponseInterface $indexingConfigurationsToInitialize = $this->request->getArgument('tx_solr-index-queue-initialization'); if ((!empty($indexingConfigurationsToInitialize)) && (is_array($indexingConfigurationsToInitialize))) { - // initialize selected indexing configuration - try { - $initializedIndexingConfigurations = $this->indexQueue->getInitializationService()->initializeBySiteAndIndexConfigurations($this->selectedSite, $indexingConfigurationsToInitialize); - } catch (Throwable $e) { - $this->addFlashMessage( - sprintf( + $initializationService = GeneralUtility::makeInstance(QueueInitializationService::class); + foreach ($indexingConfigurationsToInitialize as $configurationToInitialize) { + $indexQueueClass = $this->selectedSite->getSolrConfiguration()->getIndexQueueClassByConfigurationName($configurationToInitialize); + $indexQueue = $this->enabledIndexQueues[$indexQueueClass]; + + try { + $status = $initializationService->initializeBySiteAndIndexConfigurations($this->selectedSite, [$configurationToInitialize]); + $initializedIndexingConfiguration = [ + 'status' => $status[$configurationToInitialize], + 'statistic' => 0, + ]; + if ($status[$configurationToInitialize] === true) { + $initializedIndexingConfiguration['totalCount'] = $indexQueue->getStatisticsBySite($this->selectedSite, $configurationToInitialize)->getTotalCount(); + } + $initializedIndexingConfigurations[$configurationToInitialize] = $initializedIndexingConfiguration; + } catch (Throwable $e) { + $this->addFlashMessage( + sprintf( + LocalizationUtility::translate( + 'solr.backend.index_queue_module.flashmessage.initialize_failure', + 'Solr' + ), + $e->getMessage(), + $e->getCode() + ), LocalizationUtility::translate( - 'solr.backend.index_queue_module.flashmessage.initialize_failure', + 'solr.backend.index_queue_module.flashmessage.initialize_failure.title', 'Solr' ), - $e->getMessage(), - $e->getCode() - ), - LocalizationUtility::translate( - 'solr.backend.index_queue_module.flashmessage.initialize_failure.title', - 'Solr' - ), - ContextualFeedbackSeverity::ERROR - ); + ContextualFeedbackSeverity::ERROR + ); + } } } else { $messageLabel = 'solr.backend.index_queue_module.flashmessage.initialize.no_selection'; @@ -134,18 +169,37 @@ public function initializeIndexQueueAction(): ResponseInterface ContextualFeedbackSeverity::WARNING ); } + $messagesForConfigurations = []; - foreach (array_keys($initializedIndexingConfigurations) as $indexingConfigurationName) { - $itemCount = $this->indexQueue->getStatisticsBySite($this->selectedSite, $indexingConfigurationName)->getTotalCount(); - $messagesForConfigurations[] = $indexingConfigurationName . ' (' . $itemCount . ' records)'; + foreach ($initializedIndexingConfigurations as $indexingConfigurationName => $initializationData) { + if ($initializationData['status'] === true) { + $messagesForConfigurations[] = $indexingConfigurationName . ' (' . $initializationData['totalCount'] . ' records)'; + } else { + $this->addFlashMessage( + sprintf( + LocalizationUtility::translate( + 'solr.backend.index_queue_module.flashmessage.initialize_failure', + 'Solr' + ), + $indexingConfigurationName, + 1662117020 + ), + LocalizationUtility::translate( + 'solr.backend.index_queue_module.flashmessage.initialize_failure.title', + 'Solr' + ), + ContextualFeedbackSeverity::ERROR + ); + } } - if (!empty($initializedIndexingConfigurations)) { + if (!empty($messagesForConfigurations)) { $messageLabel = 'solr.backend.index_queue_module.flashmessage.initialize.success'; $titleLabel = 'solr.backend.index_queue_module.flashmessage.initialize.title'; $this->addFlashMessage( LocalizationUtility::translate($messageLabel, 'Solr', [implode(', ', $messagesForConfigurations)]), - LocalizationUtility::translate($titleLabel, 'Solr') + LocalizationUtility::translate($titleLabel, 'Solr'), + ContextualFeedbackSeverity::OK ); } @@ -159,16 +213,18 @@ public function initializeIndexQueueAction(): ResponseInterface */ public function resetLogErrorsAction(): ResponseInterface { - $resetResult = $this->indexQueue->resetAllErrors(); + foreach ($this->enabledIndexQueues as $queue) { + $resetResult = $queue->resetAllErrors(); - $label = 'solr.backend.index_queue_module.flashmessage.success.reset_errors'; - $severity = ContextualFeedbackSeverity::OK; - if (!$resetResult) { - $label = 'solr.backend.index_queue_module.flashmessage.error.reset_errors'; - $severity = ContextualFeedbackSeverity::ERROR; - } + $label = 'solr.backend.index_queue_module.flashmessage.success.reset_errors'; + $severity = ContextualFeedbackSeverity::OK; + if (!$resetResult) { + $label = 'solr.backend.index_queue_module.flashmessage.error.reset_errors'; + $severity = ContextualFeedbackSeverity::ERROR; + } - $this->addIndexQueueFlashMessage($label, $severity); + $this->addIndexQueueFlashMessage($label, $severity); + } return new RedirectResponse($this->uriBuilder->uriFor('index'), 303); } @@ -255,4 +311,21 @@ protected function addIndexQueueFlashMessage(string $label, ContextualFeedbackSe { $this->addFlashMessage(LocalizationUtility::translate($label, 'Solr'), LocalizationUtility::translate('solr.backend.index_queue_module.flashmessage.title', 'Solr'), $severity); } + + /** + * @return QueueInterface[] + */ + protected function getIndexQueues(): array + { + $queues = []; + $configuration = $this->selectedSite->getSolrConfiguration(); + foreach ($configuration->getEnabledIndexQueueConfigurationNames() as $indexingConfiguration) { + $indexQueueClass = $configuration->getIndexQueueClassByConfigurationName($indexingConfiguration); + if (!isset($queues[$indexQueueClass])) { + $queues[$indexQueueClass] = GeneralUtility::makeInstance($indexQueueClass); + } + } + + return $queues; + } } diff --git a/Classes/Domain/Index/IndexService.php b/Classes/Domain/Index/IndexService.php index 6144084eaa..1e0aae5cd2 100644 --- a/Classes/Domain/Index/IndexService.php +++ b/Classes/Domain/Index/IndexService.php @@ -24,6 +24,7 @@ use ApacheSolrForTypo3\Solr\IndexQueue\Indexer; use ApacheSolrForTypo3\Solr\IndexQueue\Item; use ApacheSolrForTypo3\Solr\IndexQueue\Queue; +use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use ApacheSolrForTypo3\Solr\Task\IndexQueueWorkerTask; @@ -45,7 +46,7 @@ class IndexService protected ?IndexQueueWorkerTask $contextTask = null; - protected Queue $indexQueue; + protected QueueInterface $indexQueue; protected EventDispatcherInterface $eventDispatcher; @@ -53,7 +54,7 @@ class IndexService public function __construct( Site $site, - Queue $queue = null, + QueueInterface $queue = null, EventDispatcherInterface $eventDispatcher = null, SolrLogManager $solrLogManager = null, ) { diff --git a/Classes/Domain/Index/Queue/GarbageRemover/AbstractStrategy.php b/Classes/Domain/Index/Queue/GarbageRemover/AbstractStrategy.php index d27984bed8..ca851ddc65 100644 --- a/Classes/Domain/Index/Queue/GarbageRemover/AbstractStrategy.php +++ b/Classes/Domain/Index/Queue/GarbageRemover/AbstractStrategy.php @@ -17,11 +17,12 @@ use ApacheSolrForTypo3\Solr\ConnectionManager; use ApacheSolrForTypo3\Solr\Domain\Site\Exception\UnexpectedTYPO3SiteInitializationException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor; use ApacheSolrForTypo3\Solr\IndexQueue\Queue; +use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; use UnexpectedValueException; @@ -31,12 +32,12 @@ */ abstract class AbstractStrategy { - protected Queue $queue; + protected QueueInterface $queue; protected ConnectionManager $connectionManager; public function __construct( - Queue $queue = null, + QueueInterface $queue = null, ConnectionManager $connectionManager = null, ) { $this->queue = $queue ?? GeneralUtility::makeInstance(Queue::class); diff --git a/Classes/Domain/Index/Queue/QueueInitializationService.php b/Classes/Domain/Index/Queue/QueueInitializationService.php index 33b1524713..d9a3c7b620 100644 --- a/Classes/Domain/Index/Queue/QueueInitializationService.php +++ b/Classes/Domain/Index/Queue/QueueInitializationService.php @@ -20,7 +20,8 @@ use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Event\IndexQueue\AfterIndexQueueHasBeenInitializedEvent; use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\AbstractInitializer; -use ApacheSolrForTypo3\Solr\IndexQueue\Queue; +use ApacheSolrForTypo3\Solr\IndexQueue\QueueInitializationServiceAwareInterface; +use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface; use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\Exception as DBALException; use Psr\EventDispatcher\EventDispatcherInterface; @@ -35,15 +36,19 @@ */ class QueueInitializationService { - protected Queue $queue; + protected bool $clearQueueOnInitialization = true; protected EventDispatcherInterface $eventDispatcher; - public function __construct(Queue $queue, EventDispatcherInterface $eventDispatcher = null) + public function __construct(EventDispatcherInterface $eventDispatcher = null) { - $this->queue = $queue; $this->eventDispatcher = $eventDispatcher ?? GeneralUtility::makeInstance(EventDispatcherInterface::class); } + public function setClearQueueOnInitialization(bool $clearQueueOnInitialization): void + { + $this->clearQueueOnInitialization = $clearQueueOnInitialization; + } + /** * Truncate and rebuild the tx_solr_indexqueue_item table. This is the most * complete way to force reindexing, or to build the Index Queue for the @@ -113,10 +118,21 @@ public function initializeBySiteAndIndexConfigurations(Site $site, array $indexi */ protected function applyInitialization(Site $site, string $indexingConfigurationName): bool { + $solrConfiguration = $site->getSolrConfiguration(); + + /** @var QueueInterface $queue */ + $queue = GeneralUtility::makeInstance( + $solrConfiguration->getIndexQueueClassByConfigurationName($indexingConfigurationName) + ); + if ($queue instanceof QueueInitializationServiceAwareInterface) { + $queue->setQueueInitializationService($this); + } + // clear queue - $this->queue->deleteItemsBySite($site, $indexingConfigurationName); + if ($this->clearQueueOnInitialization) { + $queue->deleteItemsBySite($site, $indexingConfigurationName); + } - $solrConfiguration = $site->getSolrConfiguration(); $type = $solrConfiguration->getIndexQueueTypeOrFallbackToConfigurationName($indexingConfigurationName); $initializerClass = $solrConfiguration->getIndexQueueInitializerClassByConfigurationName($indexingConfigurationName); $indexConfiguration = $solrConfiguration->getIndexQueueConfigurationByName($indexingConfigurationName); diff --git a/Classes/Domain/Index/Queue/QueueItemRepository.php b/Classes/Domain/Index/Queue/QueueItemRepository.php index a7fb79880b..8338fd95ce 100644 --- a/Classes/Domain/Index/Queue/QueueItemRepository.php +++ b/Classes/Domain/Index/Queue/QueueItemRepository.php @@ -20,6 +20,7 @@ use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Event\IndexQueue\AfterRecordsForIndexQueueItemsHaveBeenRetrievedEvent; use ApacheSolrForTypo3\Solr\IndexQueue\Item; +use ApacheSolrForTypo3\Solr\IndexQueue\ItemInterface; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use ApacheSolrForTypo3\Solr\System\Records\AbstractRepository; use ApacheSolrForTypo3\Solr\System\Util\SiteUtility; @@ -118,7 +119,7 @@ public function flushErrorsBySite(Site $site): int /** * Flushes the error for a single item. */ - public function flushErrorByItem(Item $item): int + public function flushErrorByItem(ItemInterface $item): int { $queryBuilder = $this->getQueryBuilder(); return $this->getPreparedFlushErrorQuery($queryBuilder) @@ -311,11 +312,14 @@ public function containsItem(string $itemType, int $itemUid): bool * * @throws DBALException */ - public function containsItemWithRootPageId(string $itemType, int $itemUid, int $rootPageId): bool + public function containsItemWithRootPageId(string $itemType, int $itemUid, int $rootPageId, string $indexingConfiguration): bool { $queryBuilder = $this->getQueryBuilderForContainsMethods($itemType, $itemUid); return (bool)$queryBuilder - ->andWhere($queryBuilder->expr()->eq('root', $rootPageId)) + ->andWhere( + $queryBuilder->expr()->eq('root', $rootPageId), + $queryBuilder->expr()->eq('indexing_configuration', $queryBuilder->createNamedParameter($indexingConfiguration)) + ) ->executeQuery() ->fetchOne(); } @@ -748,7 +752,7 @@ protected function getQueueItemObjectsByRecords(array $indexQueueItemRecords, ar * Marks an item as failed and causes the indexer to skip the item in the * next run. */ - public function markItemAsFailed(Item|int|null $item, string $errorMessage = ''): int + public function markItemAsFailed(ItemInterface|int|null $item, string $errorMessage = ''): int { $itemUid = ($item instanceof Item) ? $item->getIndexQueueUid() : (int)$item; $errorMessage = empty($errorMessage) ? '1' : $errorMessage; @@ -764,7 +768,7 @@ public function markItemAsFailed(Item|int|null $item, string $errorMessage = '') /** * Sets the timestamp of when an item last has been indexed. */ - public function updateIndexTimeByItem(Item $item): int + public function updateIndexTimeByItem(ItemInterface $item): int { $queryBuilder = $this->getQueryBuilder(); return $queryBuilder @@ -777,7 +781,7 @@ public function updateIndexTimeByItem(Item $item): int /** * Sets the change timestamp of an item. */ - public function updateChangedTimeByItem(Item $item, int $changedTime = 0): int + public function updateChangedTimeByItem(ItemInterface $item, int $changedTime = 0): int { $queryBuilder = $this->getQueryBuilder(); return $queryBuilder diff --git a/Classes/Domain/Index/Queue/Statistic/QueueStatisticsRepository.php b/Classes/Domain/Index/Queue/Statistic/QueueStatisticsRepository.php index 3745a48f0b..54324a276c 100644 --- a/Classes/Domain/Index/Queue/Statistic/QueueStatisticsRepository.php +++ b/Classes/Domain/Index/Queue/Statistic/QueueStatisticsRepository.php @@ -29,6 +29,11 @@ class QueueStatisticsRepository extends AbstractRepository { protected string $table = 'tx_solr_indexqueue_item'; + protected string $columnIndexed = 'indexed'; + protected string $columnIndexingConfiguration = 'indexing_configuration'; + protected string $columnChanged = 'changed'; + protected string $columnErrors = 'errors'; + protected string $columnRootpage = 'root'; /** * Extracts the number of pending, indexed and erroneous items from the @@ -43,23 +48,26 @@ public function findOneByRootPidAndOptionalIndexingConfigurationName( $queryBuilder = $this->getQueryBuilder(); $queryBuilder ->add('select', vsprintf('(%s < %s) AS %s', [ - $queryBuilder->quoteIdentifier('indexed'), - $queryBuilder->quoteIdentifier('changed'), + $queryBuilder->quoteIdentifier($this->columnIndexed), + $queryBuilder->quoteIdentifier($this->columnChanged), $queryBuilder->quoteIdentifier('pending'), ]), true) ->add('select', vsprintf('(%s) AS %s', [ - $queryBuilder->expr()->notLike('errors', $queryBuilder->createNamedParameter('')), + $queryBuilder->expr()->notLike($this->columnErrors, $queryBuilder->createNamedParameter('')), $queryBuilder->quoteIdentifier('failed'), ]), true) ->add('select', $queryBuilder->expr()->count('*', 'count'), true) ->from($this->table) ->where( - $queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter($rootPid, PDO::PARAM_INT)) + $queryBuilder->expr()->eq($this->columnRootpage, $queryBuilder->createNamedParameter($rootPid, PDO::PARAM_INT)) )->groupBy('pending', 'failed'); if (!empty($indexingConfigurationName)) { $queryBuilder->andWhere( - $queryBuilder->expr()->eq('indexing_configuration', $queryBuilder->createNamedParameter($indexingConfigurationName)) + $queryBuilder->expr()->eq( + $this->columnIndexingConfiguration, + $queryBuilder->createNamedParameter($indexingConfigurationName) + ) ); } diff --git a/Classes/Domain/Index/Queue/UpdateHandler/EventListener/AbstractBaseEventListener.php b/Classes/Domain/Index/Queue/UpdateHandler/EventListener/AbstractBaseEventListener.php index 444d96db74..77ab817c1a 100644 --- a/Classes/Domain/Index/Queue/UpdateHandler/EventListener/AbstractBaseEventListener.php +++ b/Classes/Domain/Index/Queue/UpdateHandler/EventListener/AbstractBaseEventListener.php @@ -21,8 +21,8 @@ use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\ProcessingFinishedEventInterface; use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\DataUpdateEventInterface; use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\GarbageHandler; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration; -use InvalidArgumentException; use Psr\EventDispatcher\EventDispatcherInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/Domain/Search/LastSearches/LastSearchesRepository.php b/Classes/Domain/Search/LastSearches/LastSearchesRepository.php index 933ad6e01b..50c7841a4c 100644 --- a/Classes/Domain/Search/LastSearches/LastSearchesRepository.php +++ b/Classes/Domain/Search/LastSearches/LastSearchesRepository.php @@ -15,9 +15,9 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\LastSearches; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Records\AbstractRepository; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use function json_encode; diff --git a/Classes/Domain/Search/Query/ParameterBuilder/Operator.php b/Classes/Domain/Search/Query/ParameterBuilder/Operator.php index 32f2c2831a..80b8a7aa17 100644 --- a/Classes/Domain/Search/Query/ParameterBuilder/Operator.php +++ b/Classes/Domain/Search/Query/ParameterBuilder/Operator.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; /** * The Operator ParameterProvider is responsible to build the solr query parameters diff --git a/Classes/Domain/Search/ResultSet/Facets/InvalidFacetPackageException.php b/Classes/Domain/Search/ResultSet/Facets/InvalidFacetPackageException.php index aabca67d9b..fa5269346e 100644 --- a/Classes/Domain/Search/ResultSet/Facets/InvalidFacetPackageException.php +++ b/Classes/Domain/Search/ResultSet/Facets/InvalidFacetPackageException.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; -use Exception; +use ApacheSolrForTypo3\Solr\Exception; class InvalidFacetPackageException extends Exception { diff --git a/Classes/Domain/Search/ResultSet/Facets/InvalidFacetParserException.php b/Classes/Domain/Search/ResultSet/Facets/InvalidFacetParserException.php index d333b3f55c..623eff19bc 100644 --- a/Classes/Domain/Search/ResultSet/Facets/InvalidFacetParserException.php +++ b/Classes/Domain/Search/ResultSet/Facets/InvalidFacetParserException.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; -use Exception; +use ApacheSolrForTypo3\Solr\Exception; class InvalidFacetParserException extends Exception { diff --git a/Classes/Domain/Search/ResultSet/Facets/InvalidQueryBuilderException.php b/Classes/Domain/Search/ResultSet/Facets/InvalidQueryBuilderException.php index 120efd09a8..242c37263b 100644 --- a/Classes/Domain/Search/ResultSet/Facets/InvalidQueryBuilderException.php +++ b/Classes/Domain/Search/ResultSet/Facets/InvalidQueryBuilderException.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; -use Exception; +use ApacheSolrForTypo3\Solr\Exception; class InvalidQueryBuilderException extends Exception { diff --git a/Classes/Domain/Search/ResultSet/Facets/InvalidUrlDecoderException.php b/Classes/Domain/Search/ResultSet/Facets/InvalidUrlDecoderException.php index 58d27d7a00..0c8992f20a 100644 --- a/Classes/Domain/Search/ResultSet/Facets/InvalidUrlDecoderException.php +++ b/Classes/Domain/Search/ResultSet/Facets/InvalidUrlDecoderException.php @@ -17,7 +17,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; -use Exception; +use ApacheSolrForTypo3\Solr\Exception; class InvalidUrlDecoderException extends Exception { diff --git a/Classes/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoder.php b/Classes/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoder.php index 4ba5fbc2ad..7da2bfbe94 100644 --- a/Classes/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoder.php +++ b/Classes/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoder.php @@ -18,7 +18,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\NumericRange; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetUrlDecoderInterface; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; /** * Parser to build Solr range queries from tx_solr[filter] diff --git a/Classes/Domain/Search/ResultSet/Facets/RequirementsService.php b/Classes/Domain/Search/ResultSet/Facets/RequirementsService.php index f23ba29012..7df500bfaf 100644 --- a/Classes/Domain/Search/ResultSet/Facets/RequirementsService.php +++ b/Classes/Domain/Search/ResultSet/Facets/RequirementsService.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** diff --git a/Classes/Domain/Search/ResultSet/Result/Parser/ResultParserRegistry.php b/Classes/Domain/Search/ResultSet/Result/Parser/ResultParserRegistry.php index 2c6211678f..39b18608a2 100644 --- a/Classes/Domain/Search/ResultSet/Result/Parser/ResultParserRegistry.php +++ b/Classes/Domain/Search/ResultSet/Result/Parser/ResultParserRegistry.php @@ -18,7 +18,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\Parser; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/Domain/Search/ResultSet/Result/SearchResultBuilder.php b/Classes/Domain/Search/ResultSet/Result/SearchResultBuilder.php index 2fc37b334f..dbd167ff43 100644 --- a/Classes/Domain/Search/ResultSet/Result/SearchResultBuilder.php +++ b/Classes/Domain/Search/ResultSet/Result/SearchResultBuilder.php @@ -17,8 +17,8 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Solr\Document\Document; -use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** diff --git a/Classes/Domain/Search/ResultSet/Sorting/Sorting.php b/Classes/Domain/Search/ResultSet/Sorting/Sorting.php index 5cf9ca2a8e..c48d074583 100644 --- a/Classes/Domain/Search/ResultSet/Sorting/Sorting.php +++ b/Classes/Domain/Search/ResultSet/Sorting/Sorting.php @@ -18,7 +18,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Sorting; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; /** * Class Sorting diff --git a/Classes/Domain/Search/ResultSet/Sorting/SortingHelper.php b/Classes/Domain/Search/ResultSet/Sorting/SortingHelper.php index 4ac0bb48b9..92f9086e6e 100644 --- a/Classes/Domain/Search/ResultSet/Sorting/SortingHelper.php +++ b/Classes/Domain/Search/ResultSet/Sorting/SortingHelper.php @@ -17,7 +17,7 @@ namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Sorting; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** diff --git a/Classes/Domain/Site/Exception/InvalidSiteRootPageException.php b/Classes/Domain/Site/Exception/InvalidSiteRootPageException.php new file mode 100644 index 0000000000..143cd468b3 --- /dev/null +++ b/Classes/Domain/Site/Exception/InvalidSiteRootPageException.php @@ -0,0 +1,24 @@ +itemType; } - public function getItemUid(): int + public function getItemUid(): int|string { return $this->itemUid; } @@ -57,4 +58,9 @@ public function setUpdateCount(int $updateCount): void { $this->updateCount = $updateCount; } + + public function getValidLanguageUids(): ?array + { + return $this->validLanguageUids; + } } diff --git a/Classes/Exception/InvalidArgumentException.php b/Classes/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000..a13427d418 --- /dev/null +++ b/Classes/Exception/InvalidArgumentException.php @@ -0,0 +1,27 @@ + */ -class Item +class Item implements ItemInterface, MountPointAwareItemInterface { - public const STATE_BLOCKED = -1; - - public const STATE_PENDING = 0; - - public const STATE_INDEXED = 1; - /** * The item's uid in the index queue (tx_solr_indexqueue_item.uid) */ @@ -94,6 +88,13 @@ class Item */ protected ?int $recordUid = null; + /** + * The indexing priority + * + * @var int + */ + protected int $indexingPriority = 0; + /** * The record itself */ @@ -136,6 +137,7 @@ public function __construct( $this->indexingConfigurationName = $itemMetaData['indexing_configuration'] ?? ''; $this->hasIndexingProperties = (bool)($itemMetaData['has_indexing_properties'] ?? false); + $this->indexingPriority = (int)($itemMetaData['indexing_priority'] ?? 0); if (!empty($fullRecord)) { $this->record = $fullRecord; @@ -217,7 +219,7 @@ public function getType(): ?string return $this->type; } - public function setType($type): void + public function setType(string $type): void { $this->type = $type; } @@ -266,7 +268,7 @@ public function getRecordUid(): int { $this->getRecord(); - return $this->record['uid']; + return (int)$this->record['uid']; } /** @@ -439,4 +441,12 @@ public function getIndexingPropertyNames(): array $this->loadIndexingProperties(); return array_keys($this->indexingProperties); } + + /** + * Returns the index priority. + */ + public function getIndexPriority(): int + { + return $this->indexingPriority; + } } diff --git a/Classes/IndexQueue/ItemInterface.php b/Classes/IndexQueue/ItemInterface.php new file mode 100644 index 0000000000..5c6675c645 --- /dev/null +++ b/Classes/IndexQueue/ItemInterface.php @@ -0,0 +1,115 @@ + */ -class Queue +class Queue implements QueueInterface, QueueInitializationServiceAwareInterface { protected RootPageResolver $rootPageResolver; @@ -60,20 +60,18 @@ class Queue protected EventDispatcherInterface $eventDispatcher; public function __construct( - RootPageResolver $rootPageResolver = null, - ConfigurationAwareRecordService $recordService = null, - QueueItemRepository $queueItemRepository = null, - QueueStatisticsRepository $queueStatisticsRepository = null, - QueueInitializationService $queueInitializationService = null, - FrontendEnvironment $frontendEnvironment = null, - EventDispatcherInterface $eventDispatcher = null, + ?RootPageResolver $rootPageResolver = null, + ?ConfigurationAwareRecordService $recordService = null, + ?QueueItemRepository $queueItemRepository = null, + ?QueueStatisticsRepository $queueStatisticsRepository = null, + ?FrontendEnvironment $frontendEnvironment = null, + ?EventDispatcherInterface $eventDispatcher = null, ) { $this->logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__); $this->rootPageResolver = $rootPageResolver ?? GeneralUtility::makeInstance(RootPageResolver::class); $this->recordService = $recordService ?? GeneralUtility::makeInstance(ConfigurationAwareRecordService::class); $this->queueItemRepository = $queueItemRepository ?? GeneralUtility::makeInstance(QueueItemRepository::class); $this->queueStatisticsRepository = $queueStatisticsRepository ?? GeneralUtility::makeInstance(QueueStatisticsRepository::class); - $this->queueInitializationService = $queueInitializationService ?? GeneralUtility::makeInstance(QueueInitializationService::class, $this); $this->frontendEnvironment = $frontendEnvironment ?? GeneralUtility::makeInstance(FrontendEnvironment::class); $this->eventDispatcher = $eventDispatcher ?? GeneralUtility::makeInstance(EventDispatcherInterface::class); } @@ -113,14 +111,43 @@ public function getLastIndexedItemId(int $rootPageId): int return $lastIndexedItemId; } + public function setQueueInitializationService(QueueInitializationService $queueInitializationService): void + { + $this->queueInitializationService = $queueInitializationService; + } + /** * Returns the QueueInitializationService */ - public function getInitializationService(): QueueInitializationService + public function getQueueInitializationService(): QueueInitializationService { + if (!isset($this->queueInitializationService)) { + trigger_error( + 'queueInitializationService is no longer initalized automatically, till EXT:solr supports DI' + . ' the QueueInitializationService has to be set manually, fallback will be removed in v13.', + E_USER_DEPRECATED + ); + $this->queueInitializationService = GeneralUtility::makeInstance(QueueInitializationService::class); + } + return $this->queueInitializationService; } + /** + * @deprecated Queue->getInitializationService is deprecated and will be removed in v12. + * Use Queue->getQueueInitializationService instead or create a fresh instance. + */ + public function getInitializationService(): QueueInitializationService + { + trigger_error( + 'Queue->getInitializationService is deprecated and will be removed in v13.' + . ' Use Queue->getQueueInitializationService instead or create a fresh instance.', + E_USER_DEPRECATED + ); + + return $this->getQueueInitializationService(); + } + /** * Marks an item as needing (re)indexing. * @@ -134,11 +161,12 @@ public function getInitializationService(): QueueInitializationService */ public function updateItem( string $itemType, - int $itemUid, + int|string $itemUid, int $forcedChangeTime = 0, + ?array $validLanguageUids = null ): int { $updateCount = $this->updateOrAddItemForAllRelatedRootPages($itemType, $itemUid, $forcedChangeTime); - $event = new AfterIndexQueueItemHasBeenMarkedForReindexingEvent($itemType, $itemUid, $forcedChangeTime, $updateCount); + $event = new AfterIndexQueueItemHasBeenMarkedForReindexingEvent($itemType, $itemUid, $forcedChangeTime, $updateCount, $validLanguageUids); $event = $this->eventDispatcher->dispatch($event); return $event->getUpdateCount(); } @@ -156,7 +184,7 @@ protected function updateOrAddItemForAllRelatedRootPages( ): int { $updateCount = 0; try { - $rootPageIds = $this->rootPageResolver->getResponsibleRootPageIds($itemType, $itemUid); + $rootPageIds = $this->rootPageResolver->getResponsibleRootPageIds($itemType, (int)$itemUid); } catch (RootPageRecordNotFoundException $e) { $this->deleteItem($itemType, $itemUid); return 0; @@ -181,11 +209,11 @@ protected function updateOrAddItemForAllRelatedRootPages( continue; } $indexingPriority = $solrConfiguration->getIndexQueueIndexingPriorityByConfigurationName($indexingConfiguration); - $itemInQueueForRootPage = $this->containsItemWithRootPageId($itemType, $itemUid, $rootPageId); + $itemInQueueForRootPage = $this->containsItemWithRootPageId($itemType, $itemUid, $rootPageId, $indexingConfiguration); if ($itemInQueueForRootPage) { // update changed time if that item is in the queue already - $changedTime = ($forcedChangeTime > 0) ? $forcedChangeTime : $this->getItemChangedTime($itemType, $itemUid); - $updatedRows = $this->queueItemRepository->updateExistingItemByItemTypeAndItemUidAndRootPageId($itemType, $itemUid, $rootPageId, $changedTime, $indexingConfiguration, $indexingPriority); + $changedTime = ($forcedChangeTime > 0) ? $forcedChangeTime : $this->getItemChangedTime($itemType, (int)$itemUid); + $updatedRows = $this->queueItemRepository->updateExistingItemByItemTypeAndItemUidAndRootPageId($itemType, (int)$itemUid, $rootPageId, $changedTime, $indexingConfiguration, $indexingPriority); } else { // add the item since it's not in the queue yet $updatedRows = $this->addNewItem($itemType, $itemUid, $indexingConfiguration, $rootPageId, $indexingPriority); @@ -226,7 +254,7 @@ public function resetErrorsBySite(Site $site): int /** * Resets the error in the index queue for a specific item */ - public function resetErrorByItem(Item $item): int + public function resetErrorByItem(ItemInterface $item): int { return $this->queueItemRepository->flushErrorByItem($item); } @@ -249,15 +277,15 @@ private function addNewItem( $additionalRecordFields = ', doktype, uid'; } - $record = $this->getRecordCached($itemType, $itemUid, $additionalRecordFields); + $record = $this->getRecordCached($itemType, (int)$itemUid, $additionalRecordFields); if (empty($record) || ($itemType === 'pages' && !$this->frontendEnvironment->isAllowedPageType($record, $indexingConfiguration))) { return 0; } - $changedTime = $this->getItemChangedTime($itemType, $itemUid); + $changedTime = $this->getItemChangedTime($itemType, (int)$itemUid); - return $this->queueItemRepository->add($itemType, $itemUid, $rootPageId, $changedTime, $indexingConfiguration, $indexingPriority); + return $this->queueItemRepository->add($itemType, (int)$itemUid, $rootPageId, $changedTime, $indexingConfiguration, $indexingPriority); } /** @@ -269,7 +297,7 @@ protected function getRecordCached( string $additionalRecordFields, ): ?array { $cache = GeneralUtility::makeInstance(TwoLevelCache::class, 'runtime'); - $cacheId = md5('Queue' . ':' . 'getRecordCached' . ':' . $itemType . ':' . $itemUid . ':' . 'pid' . $additionalRecordFields); + $cacheId = md5('Queue' . ':' . 'getRecordCached' . ':' . $itemType . ':' . (string)$itemUid . ':' . 'pid' . $additionalRecordFields); $record = $cache->get($cacheId); if (empty($record)) { @@ -324,7 +352,7 @@ protected function getItemChangedTime( $pageChangedTime = $this->getPageItemChangedTime($record); } - $localizationsChangedTime = $this->queueItemRepository->getLocalizableItemChangedTime($itemType, (int)$itemUid); + $localizationsChangedTime = $this->queueItemRepository->getLocalizableItemChangedTime($itemType, $itemUid); // if start time exists and start time is higher than last changed timestamp // then set changed to the future start time to make the item @@ -358,7 +386,7 @@ protected function getPageItemChangedTime(array $page): int */ public function containsItem( string $itemType, - int $itemUid, + int|string $itemUid, ): bool { return $this->queueItemRepository->containsItem($itemType, (int)$itemUid); } @@ -370,10 +398,11 @@ public function containsItem( */ public function containsItemWithRootPageId( string $itemType, - int $itemUid, + int|string $itemUid, int $rootPageId, + string $indexingConfiguration ): bool { - return $this->queueItemRepository->containsItemWithRootPageId($itemType, (int)$itemUid, $rootPageId); + return $this->queueItemRepository->containsItemWithRootPageId($itemType, (int)$itemUid, $rootPageId, $indexingConfiguration); } /** @@ -384,7 +413,7 @@ public function containsItemWithRootPageId( */ public function containsIndexedItem( string $itemType, - int $itemUid, + int|string $itemUid, ): bool { return $this->queueItemRepository->containsIndexedItem($itemType, (int)$itemUid); } @@ -396,7 +425,7 @@ public function containsIndexedItem( */ public function deleteItem( string $itemType, - int $itemUid, + int|string $itemUid, ): void { $this->queueItemRepository->deleteItem($itemType, (int)$itemUid); } @@ -437,7 +466,7 @@ public function deleteAllItems(): int * * @throws DBALException */ - public function getItem(int $itemId): ?Item + public function getItem(int|string $itemId): ?Item { return $this->queueItemRepository->findItemByUid($itemId); } @@ -451,7 +480,7 @@ public function getItem(int $itemId): ?Item */ public function getItems( string $itemType, - int $itemUid, + int|string $itemUid, ): array { return $this->queueItemRepository->findItemsByItemTypeAndItemUid($itemType, (int)$itemUid); } @@ -508,24 +537,24 @@ public function getItemsToIndex(Site $site, int $limit = 50): array * Marks an item as failed and causes the indexer to skip the item in the * next run. */ - public function markItemAsFailed(Item|int|null $item, string $errorMessage = ''): void + public function markItemAsFailed(ItemInterface|int|null $item, string $errorMessage = ''): int { - $this->queueItemRepository->markItemAsFailed($item, $errorMessage); + return $this->queueItemRepository->markItemAsFailed($item, $errorMessage); } /** * Sets the timestamp of when an item last has been indexed. */ - public function updateIndexTimeByItem(Item $item): void + public function updateIndexTimeByItem(ItemInterface $item): int { - $this->queueItemRepository->updateIndexTimeByItem($item); + return $this->queueItemRepository->updateIndexTimeByItem($item); } /** * Sets the change timestamp of an item. */ - public function setForcedChangeTimeByItem(Item $item, int $forcedChangeTime = 0): void + public function setForcedChangeTimeByItem(ItemInterface $item, int $forcedChangeTime = 0): int { - $this->queueItemRepository->updateChangedTimeByItem($item, $forcedChangeTime); + return $this->queueItemRepository->updateChangedTimeByItem($item, $forcedChangeTime); } } diff --git a/Classes/IndexQueue/QueueInitializationServiceAwareInterface.php b/Classes/IndexQueue/QueueInitializationServiceAwareInterface.php new file mode 100644 index 0000000000..9b850e82c0 --- /dev/null +++ b/Classes/IndexQueue/QueueInitializationServiceAwareInterface.php @@ -0,0 +1,36 @@ +getValueByPathOrDefaultValue($path, $defaultIfEmpty); } + /** + * This method is used to retrieve the className of a queue initializer for a certain indexing configuration + * + * plugin.tx_solr.index.queue..indexQueue + * + * @param string $configurationName + * @return string + */ + public function getIndexQueueClassByConfigurationName(string $configurationName): string + { + $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexQueue'; + return (string)$this->getValueByPathOrDefaultValue($path, Queue::class); + } + /** * Returns the _LOCAL_LANG configuration from the TypoScript. * diff --git a/Classes/System/Environment/WebRootAllReadyDefinedException.php b/Classes/System/Environment/WebRootAllReadyDefinedException.php index e067cd4cb0..1788c5ee02 100644 --- a/Classes/System/Environment/WebRootAllReadyDefinedException.php +++ b/Classes/System/Environment/WebRootAllReadyDefinedException.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\System\Environment; -use Exception; +use ApacheSolrForTypo3\Solr\Exception; /** * Exception that is thrown when a language file is needed, but not available. diff --git a/Classes/System/Object/AbstractClassRegistry.php b/Classes/System/Object/AbstractClassRegistry.php index a96234ba67..9d8ce25ce5 100644 --- a/Classes/System/Object/AbstractClassRegistry.php +++ b/Classes/System/Object/AbstractClassRegistry.php @@ -17,7 +17,7 @@ namespace ApacheSolrForTypo3\Solr\System\Object; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use stdClass; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/System/Records/AbstractRepository.php b/Classes/System/Records/AbstractRepository.php index 5e7895d5fd..166b9cd245 100644 --- a/Classes/System/Records/AbstractRepository.php +++ b/Classes/System/Records/AbstractRepository.php @@ -17,8 +17,8 @@ namespace ApacheSolrForTypo3\Solr\System\Records; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use RuntimeException; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; diff --git a/Classes/System/Records/Pages/PagesRepository.php b/Classes/System/Records/Pages/PagesRepository.php index d3eb1425e0..5f51cd9c30 100644 --- a/Classes/System/Records/Pages/PagesRepository.php +++ b/Classes/System/Records/Pages/PagesRepository.php @@ -17,11 +17,11 @@ namespace ApacheSolrForTypo3\Solr\System\Records\Pages; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache; use ApacheSolrForTypo3\Solr\System\Records\AbstractRepository; use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use PDO; use Throwable; use TYPO3\CMS\Backend\Utility\BackendUtility; diff --git a/Classes/System/Solr/Parser/StopWordParser.php b/Classes/System/Solr/Parser/StopWordParser.php index 42581021c5..c4f9038c6e 100644 --- a/Classes/System/Solr/Parser/StopWordParser.php +++ b/Classes/System/Solr/Parser/StopWordParser.php @@ -15,7 +15,7 @@ namespace ApacheSolrForTypo3\Solr\System\Solr\Parser; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; /** * Class to parse the stopwords from a solr response. diff --git a/Classes/System/Solr/Service/SolrAdminService.php b/Classes/System/Solr/Service/SolrAdminService.php index 503268ffad..f0d47c72ff 100644 --- a/Classes/System/Solr/Service/SolrAdminService.php +++ b/Classes/System/Solr/Service/SolrAdminService.php @@ -17,6 +17,7 @@ namespace ApacheSolrForTypo3\Solr\System\Solr\Service; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use ApacheSolrForTypo3\Solr\System\Solr\Parser\SchemaParser; @@ -24,7 +25,6 @@ use ApacheSolrForTypo3\Solr\System\Solr\Parser\SynonymParser; use ApacheSolrForTypo3\Solr\System\Solr\ResponseAdapter; use ApacheSolrForTypo3\Solr\System\Solr\Schema\Schema; -use InvalidArgumentException; use Solarium\Client; use stdClass; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/Task/AbstractSolrTask.php b/Classes/Task/AbstractSolrTask.php index af041e754c..c96a40fb18 100644 --- a/Classes/Task/AbstractSolrTask.php +++ b/Classes/Task/AbstractSolrTask.php @@ -19,9 +19,9 @@ use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Scheduler\Task\AbstractTask; diff --git a/Classes/Task/EventQueueWorkerTask.php b/Classes/Task/EventQueueWorkerTask.php index 612119e21e..5483e74988 100644 --- a/Classes/Task/EventQueueWorkerTask.php +++ b/Classes/Task/EventQueueWorkerTask.php @@ -19,10 +19,10 @@ use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\DelayedProcessingFinishedEvent; use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\DataUpdateEventInterface; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use ApacheSolrForTypo3\Solr\System\Records\Queue\EventQueueItemRepository; use Doctrine\DBAL\Exception as DBALException; -use InvalidArgumentException; use Psr\EventDispatcher\EventDispatcherInterface; use Throwable; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/Task/ReIndexTask.php b/Classes/Task/ReIndexTask.php index c460b387f2..745a545b77 100644 --- a/Classes/Task/ReIndexTask.php +++ b/Classes/Task/ReIndexTask.php @@ -18,7 +18,7 @@ namespace ApacheSolrForTypo3\Solr\Task; use ApacheSolrForTypo3\Solr\ConnectionManager; -use ApacheSolrForTypo3\Solr\IndexQueue\Queue; +use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueInitializationService; use Doctrine\DBAL\ConnectionException as DBALConnectionException; use Doctrine\DBAL\Exception as DBALException; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -53,9 +53,9 @@ public function execute() $cleanUpResult = $this->cleanUpIndex(); // initialize for re-indexing - /** @var Queue $indexQueue */ - $indexQueue = GeneralUtility::makeInstance(Queue::class); - $indexQueueInitializationResults = $indexQueue->getInitializationService() + /** @var QueueInitializationService $indexQueueInitializationService */ + $indexQueueInitializationService = GeneralUtility::makeInstance(QueueInitializationService::class); + $indexQueueInitializationResults = $indexQueueInitializationService ->initializeBySiteAndIndexConfigurations($this->getSite(), $this->indexingConfigurationsToReIndex); return $cleanUpResult && !in_array(false, $indexQueueInitializationResults); diff --git a/Classes/Utility/ManagedResourcesUtility.php b/Classes/Utility/ManagedResourcesUtility.php index 64755b9672..1e8ecf95c5 100644 --- a/Classes/Utility/ManagedResourcesUtility.php +++ b/Classes/Utility/ManagedResourcesUtility.php @@ -17,7 +17,7 @@ namespace ApacheSolrForTypo3\Solr\Utility; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use TYPO3\CMS\Core\Http\Stream; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/ViewHelpers/Backend/Security/IfHasAccessToModuleViewHelper.php b/Classes/ViewHelpers/Backend/Security/IfHasAccessToModuleViewHelper.php index 7ac72d3721..326b48d5f8 100644 --- a/Classes/ViewHelpers/Backend/Security/IfHasAccessToModuleViewHelper.php +++ b/Classes/ViewHelpers/Backend/Security/IfHasAccessToModuleViewHelper.php @@ -17,7 +17,7 @@ namespace ApacheSolrForTypo3\Solr\ViewHelpers\Backend\Security; -use InvalidArgumentException; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use RuntimeException; use TYPO3\CMS\Backend\Module\ModuleProvider; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/ViewHelpers/Uri/AbstractUriViewHelper.php b/Classes/ViewHelpers/Uri/AbstractUriViewHelper.php index 57cf2d8db3..17d96453f9 100644 --- a/Classes/ViewHelpers/Uri/AbstractUriViewHelper.php +++ b/Classes/ViewHelpers/Uri/AbstractUriViewHelper.php @@ -20,8 +20,8 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequest; use ApacheSolrForTypo3\Solr\Domain\Search\Uri\SearchUriBuilder; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper; -use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext; diff --git a/Classes/ViewHelpers/Uri/Facet/AbstractValueViewHelper.php b/Classes/ViewHelpers/Uri/Facet/AbstractValueViewHelper.php index 97bfe5b056..c849903cdb 100644 --- a/Classes/ViewHelpers/Uri/Facet/AbstractValueViewHelper.php +++ b/Classes/ViewHelpers/Uri/Facet/AbstractValueViewHelper.php @@ -18,8 +18,8 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacet; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacetItem; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\ViewHelpers\Uri\AbstractUriViewHelper; -use InvalidArgumentException; /** * Class AbstractValueViewHelper diff --git a/Documentation/Configuration/Reference/TxSolrIndex.rst b/Documentation/Configuration/Reference/TxSolrIndex.rst index 746624f034..3b0bd3039d 100644 --- a/Documentation/Configuration/Reference/TxSolrIndex.rst +++ b/Documentation/Configuration/Reference/TxSolrIndex.rst @@ -224,6 +224,16 @@ Defines the type to index, which is usally the database table. Sometimes you may +queue.[indexConfig].indexQueue +------------------------------ + +:Type: String +:TS Path: plugin.tx_solr.index.queue.[indexConfig].indexQueue +:Since: 11.6 +:Default: + +Class name of custom index queue implementation, falls back to the default index queue (ApacheSolrForTypo3\Solr\IndexQueue\Queue). + queue.[indexConfig].initialization ---------------------------------- diff --git a/Tests/Integration/Domain/Site/SiteRepositoryTest.php b/Tests/Integration/Domain/Site/SiteRepositoryTest.php index 7bf92231ea..63dd42595b 100644 --- a/Tests/Integration/Domain/Site/SiteRepositoryTest.php +++ b/Tests/Integration/Domain/Site/SiteRepositoryTest.php @@ -17,8 +17,8 @@ use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest; -use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** diff --git a/Tests/Integration/Domain/Site/SiteTest.php b/Tests/Integration/Domain/Site/SiteTest.php index cb883fc3b6..b8608deea1 100644 --- a/Tests/Integration/Domain/Site/SiteTest.php +++ b/Tests/Integration/Domain/Site/SiteTest.php @@ -17,8 +17,8 @@ use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest; -use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** diff --git a/Tests/Integration/IndexQueue/QueueTest.php b/Tests/Integration/IndexQueue/QueueTest.php index 91788de63d..3f92597471 100644 --- a/Tests/Integration/IndexQueue/QueueTest.php +++ b/Tests/Integration/IndexQueue/QueueTest.php @@ -15,6 +15,7 @@ namespace ApacheSolrForTypo3\Solr\Tests\Integration\IndexQueue; +use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueInitializationService; use ApacheSolrForTypo3\Solr\Domain\Site\Site; use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; use ApacheSolrForTypo3\Solr\IndexQueue\Queue; @@ -43,6 +44,7 @@ protected function setUp(): void parent::setUp(); $this->writeDefaultSolrTestSiteConfiguration(); $this->indexQueue = GeneralUtility::makeInstance(Queue::class); + $this->indexQueue->setQueueInitializationService(GeneralUtility::makeInstance(QueueInitializationService::class)); $this->siteRepository = GeneralUtility::makeInstance(SiteRepository::class); } @@ -75,7 +77,7 @@ public function preFilledQueueContainsRootPageAfterInitialize() // after initialize the prefilled queue item should be lost and the root page should be added again $site = $this->siteRepository->getFirstAvailableSite(); - $this->indexQueue->getInitializationService()->initializeBySiteAndIndexConfiguration($site, 'pages'); + $this->indexQueue->getQueueInitializationService()->initializeBySiteAndIndexConfiguration($site, 'pages'); $this->assertItemsInQueue(1); self::assertTrue($this->indexQueue->containsItem('pages', 1)); @@ -152,10 +154,10 @@ public function mountPagesAreOnlyAddedOnceAfterInitialize() $this->assertEmptyQueue(); $site = $this->siteRepository->getFirstAvailableSite(); - $this->indexQueue->getInitializationService()->initializeBySiteAndIndexConfiguration($site, 'pages'); + $this->indexQueue->getQueueInitializationService()->initializeBySiteAndIndexConfiguration($site, 'pages'); $this->assertItemsInQueue(4); - $this->indexQueue->getInitializationService()->initializeBySiteAndIndexConfiguration($site, 'pages'); + $this->indexQueue->getQueueInitializationService()->initializeBySiteAndIndexConfiguration($site, 'pages'); $this->assertItemsInQueue(4); } @@ -188,7 +190,7 @@ public function canAddCustomPageTypeToTheQueue() }' ); $site = $this->siteRepository->getFirstAvailableSite(); - $this->indexQueue->getInitializationService()->initializeBySiteAndIndexConfiguration($site, 'custom_page_type'); + $this->indexQueue->getQueueInitializationService()->initializeBySiteAndIndexConfiguration($site, 'custom_page_type'); $this->assertItemsInQueue(1); @@ -244,7 +246,7 @@ public function canInitializeMultipleSites() if (is_array($availableSites)) { foreach ($availableSites as $site) { if ($site instanceof Site) { - $this->indexQueue->getInitializationService()->initializeBySiteAndIndexConfiguration($site); + $this->indexQueue->getQueueInitializationService()->initializeBySiteAndIndexConfiguration($site); } } } diff --git a/Tests/Integration/IntegrationTest.php b/Tests/Integration/IntegrationTest.php index d35d49c260..4dc26a4e46 100644 --- a/Tests/Integration/IntegrationTest.php +++ b/Tests/Integration/IntegrationTest.php @@ -16,9 +16,9 @@ namespace ApacheSolrForTypo3\Solr\Tests\Integration; use ApacheSolrForTypo3\Solr\Access\Rootline; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\IndexQueue\Item; use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest; -use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use ReflectionClass; use ReflectionException; diff --git a/Tests/Unit/Controller/Backend/Search/IndexQueueModuleControllerTest.php b/Tests/Unit/Controller/Backend/Search/IndexQueueModuleControllerTest.php index c1a368a329..40123fb6b2 100644 --- a/Tests/Unit/Controller/Backend/Search/IndexQueueModuleControllerTest.php +++ b/Tests/Unit/Controller/Backend/Search/IndexQueueModuleControllerTest.php @@ -16,7 +16,6 @@ namespace ApacheSolrForTypo3\Solr\Tests\Unit\Controller\Backend\Search; use ApacheSolrForTypo3\Solr\Controller\Backend\Search\IndexQueueModuleController; -use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueInitializationService; use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueItemRepository; use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\ConfigurationAwareRecordService; use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver; @@ -57,7 +56,6 @@ protected function setUp(): void $this->createMock(ConfigurationAwareRecordService::class), $this->createMock(QueueItemRepository::class), $this->createMock(QueueStatisticsRepository::class), - $this->createMock(QueueInitializationService::class), $this->createMock(FrontendEnvironment::class), $this->eventDispatcher, ]) diff --git a/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php b/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php index 9f8248f536..62392ca2bb 100644 --- a/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php +++ b/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php @@ -38,6 +38,7 @@ use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher; +use TYPO3\CMS\Core\Utility\GeneralUtility; /** * @author Timo Hund @@ -50,7 +51,9 @@ class QueueInitializerServiceTest extends SetUpUnitTestCase public function allIndexConfigurationsAreUsedWhenWildcardIsPassed(): void { $queueMock = $this->createMock(Queue::class); - $service = $this->getMockBuilder(QueueInitializationService::class)->onlyMethods(['executeInitializer'])->setConstructorArgs([$queueMock, new NoopEventDispatcher()])->getMock(); + GeneralUtility::addInstance(Queue::class, $queueMock); + GeneralUtility::addInstance(Queue::class, $queueMock); + $service = $this->getMockBuilder(QueueInitializationService::class)->onlyMethods(['executeInitializer'])->setConstructorArgs([new NoopEventDispatcher()])->getMock(); $fakeTs = [ 'plugin.' => [ diff --git a/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php b/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php index 7dd1b3c870..ed062f6a93 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php @@ -17,9 +17,9 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetRegistry; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options\OptionsPackage; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Search\ResultSet\Facets\TestPackage\TestPackage; use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; -use InvalidArgumentException; use PHPUnit\Framework\MockObject\MockObject; /** diff --git a/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php b/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php index 31fdee15cf..e15e67166a 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php @@ -16,8 +16,8 @@ namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Search\ResultSet\Facets\RangeBased\NumericRange; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\NumericRange\NumericRangeUrlDecoder; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; -use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** diff --git a/Tests/Unit/Domain/Search/ResultSet/Facets/RequirementsServiceTest.php b/Tests/Unit/Domain/Search/ResultSet/Facets/RequirementsServiceTest.php index 3632e8c378..1422d4099b 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Facets/RequirementsServiceTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Facets/RequirementsServiceTest.php @@ -19,6 +19,7 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options\OptionsFacet; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RequirementsService; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -229,7 +230,7 @@ public function getAllRequirementsMetIsReturnsFalseIfRequiredFacetValueIsNotSele */ public function exceptionIsThrownForRequirementWithNotExistingFacet() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Requirement for unexisting facet configured'); $resultSet = new SearchResultSet(); diff --git a/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingHelperTest.php b/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingHelperTest.php index 3820e42515..f4700a2891 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingHelperTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingHelperTest.php @@ -16,6 +16,7 @@ namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Search\ResultSet\Sorting; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Sorting\SortingHelper; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; /** @@ -49,7 +50,7 @@ public function canGetSortFieldFromUrlParameter() */ public function canThrowExceptionForUnconfiguredSorting() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('No sorting configuration found for option name unconfigured'); $sorting = new SortingHelper([]); $sorting->getSortFieldFromUrlParameter('unconfigured asc'); diff --git a/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingTest.php b/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingTest.php index a2dcd72485..44e3ccc594 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Sorting/SortingTest.php @@ -17,6 +17,7 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Sorting\Sorting; +use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; /** @@ -55,7 +56,7 @@ protected function setUp(): void */ public function canNotCreateWhenInvalidDirectionIsPassed() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new Sorting($this->resultSetMock, 'Color', 'color_s', 'invalid direction', 'the color', false, false); } diff --git a/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php b/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php index 75c470951b..c0df7c41c3 100644 --- a/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php +++ b/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php @@ -15,6 +15,8 @@ namespace ApacheSolrForTypo3\Solr\Tests\Unit\System\Configuration; +use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Record; +use ApacheSolrForTypo3\Solr\IndexQueue\Queue; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; @@ -316,7 +318,6 @@ public function canGetIndexQueueConfigurationNamesByTableName() 'custom_one.' => [ 'type' => 'tx_model_bar', ], - 'custom_two' => 1, 'custom_two.' => [ 'type' => 'tx_model_news', @@ -329,6 +330,54 @@ public function canGetIndexQueueConfigurationNamesByTableName() self::assertEquals(['tx_model_news', 'custom_two'], $configuration->getIndexQueueConfigurationNamesByTableName('tx_model_news')); } + /** + * @test + */ + public function canGetIndexQueueInitializerClassByConfigurationName() + { + $fakeConfigurationArray['plugin.']['tx_solr.'] = [ + 'index.' => [ + 'queue.' => [ + 'tx_model_news' => 1, + 'tx_model_news.' => [ + ], + 'custom_one' => 1, + 'custom_one.' => [ + 'initialization' => 'CustomInitializer', + ], + ], + ], + ]; + + $configuration = new TypoScriptConfiguration($fakeConfigurationArray); + self::assertEquals(Record::class, $configuration->getIndexQueueInitializerClassByConfigurationName('tx_model_news')); + self::assertEquals('CustomInitializer', $configuration->getIndexQueueInitializerClassByConfigurationName('custom_one')); + } + + /** + * @test + */ + public function canGetIndexQueueClassByConfigurationName() + { + $fakeConfigurationArray['plugin.']['tx_solr.'] = [ + 'index.' => [ + 'queue.' => [ + 'tx_model_news' => 1, + 'tx_model_news.' => [ + ], + 'custom_one' => 1, + 'custom_one.' => [ + 'indexQueue' => 'CustomQueue', + ], + ], + ], + ]; + + $configuration = new TypoScriptConfiguration($fakeConfigurationArray); + self::assertEquals(Queue::class, $configuration->getIndexQueueClassByConfigurationName('tx_model_news')); + self::assertEquals('CustomQueue', $configuration->getIndexQueueClassByConfigurationName('custom_one')); + } + /** * @test */