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:BP:11.6] Relax dependencies to local tables #3765

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
4 changes: 3 additions & 1 deletion Classes/Access/RootlineElementFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

namespace ApacheSolrForTypo3\Solr\Access;

use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException;

/**
* Signals a wrong format for the access definition of a page or the content.
*
* @author Ingo Renner <ingo@typo3.org>
*/
class RootlineElementFormatException extends \InvalidArgumentException
class RootlineElementFormatException extends InvalidArgumentException
{
}
2 changes: 1 addition & 1 deletion Classes/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

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\Records\SystemLanguage\SystemLanguageRepository;
use ApacheSolrForTypo3\Solr\System\Solr\Node;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use ApacheSolrForTypo3\Solr\System\Util\SiteUtility;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use InvalidArgumentException;
use function json_encode;
use Throwable;
use TYPO3\CMS\Core\SingletonInterface;
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 @@ -18,11 +18,12 @@
use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\Domain\Site\Site;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException;
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;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Throwable;
use TYPO3\CMS\Backend\Template\Components\Menu\Menu;
Expand Down Expand Up @@ -61,7 +62,7 @@ abstract class AbstractModuleController extends ActionController
protected int $requestedPageUID;

/**
* @var ?Site
* @var Site|null
*/
protected ?Site $selectedSite = null;

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
144 changes: 111 additions & 33 deletions Classes/Controller/Backend/Search/IndexQueueModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

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 Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Form\Exception as BackendFormException;
use TYPO3\CMS\Core\Http\RedirectResponse;
Expand All @@ -29,28 +31,46 @@
/**
* Index Queue Module
*
* @todo: Support all index queues in actions beside "initializeIndexQueueAction" and
* "resetLogErrorsAction"
*
* @author Ingo Renner <ingo@typo3.org>
*/
class IndexQueueModuleController extends AbstractModuleController
{
/**
* @var Queue
* The default Solr Queue

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

/**
* Enabled Solr index queues
*
* @var QueueInterface[]
*/
protected array $enabledIndexQueues;

/**
* Initializes the controller before invoking an action method.
*/
protected function initializeAction()
{
parent::initializeAction();
$this->indexQueue = GeneralUtility::makeInstance(Queue::class);

$this->enabledIndexQueues = $this->getIndexQueues();
if (!empty($this->enabledIndexQueues)) {
$this->indexQueue = $this->enabledIndexQueues[Queue::class] ?? reset($this->enabledIndexQueues);
}
}

/**
* @param Queue $indexQueue
* Sets the default queue to use
*
* @param QueueInterface $indexQueue
*/
public function setIndexQueue(Queue $indexQueue)
public function setIndexQueue(QueueInterface $indexQueue)
{
$this->indexQueue = $indexQueue;
}
Expand Down Expand Up @@ -85,6 +105,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 @@ -119,25 +144,39 @@ public function initializeIndexQueueAction(): ResponseInterface

$indexingConfigurationsToInitialize = GeneralUtility::_POST('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(
/** @var QueueInitializationService $initializationService */
$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'
),
FlashMessage::ERROR
);
FlashMessage::ERROR
);
}
}
} else {
$messageLabel = 'solr.backend.index_queue_module.flashmessage.initialize.no_selection';
Expand All @@ -148,13 +187,31 @@ public function initializeIndexQueueAction(): ResponseInterface
FlashMessage::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'
),
FlashMessage::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(
Expand All @@ -174,16 +231,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 = FlashMessage::OK;
if (!$resetResult) {
$label = 'solr.backend.index_queue_module.flashmessage.error.reset_errors';
$severity = FlashMessage::ERROR;
}
$label = 'solr.backend.index_queue_module.flashmessage.success.reset_errors';
$severity = FlashMessage::OK;
if (!$resetResult) {
$label = 'solr.backend.index_queue_module.flashmessage.error.reset_errors';
$severity = FlashMessage::ERROR;
}

$this->addIndexQueueFlashMessage($label, $severity);
$this->addIndexQueueFlashMessage($label, $severity);
}

return new RedirectResponse($this->uriBuilder->uriFor('index'), 303);
}
Expand Down Expand Up @@ -269,4 +328,23 @@ protected function addIndexQueueFlashMessage(string $label, int $severity)
{
$this->addFlashMessage(LocalizationUtility::translate($label, 'Solr'), LocalizationUtility::translate('solr.backend.index_queue_module.flashmessage.title', 'Solr'), $severity);
}

/**
* Get index queues
*
* @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;
}
}
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
11 changes: 6 additions & 5 deletions Classes/Domain/Index/Queue/GarbageRemover/AbstractStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue\GarbageRemover;

use ApacheSolrForTypo3\Solr\ConnectionManager;
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 ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use InvalidArgumentException;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
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
Loading