Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fix the sync index settings command not using the scout prefix #670

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Console/SyncIndexSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Laravel\Scout\EngineManager;

class SyncIndexSettingsCommand extends Command
Expand Down Expand Up @@ -43,9 +44,9 @@ public function handle(EngineManager $manager)

if (count($indexes)) {
foreach ($indexes as $name => $settings) {
$engine->updateIndexSettings($name, $settings);
$engine->updateIndexSettings($indexName = $this->indexName($name), $settings);

$this->info('Settings for the ["'.$name.'"] index synced successfully.');
$this->info('Settings for the ["'.$indexName.'"] index synced successfully.');
}
} else {
$this->info('No index settings found for the "'.$driver.'" engine.');
Expand All @@ -54,4 +55,21 @@ public function handle(EngineManager $manager)
$this->error($exception->getMessage());
}
}

/**
* Get the fully-qualified index name for the given index.
*
* @param string $name
* @return string
*/
protected function indexName($name)
{
if (class_exists($name)) {
return (new $name)->searchableAs();
}

$prefix = config('scout.prefix');

return ! Str::startsWith($name, $prefix) ? $prefix.$name : $name;
}
}