Fix config seeder will never run (#14113)

* Fix config seeder will never run
Because of startup processes, the config database is never empty.
Use config_seeded variable to detect if the config has been seeded.
But don't clobber settings that already exist in the database unless REAPPLY_YAML_CONFIG is set
Don't notify for existing settings that match, give tip that REAPPLY_YAML_CONFIG exists

* spelling
This commit is contained in:
Tony Murray
2022-07-15 11:08:33 -05:00
committed by GitHub
parent a6bc7490e2
commit ead4f1ad34

View File

@@ -57,12 +57,16 @@ class ConfigSeeder extends Seeder
return; // nothing to do
}
if (\App\Models\Config::exists() && ! getenv('REAPPLY_YAML_CONFIG')) {
$reapply = getenv('REAPPLY_YAML_CONFIG');
if (Config::get('config_seeded') && ! $reapply) {
if (! app()->runningInConsole() || ! $this->command->confirm(trans('commands.db:seed.existing_config'), false)) {
return; // don't overwrite existing settings.
}
}
$skipped_existing = false;
foreach ($files as $file) {
$settings = Yaml::parse(file_get_contents($file));
foreach (Arr::wrap($settings) as $key => $value) {
@@ -71,8 +75,22 @@ class ConfigSeeder extends Seeder
continue;
}
if (! $reapply && \App\Models\Config::where('config_name', $key)->exists()) {
if (! \App\Models\Config::where('config_name', $key)->value('config_value') == $value) {
echo 'Skipped existing config key: ' . json_encode($key) . PHP_EOL;
$skipped_existing = true;
}
continue;
}
Config::persist($key, $value);
}
}
Config::persist('config_seeded', true);
if ($skipped_existing) {
echo 'Skipped overwriting existing config settings. To overwrite them, run: REAPPLY_YAML_CONFIG=1 lnms db:seed' . PHP_EOL;
}
}
}