-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Consider queue initialization status
Queue initialization status returned by the QueueInitializationService isn't considered in the backend module and a success message is always shown. This commit adds a check for the returned status and displays an error message similiar to the message that is shown if an exceptions occured. Resolves: #3763
- Loading branch information
1 parent
e5c2623
commit 993f75a
Showing
3 changed files
with
113 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
use ApacheSolrForTypo3\Solr\Domain\Site\Exception\UnexpectedTYPO3SiteInitializationException; | ||
use ApacheSolrForTypo3\Solr\IndexQueue\Queue; | ||
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface; | ||
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInitializationServiceAwareInterface; | ||
use Doctrine\DBAL\ConnectionException; | ||
use Doctrine\DBAL\Exception as DBALException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
@@ -35,10 +34,26 @@ | |
/** | ||
* Index Queue Module | ||
* | ||
* @todo: Support all index queues in actions beside "initializeIndexQueueAction" and | ||
* "resetLogErrorsAction" | ||
* | ||
* @author Ingo Renner <[email protected]> | ||
*/ | ||
class IndexQueueModuleController extends AbstractModuleController | ||
{ | ||
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; | ||
|
@@ -74,6 +89,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; | ||
|
@@ -108,24 +128,62 @@ public function initializeIndexQueueAction(): ResponseInterface | |
|
||
$indexingConfigurationsToInitialize = $this->request->getArgument('tx_solr-index-queue-initialization'); | ||
if ((!empty($indexingConfigurationsToInitialize)) && (is_array($indexingConfigurationsToInitialize))) { | ||
// initialize selected indexing configuration | ||
try { | ||
if ($this->indexQueue instanceof QueueInitializationServiceAwareInterface) { | ||
$initializationService = $this->indexQueue->getQueueInitializationService(); | ||
} else { | ||
$initializationService = GeneralUtility::makeInstance(QueueInitializationService::class); | ||
$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.title', | ||
'Solr' | ||
), | ||
ContextualFeedbackSeverity::ERROR | ||
); | ||
} | ||
|
||
$initializedIndexingConfigurations = $initializationService->initializeBySiteAndIndexConfigurations($this->selectedSite, $indexingConfigurationsToInitialize); | ||
} catch (Throwable $e) { | ||
} | ||
} else { | ||
$messageLabel = 'solr.backend.index_queue_module.flashmessage.initialize.no_selection'; | ||
$titleLabel = 'solr.backend.index_queue_module.flashmessage.not_initialized.title'; | ||
$this->addFlashMessage( | ||
LocalizationUtility::translate($messageLabel, 'Solr'), | ||
LocalizationUtility::translate($titleLabel, 'Solr'), | ||
ContextualFeedbackSeverity::WARNING | ||
); | ||
} | ||
|
||
$messagesForConfigurations = []; | ||
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' | ||
), | ||
$e->getMessage(), | ||
$e->getCode() | ||
$indexingConfigurationName, | ||
1662117020 | ||
), | ||
LocalizationUtility::translate( | ||
'solr.backend.index_queue_module.flashmessage.initialize_failure.title', | ||
|
@@ -134,27 +192,15 @@ public function initializeIndexQueueAction(): ResponseInterface | |
ContextualFeedbackSeverity::ERROR | ||
); | ||
} | ||
} else { | ||
$messageLabel = 'solr.backend.index_queue_module.flashmessage.initialize.no_selection'; | ||
$titleLabel = 'solr.backend.index_queue_module.flashmessage.not_initialized.title'; | ||
$this->addFlashMessage( | ||
LocalizationUtility::translate($messageLabel, 'Solr'), | ||
LocalizationUtility::translate($titleLabel, 'Solr'), | ||
ContextualFeedbackSeverity::WARNING | ||
); | ||
} | ||
$messagesForConfigurations = []; | ||
foreach (array_keys($initializedIndexingConfigurations) as $indexingConfigurationName) { | ||
$itemCount = $this->indexQueue->getStatisticsBySite($this->selectedSite, $indexingConfigurationName)->getTotalCount(); | ||
$messagesForConfigurations[] = $indexingConfigurationName . ' (' . $itemCount . ' records)'; | ||
} | ||
|
||
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 | ||
); | ||
} | ||
|
||
|
@@ -168,16 +214,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); | ||
} | ||
|
@@ -264,4 +312,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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters