diff --git a/src/bundle/Core/Command/ReindexCommand.php b/src/bundle/Core/Command/ReindexCommand.php index c5f5b217b9..8b0cb1933a 100644 --- a/src/bundle/Core/Command/ReindexCommand.php +++ b/src/bundle/Core/Command/ReindexCommand.php @@ -11,9 +11,11 @@ use DateTime; use const DIRECTORY_SEPARATOR; use Ibexa\Bundle\Core\Command\Indexer\ContentIdListGeneratorStrategyInterface; +use Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface; use Ibexa\Contracts\Core\Persistence\Content\Location\Handler; use Ibexa\Contracts\Core\Search\Content\IndexerGateway; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; +use Ibexa\Core\Search\Common\IncrementalIndexer; use Ibexa\Core\Search\Common\Indexer; use Psr\Log\LoggerInterface; use RuntimeException; @@ -75,6 +77,7 @@ public function __construct( bool $isDebug, string $projectDir, ContentIdListGeneratorStrategyInterface $contentIdListGeneratorStrategy, + private readonly RepositoryConfigurationProviderInterface $repositoryConfigurationProvider, string $phpPath = null ) { $this->gateway = $gateway; @@ -210,12 +213,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int - number of processes for parallel batch operations is high enough (default: 'auto' is a good choice). EOT); - if (!$io->confirm('Continue?', true)) { + if (!$io->confirm('Continue?')) { return self::SUCCESS; } } - $output->writeln('Re-indexing started for search engine: ' . get_class($this->searchIndexer)); + $output->writeln( + sprintf( + 'Re-indexing started for search engine: %s', + $this->getSearchEngineAlias() + ) + ); $output->writeln(''); return $this->indexIncrementally($input, $output, $iterationCount, $commit); @@ -469,4 +477,28 @@ private function getNumberOfCPUCores(): int return $cores; } + + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + private function getSearchEngineAlias(): string + { + if ($this->searchIndexer instanceof IncrementalIndexer) { + return $this->searchIndexer->getName(); + } + + $repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig(); + $searchEngineAlias = $repositoryConfig['search']['engine'] ?? null; + + if (null === $searchEngineAlias) { + throw new RuntimeException( + sprintf( + '"%s" repository has no search engine configured', + $this->repositoryConfigurationProvider->getCurrentRepositoryAlias() + ) + ); + } + + return $searchEngineAlias; + } } diff --git a/src/bundle/Core/Resources/config/commands.yml b/src/bundle/Core/Resources/config/commands.yml index e8b077d0cf..f8d089acc5 100644 --- a/src/bundle/Core/Resources/config/commands.yml +++ b/src/bundle/Core/Resources/config/commands.yml @@ -43,6 +43,7 @@ services: $projectDir: '%kernel.project_dir%' $isDebug: '%kernel.debug%' $contentIdListGeneratorStrategy: '@Ibexa\Bundle\Core\Command\Indexer\ContentIdList\ContentTypeInputGeneratorStrategy' + $repositoryConfigurationProvider: '@Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface' tags: - { name: console.command }