diff --git a/Classes/IndexQueue/Indexer.php b/Classes/IndexQueue/Indexer.php index 9da348a1bf..a2a6de00ea 100644 --- a/Classes/IndexQueue/Indexer.php +++ b/Classes/IndexQueue/Indexer.php @@ -195,7 +195,7 @@ protected function indexItem(Item $item, int $language = 0): bool $documents[] = $itemDocument; $documents = array_merge($documents, $this->getAdditionalDocuments($item, $language, $itemDocument)); $documents = $this->processDocuments($item, $documents); - $documents = $this->preAddModifyDocuments($item, $language, $documents); + $documents = self::preAddModifyDocuments($item, $language, $documents); try { $response = $this->solr->getWriteService()->addDocuments($documents); @@ -531,7 +531,7 @@ protected function getAdditionalDocuments(Item $item, int $language, Document $i * @param array $documents An array of documents to be indexed * @return array An array of modified documents */ - protected function preAddModifyDocuments(Item $item, int $language, array $documents): array + public static function preAddModifyDocuments(Item $item, int $language, array $documents): array { if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'] ?? null)) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'] as $classReference) { diff --git a/Classes/PageDocumentPostProcessor.php b/Classes/PageDocumentPostProcessor.php index 1d69d25cb0..024304f1f8 100644 --- a/Classes/PageDocumentPostProcessor.php +++ b/Classes/PageDocumentPostProcessor.php @@ -25,6 +25,8 @@ * have been put together, but not yet submitted to Solr. * * @author Steffen Ritter + * + * @deprecated in favor of PageIndexerDocumentsModifier */ interface PageDocumentPostProcessor { diff --git a/Classes/Typo3PageIndexer.php b/Classes/Typo3PageIndexer.php index 3de7301267..bee8abbcfb 100644 --- a/Classes/Typo3PageIndexer.php +++ b/Classes/Typo3PageIndexer.php @@ -21,6 +21,7 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ApacheSolrDocument\Builder; use ApacheSolrForTypo3\Solr\FieldProcessor\Service; use ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\PageFieldMappingIndexer; +use ApacheSolrForTypo3\Solr\IndexQueue\Indexer; use ApacheSolrForTypo3\Solr\IndexQueue\Item; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; @@ -258,6 +259,11 @@ public function indexPage(): bool $documents[] = $pageDocument; $documents = $this->getAdditionalDocuments($pageDocument, $documents); $this->processDocuments($documents); + $documents = Indexer::preAddModifyDocuments( + $this->indexQueueItem, + $this->page->getLanguage()->getLanguageId(), + $documents + ); $pageIndexed = $this->addDocumentsToSolrIndex($documents); $this->documentsSentToSolr = $documents; @@ -268,6 +274,8 @@ public function indexPage(): bool /** * Applies the configured post processors (indexPagePostProcessPageDocument) * + * @deprecated + * * @param Document $pageDocument */ protected function applyIndexPagePostProcessors(Document $pageDocument) @@ -276,6 +284,11 @@ protected function applyIndexPagePostProcessors(Document $pageDocument) return; } + trigger_error( + "The hook indexPagePostProcessPageDocument has been superseded by \$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments']", + E_USER_DEPRECATED + ); + foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPagePostProcessPageDocument'] as $classReference) { $postProcessor = GeneralUtility::makeInstance($classReference); if (!$postProcessor instanceof PageDocumentPostProcessor) { diff --git a/Documentation/Development/Indexing.rst b/Documentation/Development/Indexing.rst index 7a59790666..e8b53c351b 100644 --- a/Documentation/Development/Indexing.rst +++ b/Documentation/Development/Indexing.rst @@ -32,12 +32,23 @@ Required Interface: SubstitutePageIndexer indexPagePostProcessPageDocument -------------------------------- +This is deprecated in favor of preAddModifyDocuments. + Registered classes can be used to post process a Solr document of a page. Registration with: $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPagePostProcessPageDocument'] Required Interface: PageDocumentPostProcessor +preAddModifyDocuments +--------------------- + +Registered classes can be used to process Solr documents (pages and records) before they are added to index. + +Registration with: $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'] +Required Interface: PageIndexerDocumentsModifier + + Independent indexer =================== diff --git a/Tests/Integration/Controller/AbstractFrontendControllerTest.php b/Tests/Integration/Controller/AbstractFrontendControllerTest.php index 9e676d66b9..7cf1c783bb 100644 --- a/Tests/Integration/Controller/AbstractFrontendControllerTest.php +++ b/Tests/Integration/Controller/AbstractFrontendControllerTest.php @@ -17,6 +17,7 @@ use ApacheSolrForTypo3\Solr\FrontendEnvironment\Exception\Exception as SolrFrontendEnvironmentException; use ApacheSolrForTypo3\Solr\FrontendEnvironment\Tsfe; +use ApacheSolrForTypo3\Solr\IndexQueue\Item; use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTest; use ApacheSolrForTypo3\Solr\Typo3PageIndexer; use Doctrine\DBAL\DBALException; @@ -75,6 +76,11 @@ protected function indexPages($importPageIds) /* @var $pageIndexer Typo3PageIndexer */ $pageIndexer = GeneralUtility::makeInstance(Typo3PageIndexer::class, $fakeTSFE); + $indexQueueItemMock = $this->createMock(Item::class); + $indexQueueItemMock->expects(self::any()) + ->method('getIndexingConfigurationName') + ->willReturn('pages'); + $pageIndexer->setIndexQueueItem($indexQueueItemMock); $pageIndexer->indexPage(); } $this->waitToBeVisibleInSolr(); diff --git a/Tests/Integration/IndexQueue/FrontendHelper/PageIndexerTest.php b/Tests/Integration/IndexQueue/FrontendHelper/PageIndexerTest.php index 94af0ba928..13ab7c749d 100644 --- a/Tests/Integration/IndexQueue/FrontendHelper/PageIndexerTest.php +++ b/Tests/Integration/IndexQueue/FrontendHelper/PageIndexerTest.php @@ -211,7 +211,7 @@ public function canIndexPageIntoSolrWithAdditionalFieldsFromRootLine() */ public function canExecutePostProcessor() { - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPagePostProcessPageDocument']['TestPostProcessor'] = TestPostProcessor::class; + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments']['TestPageIndexerDocumentsModifier'] = TestPageIndexerDocumentsModifier::class; $this->importDataSetFromFixture('can_index_into_solr.xml'); $this->executePageIndexer(); diff --git a/Tests/Integration/IndexQueue/FrontendHelper/TestPageIndexerDocumentsModifier.php b/Tests/Integration/IndexQueue/FrontendHelper/TestPageIndexerDocumentsModifier.php new file mode 100644 index 0000000000..2e1f898f53 --- /dev/null +++ b/Tests/Integration/IndexQueue/FrontendHelper/TestPageIndexerDocumentsModifier.php @@ -0,0 +1,27 @@ +addField('postProcessorField_stringS', 'postprocessed'); + } + + return $documents; + } +} diff --git a/Tests/Integration/IntegrationTest.php b/Tests/Integration/IntegrationTest.php index 52f7e76d74..80e2dcbe88 100644 --- a/Tests/Integration/IntegrationTest.php +++ b/Tests/Integration/IntegrationTest.php @@ -16,6 +16,7 @@ namespace ApacheSolrForTypo3\Solr\Tests\Integration; use ApacheSolrForTypo3\Solr\Access\Rootline; +use ApacheSolrForTypo3\Solr\IndexQueue\Item; use ApacheSolrForTypo3\Solr\Tests\Unit\Helper\FakeObjectManager; use ApacheSolrForTypo3\Solr\Typo3PageIndexer; use Doctrine\DBAL\DBALException; @@ -340,8 +341,13 @@ protected function indexPageIds(array $importPageIds, array $feUserGroupArray = foreach ($importPageIds as $importPageId) { $fakeTSFE = $this->fakeTSFE($importPageId, $feUserGroupArray); - /** @var $pageIndexer Typo3PageIndexer */ + /* @var Typo3PageIndexer $pageIndexer */ $pageIndexer = GeneralUtility::makeInstance(Typo3PageIndexer::class, $fakeTSFE); + $indexQueueItemMock = $this->createMock(Item::class); + $indexQueueItemMock->expects(self::any()) + ->method('getIndexingConfigurationName') + ->willReturn('pages'); + $pageIndexer->setIndexQueueItem($indexQueueItemMock); $pageIndexer->setPageAccessRootline(Rootline::getAccessRootlineByPageId($importPageId)); $pageIndexer->indexPage(); } diff --git a/Tests/Integration/SearchTest.php b/Tests/Integration/SearchTest.php index 9583d9fe81..8ed9219ddc 100644 --- a/Tests/Integration/SearchTest.php +++ b/Tests/Integration/SearchTest.php @@ -21,6 +21,7 @@ use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Slops; use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\TrigramPhraseFields; use ApacheSolrForTypo3\Solr\Domain\Search\Query\QueryBuilder; +use ApacheSolrForTypo3\Solr\IndexQueue\Item; use ApacheSolrForTypo3\Solr\Search; use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; @@ -71,8 +72,13 @@ public function canSearchForADocument() $fakeTSFE = $this->getConfiguredTSFE(); $GLOBALS['TSFE'] = $fakeTSFE; - /** @var $pageIndexer \ApacheSolrForTypo3\Solr\Typo3PageIndexer */ + /* @var Typo3PageIndexer $pageIndexer */ $pageIndexer = GeneralUtility::makeInstance(Typo3PageIndexer::class, $fakeTSFE); + $indexQueueItemMock = $this->createMock(Item::class); + $indexQueueItemMock->expects(self::any()) + ->method('getIndexingConfigurationName') + ->willReturn('pages'); + $pageIndexer->setIndexQueueItem($indexQueueItemMock); $pageIndexer->indexPage(); $this->waitToBeVisibleInSolr(); @@ -435,8 +441,13 @@ protected function fillIndexForPhraseSearchTests(string $fixture = 'phrase_searc $fakeTSFE = $this->getConfiguredTSFE($i); $GLOBALS['TSFE'] = $fakeTSFE; - /** @var $pageIndexer \ApacheSolrForTypo3\Solr\Typo3PageIndexer */ + /* @var Typo3PageIndexer $pageIndexer */ $pageIndexer = GeneralUtility::makeInstance(Typo3PageIndexer::class, $fakeTSFE); + $indexQueueItemMock = $this->createMock(Item::class); + $indexQueueItemMock->expects(self::any()) + ->method('getIndexingConfigurationName') + ->willReturn('pages'); + $pageIndexer->setIndexQueueItem($indexQueueItemMock); $pageIndexer->indexPage(); } $this->waitToBeVisibleInSolr();