From 0d4398a76893a3326de7cf2c93af7aea844352bc Mon Sep 17 00:00:00 2001 From: erikn69 Date: Sun, 17 Dec 2023 12:30:46 -0500 Subject: [PATCH] Make queued audits feature opt-in (#881) --- config/audit.php | 1 + src/AuditableObserver.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/audit.php b/config/audit.php index 5dbcf4e2..472388c0 100644 --- a/config/audit.php +++ b/config/audit.php @@ -166,6 +166,7 @@ */ 'queue' => [ + 'enable' => true, 'connection' => 'sync', 'queue' => 'default', 'delay' => 0, diff --git a/src/AuditableObserver.php b/src/AuditableObserver.php index 08237c88..444745ae 100644 --- a/src/AuditableObserver.php +++ b/src/AuditableObserver.php @@ -2,9 +2,11 @@ namespace OwenIt\Auditing; +use Illuminate\Support\Facades\Config; use OwenIt\Auditing\Contracts\Auditable; use OwenIt\Auditing\Events\DispatchAudit; use OwenIt\Auditing\Events\DispatchingAudit; +use OwenIt\Auditing\Facades\Auditor; class AuditableObserver { @@ -99,7 +101,15 @@ public function restored(Auditable $model) protected function dispatchAudit(Auditable $model) { - if (!$model->readyForAuditing() || !$this->fireDispatchingAuditEvent($model)) { + if (!$model->readyForAuditing()) { + return; + } + + if (!Config::get('audit.queue.enable', true)) { + return Auditor::execute($model); + } + + if (!$this->fireDispatchingAuditEvent($model)) { return; }