mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
(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
This commit is contained in:
parent
a462e91983
commit
f403db274a
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Setting;
|
||||
|
||||
class SettingSaved
|
||||
{
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param \App\Models\Setting $settings
|
||||
*/
|
||||
public function __construct(Setting $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -59,6 +59,7 @@ class AssetObserver
|
|||
{
|
||||
if ($settings = Setting::getSettings()) {
|
||||
$settings->increment('next_auto_tag_base');
|
||||
$settings->save();
|
||||
}
|
||||
|
||||
$logAction = new Actionlog();
|
||||
|
|
23
app/Observers/SettingObserver.php
Normal file
23
app/Observers/SettingObserver.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class SettingObserver
|
||||
{
|
||||
/**
|
||||
* Listen to the Setting saved event.
|
||||
*
|
||||
* @param Setting $setting
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saved(Setting $setting)
|
||||
{
|
||||
Cache::forget(Setting::APP_SETTINGS_KEY);
|
||||
Cache::forget(Setting::SETUP_CHECK_KEY);
|
||||
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
namespace App\Providers;
|
||||
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Observers\SettingObserver;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
@ -41,8 +43,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
Component::observe(ComponentObserver::class);
|
||||
Consumable::observe(ConsumableObserver::class);
|
||||
License::observe(LicenseObserver::class);
|
||||
|
||||
|
||||
Setting::observe(SettingObserver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,12 +2,8 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Events\SettingSaved;
|
||||
use App\Listeners\LogListener;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use App\Listeners\CheckoutableListener;
|
||||
use App\Listeners\LogListener;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
|
@ -18,7 +14,6 @@ class EventServiceProvider extends ServiceProvider
|
|||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\LogSuccessfulLogin',
|
||||
],
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue