Skip to content

[6.x] Fix search:update ignoring the index argument when index names are customized#15024

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
edalzell:fix/update-search-index-bug
Jul 17, 2026
Merged

[6.x] Fix search:update ignoring the index argument when index names are customized#15024
jasonvarga merged 1 commit into
statamic:6.xfrom
edalzell:fix/update-search-index-bug

Conversation

@edalzell

@edalzell edalzell commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The problem

Customizing index names lets you rename an index at runtime, e.g. prefixing it per-environment:

Index::resolveNameUsing(fn ($name, $locale) => 'local_'.$name.'_'.$locale);

With a test index configured that way, php please search:update test doesn'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:

if (collect(config('statamic.search.indexes'))->put('cp', [])->has($arg)) {
    return $this->indexes()->filter(fn ($index) => Str::startsWith($index->name(), $arg))->all();
}

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_en doesn't start with test. The filter comes up empty and returns [], which is falsy, so it slips past the if ($requestedIndex = $this->getRequestedIndex()) guard in getIndexes() 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->handle to InsertMultipleJob precisely because the resolved name can't be reversed back into the handle. Update is the remaining caller doing it by string manipulation.

The fix

Match on the configured handle, which Index already tracks in $this->handle. This adds a public handle() accessor to Index and uses it:

if ($indexes = $this->indexes()->filter(fn ($index) => $index->handle() === $arg)->all()) {
    return $indexes;
}

This was written by good ol' Claude. I've reviewed the change and the tests, and confirmed the new test fails on 6.x and passes with the fix.

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.
@jasonvarga
jasonvarga merged commit 5d7ccd7 into statamic:6.x Jul 17, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants