Skip to content

Commit 0d4398a

Browse files
authored
Make queued audits feature opt-in (#881)
1 parent 2079683 commit 0d4398a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

config/audit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
*/
167167

168168
'queue' => [
169+
'enable' => true,
169170
'connection' => 'sync',
170171
'queue' => 'default',
171172
'delay' => 0,

src/AuditableObserver.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace OwenIt\Auditing;
44

5+
use Illuminate\Support\Facades\Config;
56
use OwenIt\Auditing\Contracts\Auditable;
67
use OwenIt\Auditing\Events\DispatchAudit;
78
use OwenIt\Auditing\Events\DispatchingAudit;
9+
use OwenIt\Auditing\Facades\Auditor;
810

911
class AuditableObserver
1012
{
@@ -99,7 +101,15 @@ public function restored(Auditable $model)
99101

100102
protected function dispatchAudit(Auditable $model)
101103
{
102-
if (!$model->readyForAuditing() || !$this->fireDispatchingAuditEvent($model)) {
104+
if (!$model->readyForAuditing()) {
105+
return;
106+
}
107+
108+
if (!Config::get('audit.queue.enable', true)) {
109+
return Auditor::execute($model);
110+
}
111+
112+
if (!$this->fireDispatchingAuditEvent($model)) {
103113
return;
104114
}
105115

0 commit comments

Comments
 (0)