[6.x] Fix search:update ignoring the index argument when index names are customized#15024
Merged
Merged
Conversation
When index names are customized via `Index::resolveNameUsing()`, passing a configured handle to `statamic:search:update` matched nothing and fell through to the "which index?" prompt instead of updating that index. `getRequestedIndex()` resolved the handle by prefix-matching against the resolved name, which no longer holds once a resolver renames the index. Match on the configured handle instead, which the index already tracks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Customizing index names lets you rename an index at runtime, e.g. prefixing it per-environment:
With a
testindex configured that way,php please search:update testdoesn't update the index. It silently drops the argument and shows the "Which search index would you like to update?" prompt instead — and if you're not paying attention, accepting the default reindexes everything. On a single-index site it's worse:getIndexes()returns all indexes without prompting at all.The cause
getRequestedIndex()resolved a configured handle by prefix-matching it against the resolved name:That assumes the resolved name still starts with the handle, which holds for the default
{handle}_{locale}naming but not once a resolver renames the index —local_test_endoesn't start withtest. The filter comes up empty and returns[], which is falsy, so it slips past theif ($requestedIndex = $this->getRequestedIndex())guard ingetIndexes()and falls through to the prompt rather than erroring.This is the same assumption that was already fixed for the insert job —
Index::insertMultiple()passes$this->handletoInsertMultipleJobprecisely because the resolved name can't be reversed back into the handle.Updateis the remaining caller doing it by string manipulation.The fix
Match on the configured handle, which
Indexalready tracks in$this->handle. This adds a publichandle()accessor toIndexand uses it:This was written by good ol' Claude. I've reviewed the change and the tests, and confirmed the new test fails on
6.xand passes with the fix.