FIX: fix theme:set command.
This command did not set theme properly, when THEME was in .env file, but with no value (THEME= only - as default in .env.example).
This commit is contained in:
@@ -40,16 +40,31 @@ class SetTheme extends Command
|
||||
throw new NotFoundHttpException('Invalid theme ' . $theme . '!');
|
||||
}
|
||||
|
||||
$env = file_get_contents(base_path('.env'));
|
||||
// load .env file
|
||||
$envFile = base_path('.env');
|
||||
$env = file_get_contents($envFile);
|
||||
|
||||
$env = preg_replace('/THEME=(.+)/i', 'THEME=' . $theme, $env);
|
||||
|
||||
if (!Str::contains($env, 'THEME')) {
|
||||
if (!Str::contains($env, 'THEME=')) {
|
||||
$env = sprintf("%s\nTHEME=%s\n", $env, $theme);
|
||||
} else {
|
||||
$env = preg_replace('/THEME=(.*)/i', 'THEME=' . $theme, $env, -1, $cnt);
|
||||
}
|
||||
|
||||
file_put_contents(base_path('.env'), $env);
|
||||
// try to write content
|
||||
$bytesWritten = file_put_contents($envFile, $env);
|
||||
|
||||
// check if write was successfull
|
||||
if (!$bytesWritten) {
|
||||
throw new \Exception('Cannot write to ' . base_path('.env') . '. Add THEME=' . $theme . ' to your .env file manualy.');
|
||||
}
|
||||
|
||||
// theme written
|
||||
$this->line('Theme successfully setup.');
|
||||
$this->line('');
|
||||
$this->line(' ** PUBLISHING ASSETS AND VIEWS **');
|
||||
// publish assets and views for module and theme
|
||||
$this->call('vendor:publish', ['--tag' => ['public-assets'], '--force' => true]);
|
||||
$this->call('vendor:publish', ['--tag' => ['module-views'], '--force' => true]);
|
||||
$this->call('vendor:publish');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user