Skip to content

Commit

Permalink
IBX-5385 use contentService to get content list for reindex
Browse files Browse the repository at this point in the history
  • Loading branch information
papcio122 committed Sep 11, 2023
1 parent 77d5436 commit 76557f4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 43 deletions.
41 changes: 38 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;
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,9 @@ class ReindexCommand extends Command implements BackwardCompatibleCommand
/** @var \Ibexa\Contracts\Core\Persistence\Content\Location\Handler */
private $locationHandler;

/** @var \Ibexa\Contracts\Core\Repository\ContentService */
private $contentService;

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

parent::__construct();
}
Expand Down Expand Up @@ -262,8 +270,14 @@ protected function indexIncrementally(
$generator = $this->gateway->getContentInSubtree($location->pathString, $iterationCount);
$purge = false;
} elseif ($contentType = $input->getOption('content-type')) {
$count = $this->gateway->countContentWithContentTypeIdentifier($contentType);
$generator = $this->gateway->getContentWithContentTypeIdentifier($contentType, $iterationCount);
$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();
Expand Down Expand Up @@ -463,6 +477,27 @@ public function getDeprecatedAliases(): array
{
return ['ezplatform:reindex'];
}

private function fetchIterationFromContentList(ContentList $contentList, int $iterationCount): Generator
{
$iterator = $contentList->getIterator();
do {
$contentIds = [];
for ($i = 0; $i < $iterationCount; ++$i) {
$content = $iterator->current();

Check failure on line 487 in src/bundle/Core/Command/ReindexCommand.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Call to an undefined method iterable<Ibexa\Contracts\Core\Repository\Values\Content\Content>&Traversable::current().

Check failure on line 487 in src/bundle/Core/Command/ReindexCommand.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Call to an undefined method iterable<Ibexa\Contracts\Core\Repository\Values\Content\Content>&Traversable::current().

Check failure on line 487 in src/bundle/Core/Command/ReindexCommand.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Call to an undefined method iterable<Ibexa\Contracts\Core\Repository\Values\Content\Content>&Traversable::current().
if ($content) {
$contentIds[] = $content->id;
} elseif (empty($contentIds)) {
return;
} else {
break;
}
$iterator->next();

Check failure on line 495 in src/bundle/Core/Command/ReindexCommand.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Call to an undefined method iterable<Ibexa\Contracts\Core\Repository\Values\Content\Content>&Traversable::next().

Check failure on line 495 in src/bundle/Core/Command/ReindexCommand.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Call to an undefined method iterable<Ibexa\Contracts\Core\Repository\Values\Content\Content>&Traversable::next().

Check failure on line 495 in src/bundle/Core/Command/ReindexCommand.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Call to an undefined method iterable<Ibexa\Contracts\Core\Repository\Values\Content\Content>&Traversable::next().
}

yield $contentIds;
} while (!empty($content));
}
}

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
12 changes: 0 additions & 12 deletions src/contracts/Search/Content/IndexerGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ public function getAllContent(int $iterationCount): Generator;
* @throws \Doctrine\DBAL\Exception
*/
public function countAllContent(): int;

/**
* @throws \Doctrine\DBAL\Exception
*
* @return iterable<int> list of Content IDs for each iteration
*/
public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): iterable;

/**
* @throws \Doctrine\DBAL\Exception
*/
public function countContentWithContentTypeIdentifier(string $contentTypeIdentifier): int;
}

class_alias(IndexerGateway::class, 'eZ\Publish\SPI\Search\Content\IndexerGateway');
28 changes: 0 additions & 28 deletions src/lib/Search/Legacy/Content/IndexerGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,34 +144,6 @@ private function fetchIteration(ResultStatement $statement, int $iterationCount)
yield $contentIds;
} while (!empty($contentId));
}

public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): Generator
{
$query = $this->buildQueryForContentWithContentTypeIdentifier($contentTypeIdentifier);

yield from $this->fetchIteration($query->execute(), $iterationCount);
}

public function countContentWithContentTypeIdentifier(string $contentTypeIdentifier): int
{
$query = $this->buildCountingQuery(
$this->buildQueryForContentWithContentTypeIdentifier($contentTypeIdentifier)
);

return (int)$query->execute()->fetchOne();
}

private function buildQueryForContentWithContentTypeIdentifier(string $contentTypeIdentifier): QueryBuilder
{
return $this->connection->createQueryBuilder()
->select('DISTINCT c.id')
->from('ezcontentobject', 'c')
->innerJoin('c', 'ezcontentclass', 'cc', 'cc.id = c.contentclass_id')
->where('c.status = :status')
->andWhere('cc.identifier LIKE :identifier')
->setParameter('status', ContentInfo::STATUS_PUBLISHED, ParameterType::INTEGER)
->setParameter('identifier', $contentTypeIdentifier, ParameterType::STRING);
}
}

class_alias(IndexerGateway::class, 'eZ\Publish\Core\Search\Legacy\Content\IndexerGateway');

0 comments on commit 76557f4

Please sign in to comment.