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

IBX-5385: Added option content-type to reindex command #259

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
IBX-5385 fix phpstan errors
  • Loading branch information
papcio122 committed Sep 12, 2023
commit 2354584c34e0f666210e1c91d20fafa57c328c82
22 changes: 16 additions & 6 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/
namespace Ibexa\Bundle\Core\Command;

use ArrayIterator;
use function count;
use DateTime;
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\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
use Ibexa\Contracts\Core\Search\Content\IndexerGateway;
Expand Down Expand Up @@ -84,6 +85,7 @@ public function __construct(
$this->isDebug = $isDebug;
$this->projectDir = $projectDir;
$this->contentService = $contentService;
$this->phpPath = $phpPath;

parent::__construct();
}
Expand Down Expand Up @@ -275,9 +277,12 @@ protected function indexIncrementally(
->withCriterion(
new Query\Criterion\ContentTypeIdentifier($contentType)
);
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentList $contentList */
$contentList = $this->contentService->find($filter);
$count = $contentList->getTotalCount();
$generator = $this->fetchIterationFromContentList($contentList, $iterationCount);
/** @var ArrayIterator<int, Content> $contentListIterator */
$contentListIterator = $contentList->getIterator();
papcio122 marked this conversation as resolved.
Show resolved Hide resolved
$generator = $this->fetchIterationFromContentListIterator($contentListIterator, $iterationCount);
$purge = false;
} else {
$count = $this->gateway->countAllContent();
Expand Down Expand Up @@ -478,21 +483,26 @@ public function getDeprecatedAliases(): array
return ['ezplatform:reindex'];
}

private function fetchIterationFromContentList(ContentList $contentList, int $iterationCount): Generator
/**
* @param ArrayIterator<int, Content> $contentListIterator
* @param int $iterationCount
*
* @return \Generator
*/
private function fetchIterationFromContentListIterator(ArrayIterator $contentListIterator, int $iterationCount): Generator
{
$iterator = $contentList->getIterator();
do {
$contentIds = [];
for ($i = 0; $i < $iterationCount; ++$i) {
$content = $iterator->current();
$content = $contentListIterator->current();
if ($content) {
$contentIds[] = $content->id;
} elseif (empty($contentIds)) {
return;
} else {
break;
}
$iterator->next();
$contentListIterator->next();
}

yield $contentIds;
Expand Down