From f403db274a8f9f3638174b2cca7e481294c5d55b Mon Sep 17 00:00:00 2001 From: Martin Meredith Date: Wed, 13 Mar 2019 17:58:35 +0000 Subject: [PATCH] (develop) Fix asset auto-incrementation (#6806) * Fix auto-increment not updating This is due to the addition of caching for settings. If we're not explicitly saving the Settings model, then the cache isn't getting updated, causing the asset tag auto-increment to get an old cached version with the wrong number * Move Setting cache clear to an observer --- app/Events/SettingSaved.php | 20 ------------- app/Models/Setting.php | 11 -------- app/Observers/AssetObserver.php | 1 + app/Observers/SettingObserver.php | 23 +++++++++++++++ app/Providers/AppServiceProvider.php | 5 ++-- app/Providers/EventServiceProvider.php | 39 ++++++-------------------- 6 files changed, 35 insertions(+), 64 deletions(-) delete mode 100644 app/Events/SettingSaved.php create mode 100644 app/Observers/SettingObserver.php diff --git a/app/Events/SettingSaved.php b/app/Events/SettingSaved.php deleted file mode 100644 index e8423789b7..0000000000 --- a/app/Events/SettingSaved.php +++ /dev/null @@ -1,20 +0,0 @@ -settings = $settings; - } -} \ No newline at end of file diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 25ddbb6978..11325f0e8a 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -3,13 +3,11 @@ namespace App\Models; use Parsedown; -use App\Events\SettingSaved; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; use Watson\Validating\ValidatingTrait; -use Schema; use Illuminate\Support\Collection; /** @@ -42,15 +40,6 @@ class Setting extends Model */ protected $injectUniqueIdentifier = true; - /** - * The event map for the model. - * - * @var array - */ - protected $dispatchesEvents = [ - 'saved' => SettingSaved::class, - ]; - /** * Model rules. * diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index 2a42a26873..b435e9cb68 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -59,6 +59,7 @@ class AssetObserver { if ($settings = Setting::getSettings()) { $settings->increment('next_auto_tag_base'); + $settings->save(); } $logAction = new Actionlog(); diff --git a/app/Observers/SettingObserver.php b/app/Observers/SettingObserver.php new file mode 100644 index 0000000000..eea0240017 --- /dev/null +++ b/app/Observers/SettingObserver.php @@ -0,0 +1,23 @@ + [ + 'App\Listeners\LogSuccessfulLogin', + ], - 'Illuminate\Auth\Events\Login' => [ - 'App\Listeners\LogSuccessfulLogin', - ], - - 'Illuminate\Auth\Events\Failed' => [ - 'App\Listeners\LogFailedLogin', - ], - ]; + 'Illuminate\Auth\Events\Failed' => [ + 'App\Listeners\LogFailedLogin', + ], + ]; /** * The subscriber classes to register. @@ -37,22 +32,4 @@ class EventServiceProvider extends ServiceProvider LogListener::class, CheckoutableListener::class ]; - - /** - * Register any events for your application. - * - * @return void - */ - public function boot() - { - parent::boot(); - - /** - * Clear the LDAP settings cache when the settings model is saved - */ - Event::listen(SettingSaved::class, function () { - Cache::forget(Setting::APP_SETTINGS_KEY); - Cache::forget(Setting::SETUP_CHECK_KEY); - }); - } }