Skip to content

Commit

Permalink
NGSTACK-843 use symfony style in command
Browse files Browse the repository at this point in the history
  • Loading branch information
Katarina Miočić committed May 10, 2024
1 parent e4db8b1 commit db86bac
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions bundle/Command/IndexPageContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
use Symfony\Component\Console\Output\OutputInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList;

use Symfony\Component\Console\Style\SymfonyStyle;
use function count;
use function explode;

class IndexPageContentCommand extends Command
{
protected static $defaultName = 'netgen-search-extra:index-page-content';
private SymfonyStyle $style;

/**
* @param array<string, mixed> $sitesConfig
Expand All @@ -49,6 +51,11 @@ protected function configure(): void
);
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->style = new SymfonyStyle($input, $output);
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
Expand All @@ -57,9 +64,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
foreach ($this->sitesConfig as $site => $siteConfig) {
$output->writeln('');
$output->writeln("Indexing for site " . $site);
$output->writeln('');
$this->style->info("Indexing for site " . $site);
$this->indexContent($output, $input, $siteConfig);
}

Expand All @@ -77,30 +82,27 @@ private function indexContent(OutputInterface $output, InputInterface $input, ar
$progressBar = new ProgressBar($output, $totalCount);

if ($totalCount <= 0) {
$output->writeln('No content found to index, exiting.');
$this->style->info('No content found to index, exiting.');

return;
}

$output->writeln('Found ' . $totalCount . ' content objects...');
$output->writeln('');
$this->style->info('Found ' . $totalCount . ' content objects...');

$progressBar->start($totalCount);

while ($offset < $totalCount) {
$chunk = $this->getChunk($limit, $offset, $allowedContentTypes, $contentIds);

$this->processChunk($chunk, $output, $progressBar);
$this->processChunk($chunk, $progressBar);

$offset += $limit;
}

$progressBar->finish();

$output->writeln('');
$output->writeln('');
$output->writeln('Finished.');
$output->writeln('');
$this->style->info('Finished.');

}

Expand Down Expand Up @@ -142,14 +144,14 @@ private function getFilter(array $allowedContentTypes, array $contentIds = []):
return $filter;
}

private function processChunk(ContentList $contentList, OutputInterface $output, ProgressBar $progressBar): void
private function processChunk(ContentList $contentList, ProgressBar $progressBar): void
{
foreach ($contentList->getIterator() as $content) {
try {
$this->indexContentWithLocations($content);
$progressBar->advance();
} catch (IndexPageUnavailableException $exception) {
$output->writeln($exception->getMessage());
$this->style->error($exception->getMessage());
}
}
}
Expand Down

0 comments on commit db86bac

Please sign in to comment.