Skip to content

IBX-13203: Typed the word indexer's remove() and validated ReindexCommand's integer options - #966

Open
Steveb-p wants to merge 1 commit into
6.0from
IBX-13203-reindex-integer-options
Open

Steveb-p wants to merge 1 commit into
6.0from
IBX-13203-reindex-integer-options

Conversation

@Steveb-p

@Steveb-p Steveb-p commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
🎫 Issue IBX-13203

Related PRs:

Description:

ReindexCommand passed the --content-ids values to IncrementalIndexer::updateSearchIndex() as strings, though it takes int[]. The legacy search engine passed them on through the untyped WordIndexer\Gateway::remove() into SearchIndex's int parameters. That only works while the gateway doesn't declare strict types. With them, ibexa:reindex --content-ids=123 threw a TypeError for content that was deleted or unpublished.

remove() now takes int $contentId, ?int $versionId = null and returns bool, in the abstract gateway too. ReindexCommand parses --content-ids, --subtree, --iteration-count and --processes into integers and rejects anything else. --subtree and --processes used to be cast with (int), and an empty or 0 --content-ids was skipped, so --subtree=abc or --content-ids=0 fell through to purging and rebuilding the whole index.

Once this is in, the word indexer gateway can declare strict types again.

For QA:

php bin/console ibexa:reindex --content-ids=2,34,68
php bin/console ibexa:reindex --subtree=abc

The first one indexes the three items as before. The second one used to purge and rebuild the whole index, now it stops with Argument '--subtree' is invalid: The value must be an integer of at least 1, you provided 'abc'. Covered by tests/bundle/Core/Command/ReindexCommandTest.php.

@Steveb-p
Steveb-p marked this pull request as ready for review November 17, 2026 14:16
@Steveb-p Steveb-p added Ready for review Bug Something isn't working labels Nov 17, 2026
@Steveb-p
Steveb-p requested a review from a team November 18, 2026 10:05
…mand's integer options

ReindexCommand passed the --content-ids values on as strings, and cast
--subtree and --processes with (int), so a value like --subtree=abc or
--content-ids=0 fell through to purging and rebuilding the whole index.
The integer options are now parsed into integers, and rejected when they
aren't valid.
@Steveb-p
Steveb-p force-pushed the IBX-13203-reindex-integer-options branch from 91c292a to 143e5d2 Compare November 18, 2026 10:05
@sonarqubecloud

Copy link
Copy Markdown

$purge = false;
} elseif ($locationId = (int) $input->getOption('subtree')) {
$location = $this->locationHandler->load($locationId);
} elseif (($subtree = $input->getOption('subtree')) !== null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bare --subtree with no value still purges and rebuilds the whole index. Both --subtree and --content-ids are VALUE_OPTIONAL with no default. Symfony returns null for a bare option, and !== null treats it as if the option was not given. The command then goes to the else branch and calls purge(). Could we detect the bare option with $input->hasParameterOption('--subtree') and throw? The same applies to --content-ids at line 246

): void {
$indexer = $this->createIndexer();
$indexer->expects($this->never())->method('updateSearchIndex');
$indexer->expects($this->never())->method('purge');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never() can't fail. The IndexerGateway stub returns 0 from countAllContent(). Even if the old fall-through came back, the command would stop at "Could not find any items" before it reaches purge(). Could we stub countAllContent() and getAllContent() to return some content, so this expectation really proves the full reindex is skipped?

['--content-ids' => ''],
"Argument '--content-ids' is invalid: The value must be an integer of at least 1, you provided ''",
];
yield 'subtree that is not a number' => [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a 'subtree 0' case (and maybe an empty --subtree=)? 'abc' is truthy. If the old truthy check came back in place of !== null, the suite would still be green. --subtree=0 is the value that used to fall through to a full reindex.

{
$processes = $input->getOption('processes');

return $processes === 'auto' ? null : $this->parseIntegerOptionValue($processes, 'processes', 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test runs an accepted --processes or --subtree value. Raising the processes minimum to 1 (which would reject the documented --processes=0), changing the <= 1 check, or passing a wrong ID to load() would all keep the suite green. It may be worth adding one happy-path case, for example --subtree=45 --processes=0 with load(45) expected and a stubbed batch list indexed inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants