Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Introduce index queue type setting #3365

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Backend/IndexingConfigurationSelectorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions Classes/Domain/Index/Queue/QueueInitializationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,32 @@ 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
*/
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected function isValidTableForIndexConfigurationName(
string $indexingConfigurationName,
TypoScriptConfiguration $solrConfiguration
): bool {
$tableToIndex = $solrConfiguration->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName);
$tableToIndex = $solrConfiguration->getIndexQueueTypeOrFallbackToConfigurationName($indexingConfigurationName);

$isMatchingTable = ($tableToIndex === $recordTable);

Expand Down
49 changes: 42 additions & 7 deletions Classes/System/Configuration/TypoScriptConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.<configurationName>.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;
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Task/ReIndexTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +18,7 @@ plugin.tx_solr.index.queue {
field = datetime
date = d.m.Y H:i
}

datetime_dateS = TEXT
datetime_dateS {
field = datetime
Expand Down
16 changes: 13 additions & 3 deletions Documentation/Configuration/Reference/TxSolrIndex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
}
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Domain/Index/Queue/QueueInitializerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public function allIndexConfigurationsAreUsedWhenWildcardIsPassed()
'my_pages' => 1,
'my_pages.' => [
'initialization' => 'MyPagesInitializer',
'table' => 'pages',
'type' => 'pages',
'fields.' => [
'title' => 'title',
],
],
'my_news' => 1,
'my_news.' => [
'initialization' => 'MyNewsInitializer',
'table' => 'tx_news_domain_model_news',
'type' => 'tx_news_domain_model_news',
'fields.' => [
'title' => 'title',
],
Expand Down
50 changes: 41 additions & 9 deletions Tests/Unit/System/Configuration/TypoScriptConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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');
}

Expand All @@ -148,7 +180,7 @@ public function canGetIndexQueueConfigurationNames()
'pages.' => [
],
'custom.' => [
'table' => 'tx_model_custom',
'type' => 'tx_model_custom',
],
],
],
Expand Down Expand Up @@ -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',
],
],
],
Expand All @@ -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.' => [],
Expand All @@ -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.' => [],
Expand Down