Skip to content

Commit

Permalink
!!![TASK:BP:11.6] Introduce queue and queue item interfaces
Browse files Browse the repository at this point in the history
As an initial steps to allow custom index queue types interfaces
for queue and queue items are introduced. Additionally custom
queue classes can be configured via:
plugin.tx_solr.index.queue.<configurationName>.indexQueue

This is a breaking change for all instances that implement own
queues and queue items!

Ports: TYPO3-Solr#3764
Resolves: TYPO3-Solr#3763
  • Loading branch information
dkd-friedrich committed Mar 12, 2024
1 parent 9d09ea1 commit 65e1ef2
Show file tree
Hide file tree
Showing 18 changed files with 751 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use ApacheSolrForTypo3\Solr\Domain\Site\Site;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface;
use ApacheSolrForTypo3\Solr\System\Mvc\Backend\Service\ModuleDataStorageService;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection as SolrCoreConnection;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
Expand Down Expand Up @@ -91,9 +92,9 @@ abstract class AbstractModuleController extends ActionController
protected ModuleDataStorageService $moduleDataStorageService;

/**
* @var Queue
* @var QueueInterface
*/
protected Queue $indexQueue;
protected QueueInterface $indexQueue;

/**
* @var SiteFinder
Expand Down
19 changes: 14 additions & 5 deletions Classes/Controller/Backend/Search/IndexQueueModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

use ApacheSolrForTypo3\Solr\Backend\IndexingConfigurationSelectorField;
use ApacheSolrForTypo3\Solr\Domain\Index\IndexService;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueInitializationService;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface;
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInitializationServiceAwareInterface;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Form\Exception as BackendFormException;
use TYPO3\CMS\Core\Http\RedirectResponse;
Expand All @@ -34,9 +37,9 @@
class IndexQueueModuleController extends AbstractModuleController
{
/**
* @var Queue
* @var QueueInterface
*/
protected Queue $indexQueue;
protected QueueInterface $indexQueue;

/**
* Initializes the controller before invoking an action method.
Expand All @@ -48,9 +51,9 @@ protected function initializeAction()
}

/**
* @param Queue $indexQueue
* @param QueueInterface $indexQueue
*/
public function setIndexQueue(Queue $indexQueue)
public function setIndexQueue(QueueInterface $indexQueue)
{
$this->indexQueue = $indexQueue;
}
Expand Down Expand Up @@ -121,7 +124,13 @@ public function initializeIndexQueueAction(): ResponseInterface
if ((!empty($indexingConfigurationsToInitialize)) && (is_array($indexingConfigurationsToInitialize))) {
// initialize selected indexing configuration
try {
$initializedIndexingConfigurations = $this->indexQueue->getInitializationService()->initializeBySiteAndIndexConfigurations($this->selectedSite, $indexingConfigurationsToInitialize);
if ($this->indexQueue instanceof QueueInitializationServiceAwareInterface) {
$initializationService = $this->indexQueue->getQueueInitializationService();
} else {
$initializationService = GeneralUtility::makeInstance(QueueInitializationService::class);
}

$initializedIndexingConfigurations = $initializationService->initializeBySiteAndIndexConfigurations($this->selectedSite, $indexingConfigurationsToInitialize);
} catch (\Throwable $e) {
$this->addFlashMessage(
sprintf(
Expand Down
7 changes: 4 additions & 3 deletions Classes/Domain/Index/IndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 Down Expand Up @@ -48,9 +49,9 @@ class IndexService
protected ?IndexQueueWorkerTask $contextTask = null;

/**
* @var Queue
* @var QueueInterface
*/
protected Queue $indexQueue;
protected QueueInterface $indexQueue;

/**
* @var Dispatcher
Expand All @@ -71,7 +72,7 @@ class IndexService
*/
public function __construct(
Site $site,
Queue $queue = null,
QueueInterface $queue = null,
Dispatcher $dispatcher = null,
SolrLogManager $solrLogManager = null
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use InvalidArgumentException;
Expand All @@ -30,9 +31,9 @@
abstract class AbstractStrategy
{
/**
* @var Queue
* @var QueueInterface
*/
protected Queue $queue;
protected QueueInterface $queue;

/**
* @var ConnectionManager
Expand All @@ -41,11 +42,11 @@ abstract class AbstractStrategy

/**
* AbstractStrategy constructor.
* @param Queue|null $queue
* @param QueueInterface|null $queue
* @param ConnectionManager|null $connectionManager
*/
public function __construct(
Queue $queue = null,
QueueInterface $queue = null,
ConnectionManager $connectionManager = null
) {
$this->queue = $queue ?? GeneralUtility::makeInstance(Queue::class);
Expand Down
29 changes: 19 additions & 10 deletions Classes/Domain/Index/Queue/QueueInitializationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
use ApacheSolrForTypo3\Solr\Domain\Site\Site;
use ApacheSolrForTypo3\Solr\IndexQueue\InitializationPostProcessor;
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\AbstractInitializer;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInterface;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Exception as DBALException;
use Throwable;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use UnexpectedValueException;
use ApacheSolrForTypo3\Solr\IndexQueue\QueueInitializationServiceAwareInterface;

/**
* The queue initialization service is responsible to run the initialization of the index queue for a combination of sites
Expand All @@ -36,17 +37,14 @@
*/
class QueueInitializationService
{
/**
* @var Queue
*/
protected Queue $queue;
protected bool $clearQueueOnInitialization = true;

/**
* QueueInitializationService constructor.
* @param bool $clearQueueOnInitialization
*/
public function __construct(Queue $queue)
public function setClearQueueOnInitialization(bool $clearQueueOnInitialization): void
{
$this->queue = $queue;
$this->clearQueueOnInitialization = $clearQueueOnInitialization;
}

/**
Expand Down Expand Up @@ -138,10 +136,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
13 changes: 7 additions & 6 deletions Classes/Domain/Index/Queue/QueueItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use ApacheSolrForTypo3\Solr\Domain\Site\Site;
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\IndexQueue\ItemInterface;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use ApacheSolrForTypo3\Solr\System\Records\AbstractRepository;
use Doctrine\DBAL\ConnectionException;
Expand Down Expand Up @@ -145,12 +146,12 @@ public function flushErrorsBySite(Site $site): int
/**
* Flushes the error for a single item.
*
* @param Item $item
* @param ItemInterface $item
* @return int affected rows
*
* @throws DBALException|\Doctrine\DBAL\DBALException
*/
public function flushErrorByItem(Item $item): int
public function flushErrorByItem(ItemInterface $item): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$this->getPreparedFlushErrorQuery($queryBuilder)
Expand Down Expand Up @@ -974,12 +975,12 @@ public function markItemAsFailed($item, string $errorMessage = ''): int
/**
* Sets the timestamp of when an item last has been indexed.
*
* @param Item $item
* @param ItemInterface $item
* @return int affected rows
*
* @throws DBALException|\Doctrine\DBAL\DBALException
*/
public function updateIndexTimeByItem(Item $item): int
public function updateIndexTimeByItem(ItemInterface $item): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$queryBuilder
Expand All @@ -992,13 +993,13 @@ public function updateIndexTimeByItem(Item $item): int
/**
* Sets the change timestamp of an item.
*
* @param Item $item
* @param ItemInterface $item
* @param int $changedTime
* @return int affected rows
*
* @throws DBALException|\Doctrine\DBAL\DBALException
*/
public function updateChangedTimeByItem(Item $item, int $changedTime = 0): int
public function updateChangedTimeByItem(ItemInterface $item, int $changedTime = 0): int
{
$queryBuilder = $this->getQueryBuilder();
return (int)$queryBuilder
Expand Down
Loading

0 comments on commit 65e1ef2

Please sign in to comment.