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] Relax dependencies to local tables #3764

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/Access/RootlineElementFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Classes/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Classes/ContentObject/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
133 changes: 103 additions & 30 deletions Classes/Controller/Backend/Search/IndexQueueModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,11 +34,26 @@
/**
* Index Queue Module
*
* @todo: Support all index queues in actions beside "initializeIndexQueueAction" and
* "resetLogErrorsAction"
*
* @author Ingo Renner <ingo@typo3.org>
*/
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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand All @@ -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
);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
5 changes: 3 additions & 2 deletions Classes/Domain/Index/IndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,15 +46,15 @@ class IndexService

protected ?IndexQueueWorkerTask $contextTask = null;

protected Queue $indexQueue;
protected QueueInterface $indexQueue;

protected EventDispatcherInterface $eventDispatcher;

protected SolrLogManager $logger;

public function __construct(
Site $site,
Queue $queue = null,
QueueInterface $queue = null,
EventDispatcherInterface $eventDispatcher = null,
SolrLogManager $solrLogManager = null,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
28 changes: 22 additions & 6 deletions Classes/Domain/Index/Queue/QueueInitializationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading