Skip to content

Commit 8489fac

Browse files
tonysmtaylorotwell
andauthored
[9.x] Fix the sync index settings command not using the scout prefix (#670)
* Fix sync index settings command not using the scout prefix * Use Str::startsWith instead of str_starts_with since the former is PHP ^7.3 compatible * Fix StyleCI * formatting Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent ad3c2c5 commit 8489fac

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/Console/SyncIndexSettingsCommand.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Console\Command;
7+
use Illuminate\Support\Str;
78
use Laravel\Scout\EngineManager;
89

910
class SyncIndexSettingsCommand extends Command
@@ -43,9 +44,9 @@ public function handle(EngineManager $manager)
4344

4445
if (count($indexes)) {
4546
foreach ($indexes as $name => $settings) {
46-
$engine->updateIndexSettings($name, $settings);
47+
$engine->updateIndexSettings($indexName = $this->indexName($name), $settings);
4748

48-
$this->info('Settings for the ["'.$name.'"] index synced successfully.');
49+
$this->info('Settings for the ["'.$indexName.'"] index synced successfully.');
4950
}
5051
} else {
5152
$this->info('No index settings found for the "'.$driver.'" engine.');
@@ -54,4 +55,21 @@ public function handle(EngineManager $manager)
5455
$this->error($exception->getMessage());
5556
}
5657
}
58+
59+
/**
60+
* Get the fully-qualified index name for the given index.
61+
*
62+
* @param string $name
63+
* @return string
64+
*/
65+
protected function indexName($name)
66+
{
67+
if (class_exists($name)) {
68+
return (new $name)->searchableAs();
69+
}
70+
71+
$prefix = config('scout.prefix');
72+
73+
return ! Str::startsWith($name, $prefix) ? $prefix.$name : $name;
74+
}
5775
}

0 commit comments

Comments
 (0)