Skip to content

Commit

Permalink
Make sure identifiers are empty (#465)
Browse files Browse the repository at this point in the history
Fix and add missing parts of
#460
  • Loading branch information
Toflar authored Dec 27, 2024
1 parent 4f765ab commit 45c93e6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
10 changes: 8 additions & 2 deletions integrations/laravel/src/Console/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ReindexCommand extends Command
*
* @var string
*/
protected $signature = 'cmsig:seal:reindex {--engine= : The name of the engine} {--index= : The name of the index} {--drop : Drop the index before reindexing} {--bulk-size= : The bulk size for reindexing, defaults to 100.}';
protected $signature = 'cmsig:seal:reindex {--engine= : The name of the engine} {--index= : The name of the index} {--drop : Drop the index before reindexing} {--bulk-size= : The bulk size for reindexing, defaults to 100.} {--datetime-boundary= : Do a partial update and limit to only documents that have been changed since a given datetime object.} {--identifiers= : Do a partial update and limit to only a comma-separated list of identifiers.}';

/**
* The console command description.
Expand Down Expand Up @@ -60,11 +60,17 @@ public function handle(
$drop = $this->option('drop');
/** @var int $bulkSize */
$bulkSize = ((int) $this->option('bulk-size')) ?: 100;
/** @var \DateTimeImmutable|null $dateTimeBoundary */
$dateTimeBoundary = $this->option('datetime-boundary') ? new \DateTimeImmutable((string) $this->option('datetime-boundary')) : null; // @phpstan-ignore-line
/** @var array<string> $identifiers */
$identifiers = \array_filter(\explode(',', (string) $this->option('identifiers'))); // @phpstan-ignore-line

$reindexConfig = ReindexConfig::create()
->withIndex($indexName)
->withBulkSize($bulkSize)
->withDropIndex($drop);
->withDropIndex($drop)
->withDateTimeBoundary($dateTimeBoundary)
->withIdentifiers($identifiers);

foreach ($engineRegistry->getEngines() as $name => $engine) {
if ($engineName && $engineName !== $name) {
Expand Down
10 changes: 9 additions & 1 deletion integrations/mezzio/src/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected function configure(): void
$this->addOption('index', null, InputOption::VALUE_REQUIRED, 'The name of the index to create the schema for.');
$this->addOption('drop', null, InputOption::VALUE_NONE, 'Drop the index before reindexing.');
$this->addOption('bulk-size', null, InputOption::VALUE_REQUIRED, 'The bulk size for reindexing, defaults to 100.');
$this->addOption('datetime-boundary', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only documents that have been changed since a given datetime object.');
$this->addOption('identifiers', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only a comma-separated list of identifiers.');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -57,11 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$drop = $input->getOption('drop');
/** @var int $bulkSize */
$bulkSize = ((int) $input->getOption('bulk-size')) ?: 100; // @phpstan-ignore-line
/** @var \DateTimeImmutable|null $dateTimeBoundary */
$dateTimeBoundary = $input->getOption('datetime-boundary') ? new \DateTimeImmutable((string) $input->getOption('datetime-boundary')) : null; // @phpstan-ignore-line
/** @var array<string> $identifiers */
$identifiers = \array_filter(\explode(',', (string) $input->getOption('identifiers'))); // @phpstan-ignore-line

$reindexConfig = ReindexConfig::create()
->withIndex($indexName)
->withBulkSize($bulkSize)
->withDropIndex($drop);
->withDropIndex($drop)
->withDateTimeBoundary($dateTimeBoundary)
->withIdentifiers($identifiers);

foreach ($this->engineRegistry->getEngines() as $name => $engine) {
if ($engineName && $engineName !== $name) {
Expand Down
15 changes: 14 additions & 1 deletion integrations/spiral/src/Console/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ final class ReindexCommand extends Command
#[Option(name: 'bulk-size', description: 'The bulk size for reindexing, defaults to 100.')]
private int $bulkSize = 100;

#[Option(name: 'datetime-boundary', description: 'Do a partial update and limit to only documents that have been changed since a given datetime object.')]
private string|null $datetimeBoundary = null;

#[Option(name: 'identifiers', description: 'Do a partial update and limit to only a comma-separated list of identifiers.')]
private string|null $identifiers = null;

/**
* @param iterable<ReindexProviderInterface> $reindexProviders
*/
Expand All @@ -54,10 +60,17 @@ public function __construct(
public function __invoke(
EngineRegistry $engineRegistry,
): int {
/** @var \DateTimeImmutable|null $dateTimeBoundary */
$dateTimeBoundary = $this->datetimeBoundary ? new \DateTimeImmutable((string) $this->datetimeBoundary) : null; // @phpstan-ignore-line
/** @var array<string> $identifiers */
$identifiers = \array_filter(\explode(',', (string) $this->identifiers)); // @phpstan-ignore-line

$reindexConfig = ReindexConfig::create()
->withIndex($this->indexName)
->withBulkSize($this->bulkSize)
->withDropIndex($this->drop);
->withDropIndex($this->drop)
->withDateTimeBoundary($dateTimeBoundary)
->withIdentifiers($identifiers);

foreach ($engineRegistry->getEngines() as $name => $engine) {
if ($this->engineName && $this->engineName !== $name) {
Expand Down
2 changes: 1 addition & 1 deletion integrations/symfony/src/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var \DateTimeImmutable|null $dateTimeBoundary */
$dateTimeBoundary = $input->getOption('datetime-boundary') ? new \DateTimeImmutable((string) $input->getOption('datetime-boundary')) : null; // @phpstan-ignore-line
/** @var array<string> $identifiers */
$identifiers = \explode(',', (string) $input->getOption('identifiers')); // @phpstan-ignore-line
$identifiers = \array_filter(\explode(',', (string) $input->getOption('identifiers'))); // @phpstan-ignore-line

$reindexConfig = ReindexConfig::create()
->withIndex($indexName)
Expand Down
10 changes: 9 additions & 1 deletion integrations/yii/src/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected function configure(): void
$this->addOption('index', null, InputOption::VALUE_REQUIRED, 'The name of the index to create the schema for.');
$this->addOption('drop', null, InputOption::VALUE_NONE, 'Drop the index before reindexing.');
$this->addOption('bulk-size', null, InputOption::VALUE_REQUIRED, 'The bulk size for reindexing, defaults to 100.');
$this->addOption('datetime-boundary', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only documents that have been changed since a given datetime object.');
$this->addOption('identifiers', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only a comma-separated list of identifiers.');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -57,11 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$drop = $input->getOption('drop');
/** @var int $bulkSize */
$bulkSize = ((int) $input->getOption('bulk-size')) ?: 100; // @phpstan-ignore-line
/** @var \DateTimeImmutable|null $dateTimeBoundary */
$dateTimeBoundary = $input->getOption('datetime-boundary') ? new \DateTimeImmutable((string) $input->getOption('datetime-boundary')) : null; // @phpstan-ignore-line
/** @var array<string> $identifiers */
$identifiers = \array_filter(\explode(',', (string) $input->getOption('identifiers'))); // @phpstan-ignore-line

$reindexConfig = ReindexConfig::create()
->withIndex($indexName)
->withBulkSize($bulkSize)
->withDropIndex($drop);
->withDropIndex($drop)
->withDateTimeBoundary($dateTimeBoundary)
->withIdentifiers($identifiers);

foreach ($this->engineRegistry->getEngines() as $name => $engine) {
if ($engineName && $engineName !== $name) {
Expand Down

0 comments on commit 45c93e6

Please sign in to comment.