From d281bf6425e64933593319ae859ffde57d39f45c Mon Sep 17 00:00:00 2001 From: Markus Friedrich Date: Wed, 31 Aug 2022 11:02:54 +0200 Subject: [PATCH] [TASK] Introduce index queue type setting Queue types shouldn't be restricted to internal data, which is already prepared in some classes. As index queue setting 'table' suggests that a local table is expected, this is replaced with a new setting 'type'. queue.[indexConfig].table is now deprecated and will be removed in v13, 'type' should be used instead. Resolves: #3365 --- .../IndexingConfigurationSelectorField.php | 2 +- .../Queue/QueueInitializationService.php | 10 ++-- .../ConfigurationAwareRecordService.php | 2 +- .../Configuration/TypoScriptConfiguration.php | 49 +++++++++++++++--- Classes/Task/ReIndexTask.php | 2 +- .../Examples/IndexQueueNews/setup.typoscript | 4 +- .../Configuration/Reference/TxSolrIndex.rst | 16 ++++-- .../Queue/QueueInitializerServiceTest.php | 4 +- .../TypoScriptConfigurationTest.php | 50 +++++++++++++++---- 9 files changed, 108 insertions(+), 31 deletions(-) diff --git a/Classes/Backend/IndexingConfigurationSelectorField.php b/Classes/Backend/IndexingConfigurationSelectorField.php index 2d50956e98..45189d7ef8 100644 --- a/Classes/Backend/IndexingConfigurationSelectorField.php +++ b/Classes/Backend/IndexingConfigurationSelectorField.php @@ -137,7 +137,7 @@ protected function getIndexQueueConfigurationTableMap(): array $solrConfiguration = $this->site->getSolrConfiguration(); $configurationNames = $solrConfiguration->getEnabledIndexQueueConfigurationNames(); foreach ($configurationNames as $configurationName) { - $indexingTableMap[$configurationName] = $solrConfiguration->getIndexQueueTableNameOrFallbackToConfigurationName($configurationName); + $indexingTableMap[$configurationName] = $solrConfiguration->getIndexQueueTypeOrFallbackToConfigurationName($configurationName); } return $indexingTableMap; diff --git a/Classes/Domain/Index/Queue/QueueInitializationService.php b/Classes/Domain/Index/Queue/QueueInitializationService.php index 4d236833f6..459c381276 100644 --- a/Classes/Domain/Index/Queue/QueueInitializationService.php +++ b/Classes/Domain/Index/Queue/QueueInitializationService.php @@ -142,18 +142,18 @@ protected function applyInitialization(Site $site, string $indexingConfiguration $this->queue->deleteItemsBySite($site, $indexingConfigurationName); $solrConfiguration = $site->getSolrConfiguration(); - $tableToIndex = $solrConfiguration->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName); + $type = $solrConfiguration->getIndexQueueTypeOrFallbackToConfigurationName($indexingConfigurationName); $initializerClass = $solrConfiguration->getIndexQueueInitializerClassByConfigurationName($indexingConfigurationName); $indexConfiguration = $solrConfiguration->getIndexQueueConfigurationByName($indexingConfigurationName); - return $this->executeInitializer($site, $indexingConfigurationName, $initializerClass, $tableToIndex, $indexConfiguration); + return $this->executeInitializer($site, $indexingConfigurationName, $initializerClass, $type, $indexConfiguration); } /** * @param Site $site * @param string $indexingConfigurationName * @param string $initializerClass - * @param string $tableToIndex + * @param string $type * @param array $indexConfiguration * @return bool */ @@ -161,13 +161,13 @@ protected function executeInitializer( Site $site, string $indexingConfigurationName, string $initializerClass, - string $tableToIndex, + string $type, array $indexConfiguration ): bool { $initializer = GeneralUtility::makeInstance($initializerClass); /* @var AbstractInitializer $initializer */ $initializer->setSite($site); - $initializer->setType($tableToIndex); + $initializer->setType($type); $initializer->setIndexingConfigurationName($indexingConfigurationName); $initializer->setIndexingConfiguration($indexConfiguration); diff --git a/Classes/Domain/Index/Queue/RecordMonitor/Helper/ConfigurationAwareRecordService.php b/Classes/Domain/Index/Queue/RecordMonitor/Helper/ConfigurationAwareRecordService.php index 395b36667a..c78b05cd05 100644 --- a/Classes/Domain/Index/Queue/RecordMonitor/Helper/ConfigurationAwareRecordService.php +++ b/Classes/Domain/Index/Queue/RecordMonitor/Helper/ConfigurationAwareRecordService.php @@ -163,7 +163,7 @@ protected function isValidTableForIndexConfigurationName( string $indexingConfigurationName, TypoScriptConfiguration $solrConfiguration ): bool { - $tableToIndex = $solrConfiguration->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName); + $tableToIndex = $solrConfiguration->getIndexQueueTypeOrFallbackToConfigurationName($indexingConfigurationName); $isMatchingTable = ($tableToIndex === $recordTable); diff --git a/Classes/System/Configuration/TypoScriptConfiguration.php b/Classes/System/Configuration/TypoScriptConfiguration.php index 719c47ca8b..80300eded5 100644 --- a/Classes/System/Configuration/TypoScriptConfiguration.php +++ b/Classes/System/Configuration/TypoScriptConfiguration.php @@ -388,11 +388,49 @@ public function getIndexQueuePagesExcludeContentByClassArray(array $defaultIfEmp * * @param string $configurationName * @return string + * @deprecated queue.[indexConfig].table is deprecated and will be removed in v13. Use plugin.tx_solr.index.queue.[indexConfig].type instead */ public function getIndexQueueTableNameOrFallbackToConfigurationName(string $configurationName = ''): string { + trigger_error( + 'queue.[indexConfig].table is deprecated and will be removed in v13. Use plugin.tx_solr.index.queue.[indexConfig].type instead.', + E_USER_DEPRECATED + ); + + return $this->getIndexQueueTypeOrFallbackToConfigurationName($configurationName); + } + + /** + * Returns the configured type for an indexing queue configuration (usally a db table) or + * the configurationName itself that is used by convention as type when no + * other type is present. + * + * plugin.tx_solr.index.queue..type or configurationName + * + * @param string $configurationName + * @return string + */ + public function getIndexQueueTypeOrFallbackToConfigurationName(string $configurationName = ''): string + { + $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.type'; + $type = $this->getValueByPath($path); + if (!is_null($type)) { + return (string)$type; + } + + // TODO: Remove fallback to "table" in v13 $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.table'; - return (string)$this->getValueByPathOrDefaultValue($path, $configurationName); + $type = $this->getValueByPath($path); + if (!is_null($type)) { + trigger_error( + 'queue.[indexConfig].table is deprecated and will be removed in v13. Use plugin.tx_solr.index.queue.[indexConfig].type instead.', + E_USER_DEPRECATED + ); + + return (string)$type; + } + + return $configurationName; } /** @@ -422,7 +460,7 @@ public function getIndexQueueMonitoredTables(): array $indexingConfigurations = $this->getEnabledIndexQueueConfigurationNames(); foreach ($indexingConfigurations as $indexingConfigurationName) { - $monitoredTable = $this->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName); + $monitoredTable = $this->getIndexQueueTypeOrFallbackToConfigurationName($indexingConfigurationName); $monitoredTables[] = $monitoredTable; } @@ -612,11 +650,8 @@ public function getIndexQueueConfigurationNamesByTableName(string $tableName, ar continue; } - // when the configuration name equals the tableName we have a fallback - $hasTableNameAsConfigurationName = $configurationName == $tableName; - $hasTableAssignedInQueueConfiguration = isset($configuration[$configurationName . '.']['table']) && - $configuration[$configurationName . '.']['table'] == $tableName; - if ($hasTableNameAsConfigurationName || $hasTableAssignedInQueueConfiguration) { + $configuredType = $this->getIndexQueueTypeOrFallbackToConfigurationName($configurationName); + if ($configuredType === $tableName) { $possibleConfigurations[] = $configurationName; } } diff --git a/Classes/Task/ReIndexTask.php b/Classes/Task/ReIndexTask.php index 822dc9cc37..51c739edd4 100644 --- a/Classes/Task/ReIndexTask.php +++ b/Classes/Task/ReIndexTask.php @@ -82,7 +82,7 @@ protected function cleanUpIndex(): bool $enableCommitsSetting = $solrConfiguration->getEnableCommits(); foreach ($this->indexingConfigurationsToReIndex as $indexingConfigurationName) { - $type = $solrConfiguration->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName); + $type = $solrConfiguration->getIndexQueueTypeOrFallbackToConfigurationName($indexingConfigurationName); $typesToCleanUp[] = $type; } diff --git a/Configuration/TypoScript/Examples/IndexQueueNews/setup.typoscript b/Configuration/TypoScript/Examples/IndexQueueNews/setup.typoscript index db2b31c9f2..8f5fb0e6f7 100644 --- a/Configuration/TypoScript/Examples/IndexQueueNews/setup.typoscript +++ b/Configuration/TypoScript/Examples/IndexQueueNews/setup.typoscript @@ -3,7 +3,7 @@ plugin.tx_solr.index.queue { news = 1 news { - table = tx_news_domain_model_news + type = tx_news_domain_model_news fields { abstract = teaser @@ -18,7 +18,7 @@ plugin.tx_solr.index.queue { field = datetime date = d.m.Y H:i } - + datetime_dateS = TEXT datetime_dateS { field = datetime diff --git a/Documentation/Configuration/Reference/TxSolrIndex.rst b/Documentation/Configuration/Reference/TxSolrIndex.rst index 4d74e8034d..e6abc49289 100644 --- a/Documentation/Configuration/Reference/TxSolrIndex.rst +++ b/Documentation/Configuration/Reference/TxSolrIndex.rst @@ -188,13 +188,23 @@ queue.[indexConfig].table :Type: String :TS Path: plugin.tx_solr.index.queue.[indexConfig].table :Since: 2.0 +:Deprecated: 11.5.1 -Sometimes you may want to index records from a table with different configurations, f.e., to generate different single view URLs for tt_news records depending on their category or storage page ID. In these cases you can use a distinct name for the configuration and define the table explicitly. +Defines the type to index, which is usally the database table. Setting the record type via 'table' is deprecated and will be removed in v13, use 'type' instead. + +queue.[indexConfig].type +------------------------- + +:Type: String +:TS Path: plugin.tx_solr.index.queue.[indexConfig].type +:Since: 11.5.1 + +Defines the type to index, which is usally the database table. Sometimes you may want to index records from a table with different configurations, f.e., to generate different single view URLs for tt_news records depending on their category or storage page ID. In these cases you can use a distinct name for the configuration and define the table explicitly. .. code-block:: typoscript plugin.tx_solr.index.queue.generalNews { - table = tt_news + type = tt_news fields.url = URL for the general news // more field configurations here ... } @@ -208,7 +218,7 @@ Sometimes you may want to index records from a table with different configuratio // completely different configuration plugin.tx_solr.index.queue.productNews { - table = tt_news + type = tt_news fields.url = URL for the product news } diff --git a/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php b/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php index 2076377e6b..2fed50e2cf 100644 --- a/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php +++ b/Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php @@ -44,7 +44,7 @@ public function allIndexConfigurationsAreUsedWhenWildcardIsPassed() 'my_pages' => 1, 'my_pages.' => [ 'initialization' => 'MyPagesInitializer', - 'table' => 'pages', + 'type' => 'pages', 'fields.' => [ 'title' => 'title', ], @@ -52,7 +52,7 @@ public function allIndexConfigurationsAreUsedWhenWildcardIsPassed() 'my_news' => 1, 'my_news.' => [ 'initialization' => 'MyNewsInitializer', - 'table' => 'tx_news_domain_model_news', + 'type' => 'tx_news_domain_model_news', 'fields.' => [ 'title' => 'title', ], diff --git a/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php b/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php index a92b78d377..6b083891b9 100644 --- a/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php +++ b/Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php @@ -112,6 +112,8 @@ public function canShowEvenIfEmptyFallBackToGlobalSetting() /** * @test + * @deprecated queue.[indexConfig].table is deprecated and will be removed in v13. As soon as setting is removed this + * test must be removed too. For now this test ensures that 'table' and 'type' are supported. */ public function canGetIndexQueueTableOrFallbackToConfigurationName() { @@ -129,10 +131,40 @@ public function canGetIndexQueueTableOrFallbackToConfigurationName() $configuration = new TypoScriptConfiguration($fakeConfigurationArray); - $customTableExpected = $configuration->getIndexQueueTableNameOrFallbackToConfigurationName('pages'); + $customTableExpected = @$configuration->getIndexQueueTableNameOrFallbackToConfigurationName('pages'); + self::assertSame($customTableExpected, 'pages', 'Can not fallback to configurationName'); + $customTableExpected = $configuration->getIndexQueueTypeOrFallbackToConfigurationName('pages'); self::assertSame($customTableExpected, 'pages', 'Can not fallback to configurationName'); - $customTableExpected = $configuration->getIndexQueueTableNameOrFallbackToConfigurationName('custom'); + $customTableExpected = @$configuration->getIndexQueueTableNameOrFallbackToConfigurationName('custom'); + self::assertSame($customTableExpected, 'tx_model_custom', 'Usage of custom table tx_model_custom was expected'); + $customTableExpected = @$configuration->getIndexQueueTypeOrFallbackToConfigurationName('custom'); + self::assertSame($customTableExpected, 'tx_model_custom', 'Usage of custom table tx_model_custom was expected'); + } + + /** + * @test + */ + public function canGetIndexQueueTypeOrFallbackToConfigurationName() + { + $fakeConfigurationArray['plugin.']['tx_solr.'] = [ + 'index.' => [ + 'queue.' => [ + 'pages.' => [ + ], + 'custom.' => [ + 'type' => 'tx_model_custom', + ], + ], + ], + ]; + + $configuration = new TypoScriptConfiguration($fakeConfigurationArray); + + $customTableExpected = $configuration->getIndexQueueTypeOrFallbackToConfigurationName('pages'); + self::assertSame($customTableExpected, 'pages', 'Can not fallback to configurationName'); + + $customTableExpected = $configuration->getIndexQueueTypeOrFallbackToConfigurationName('custom'); self::assertSame($customTableExpected, 'tx_model_custom', 'Usage of custom table tx_model_custom was expected'); } @@ -148,7 +180,7 @@ public function canGetIndexQueueConfigurationNames() 'pages.' => [ ], 'custom.' => [ - 'table' => 'tx_model_custom', + 'type' => 'tx_model_custom', ], ], ], @@ -286,12 +318,12 @@ public function canGetIndexQueueConfigurationNamesByTableName() ], 'custom_one' => 1, 'custom_one.' => [ - 'table' => 'tx_model_bar', + 'type' => 'tx_model_bar', ], 'custom_two' => 1, 'custom_two.' => [ - 'table' => 'tx_model_news', + 'type' => 'tx_model_news', ], ], ], @@ -314,12 +346,12 @@ public function canGetIndexQueueMonitoredTables() ], 'custom_one' => 1, 'custom_one.' => [ - 'table' => 'tx_model_bar', + 'type' => 'tx_model_bar', ], 'custom_two' => 1, 'custom_two.' => [ - 'table' => 'tx_model_news', + 'type' => 'tx_model_news', ], 'pages' => 1, 'pages.' => [], @@ -345,12 +377,12 @@ public function canGetIndexQueueIsMonitoredTable() ], 'custom_one' => 1, 'custom_one.' => [ - 'table' => 'tx_model_bar', + 'type' => 'tx_model_bar', ], 'custom_two' => 1, 'custom_two.' => [ - 'table' => 'tx_model_news', + 'type' => 'tx_model_news', ], 'pages' => 1, 'pages.' => [],