Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
papcio122 committed Sep 19, 2023
2 parents 90c5d66 + 6c05d9f commit fe38408
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use const DIRECTORY_SEPARATOR;
use Generator;
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler;
use Ibexa\Contracts\Core\Repository\ContentService as APIContentService;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
use Ibexa\Contracts\Core\Search\Content\IndexerGateway;
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
use Ibexa\Core\Search\Common\IncrementalIndexer;
Expand Down Expand Up @@ -55,6 +59,8 @@ class ReindexCommand extends Command implements BackwardCompatibleCommand
/** @var \Ibexa\Contracts\Core\Persistence\Content\Location\Handler */
private $locationHandler;

private APIContentService $contentService;

public function __construct(
$searchIndexer,
Handler $locationHandler,
Expand All @@ -64,6 +70,7 @@ public function __construct(
string $env,
bool $isDebug,
string $projectDir,
APIContentService $contentService,
string $phpPath = null
) {
$this->gateway = $gateway;
Expand All @@ -75,6 +82,7 @@ public function __construct(
$this->env = $env;
$this->isDebug = $isDebug;
$this->projectDir = $projectDir;
$this->contentService = $contentService;
$this->phpPath = $phpPath;

parent::__construct();
Expand Down Expand Up @@ -128,23 +136,28 @@ protected function configure()
'since',
null,
InputOption::VALUE_OPTIONAL,
'Refresh changes since a time provided in any format understood by DateTime. Implies "no-purge", cannot be combined with "content-ids" or "subtree"'
'Refresh changes since a time provided in any format understood by DateTime. Implies "no-purge", cannot be combined with "content-ids", "subtree", or "content-type"'
)->addOption(
'content-ids',
null,
InputOption::VALUE_OPTIONAL,
'Comma-separated list of content ID\'s to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since" or "subtree"'
'Comma-separated list of content ID\'s to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since", "subtree", or "content-type"'
)->addOption(
'subtree',
null,
InputOption::VALUE_OPTIONAL,
'Location ID whose subtree will be indexed (including the Location itself). Implies "no-purge", cannot be combined with "since" or "content-ids"'
'Location ID whose subtree will be indexed (including the Location itself). Implies "no-purge", cannot be combined with "since", "content-ids", or "content-type"'
)->addOption(
'processes',
null,
InputOption::VALUE_OPTIONAL,
'Number of child processes to run in parallel for iterations, if set to "auto" it will set to number of CPU cores -1, set to "1" or "0" to disable',
'auto'
)->addOption(
'content-type',
null,
InputOption::VALUE_REQUIRED,
'Content type identifier to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since", "subtree", or "content-ids"'
)->setHelp(
<<<EOT
The command <info>%command.name%</info> indexes the current configured database in the configured search engine index.
Expand Down Expand Up @@ -256,6 +269,17 @@ protected function indexIncrementally(
$count = $this->gateway->countContentInSubtree($location->pathString);
$generator = $this->gateway->getContentInSubtree($location->pathString, $iterationCount);
$purge = false;
} elseif ($contentType = $input->getOption('content-type')) {
$filter = new Filter();
$filter
->withCriterion(
new Query\Criterion\ContentTypeIdentifier($contentType)
);

$contentList = $this->contentService->find($filter);
$count = $contentList->getTotalCount();
$generator = $this->fetchIterationFromContentList($contentList, $iterationCount);
$purge = false;
} else {
$count = $this->gateway->countAllContent();
$generator = $this->gateway->getAllContent($iterationCount);
Expand Down Expand Up @@ -454,6 +478,20 @@ public function getDeprecatedAliases(): array
{
return ['ezplatform:reindex'];
}

private function fetchIterationFromContentList(ContentList $contentList, int $iterationCount): Generator
{
$i = 1;
$contentIds = [];
foreach ($contentList as $content) {
$contentIds[] = $content->id;
if ($iterationCount <= $i) {
break;
}
++$i;
}
yield $contentIds;
}
}

class_alias(ReindexCommand::class, 'eZ\Bundle\EzPublishCoreBundle\Command\ReindexCommand');
1 change: 1 addition & 0 deletions src/bundle/Core/Resources/config/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ services:
$env: '%kernel.environment%'
$projectDir: '%kernel.project_dir%'
$isDebug: '%kernel.debug%'
$contentService: '@Ibexa\Contracts\Core\Repository\ContentService'
tags:
- { name: console.command }

Expand Down

0 comments on commit fe38408

Please sign in to comment.