Skip to content

Commit

Permalink
Make queued audits feature opt-in (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 authored Dec 17, 2023
1 parent 2079683 commit 0d4398a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
*/

'queue' => [
'enable' => true,
'connection' => 'sync',
'queue' => 'default',
'delay' => 0,
Expand Down
12 changes: 11 additions & 1 deletion src/AuditableObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 0d4398a

Please sign in to comment.