Repository navigation
Conversation
…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.
91c292a to
143e5d2
Compare
|
| $purge = false; | ||
| } elseif ($locationId = (int) $input->getOption('subtree')) { | ||
| $location = $this->locationHandler->load($locationId); | ||
| } elseif (($subtree = $input->getOption('subtree')) !== null) { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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' => [ |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.



Related PRs:
WordIndexer\Gateway\DoctrineDatabase::remove(), its body on 4.6, so expect a small conflict when it's merged upDescription:
ReindexCommandpassed the--content-idsvalues toIncrementalIndexer::updateSearchIndex()as strings, though it takesint[]. The legacy search engine passed them on through the untypedWordIndexer\Gateway::remove()intoSearchIndex'sintparameters. That only works while the gateway doesn't declare strict types. With them,ibexa:reindex --content-ids=123threw aTypeErrorfor content that was deleted or unpublished.remove()now takesint $contentId, ?int $versionId = nulland returnsbool, in the abstract gateway too.ReindexCommandparses--content-ids,--subtree,--iteration-countand--processesinto integers and rejects anything else.--subtreeand--processesused to be cast with(int), and an empty or0--content-idswas skipped, so--subtree=abcor--content-ids=0fell through to purging and rebuilding the whole index.Once this is in, the word indexer gateway can declare strict types again.
For QA:
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 bytests/bundle/Core/Command/ReindexCommandTest.php.