diff --git a/app/Foundation/Providers/ConfigServiceProvider.php b/app/Foundation/Providers/ConfigServiceProvider.php index e777300c..5351929a 100644 --- a/app/Foundation/Providers/ConfigServiceProvider.php +++ b/app/Foundation/Providers/ConfigServiceProvider.php @@ -14,6 +14,8 @@ namespace CachetHQ\Cachet\Foundation\Providers; use CachetHQ\Cachet\Config\Repository; use CachetHQ\Cachet\Models\Setting as SettingModel; use Exception; +use Illuminate\Contracts\Console\Kernel; +use Illuminate\Support\Facades\Config; use Illuminate\Support\ServiceProvider; /** @@ -32,6 +34,20 @@ class ConfigServiceProvider extends ServiceProvider */ public function boot() { + if ($this->app->configurationIsCached()) { + if ($this->app->environment() === 'production') { + $this->app->terminating(function () { + if ($this->app->setting->stale()) { + $this->app->make(Kernel::class)->call('config:cache'); + } + }); + } else { + $this->app->make(Kernel::class)->call('config:clear'); + } + + return; + } + try { // Get the default settings. $defaultSettings = $this->app->config->get('setting'); @@ -72,6 +88,12 @@ class ConfigServiceProvider extends ServiceProvider } $this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins); + + if ($this->app->environment() === 'production') { + $this->app->terminating(function () { + $this->app->make(Kernel::class)->call('config:cache'); + }); + } } /**