Skip to content

Commit

Permalink
Fix queue auditing contracts breaking changes (#883)
Browse files Browse the repository at this point in the history
* Fix queue auditing contracts breaking changes

* Remove Dispatchable trait(Lumen compatibility)
  • Loading branch information
erikn69 authored Dec 20, 2023
1 parent 2d3510d commit 66498a9
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/Auditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ public function transformAudit(array $data): array
*
*/
protected function resolveUser()
{
{
if (! empty($this->preloadedResolverData['user'] ?? null)) {
return $this->preloadedResolverData['user'];
}

$userResolver = Config::get('audit.user.resolver');

if (is_null($userResolver) && Config::has('audit.resolver') && !Config::has('audit.user.resolver')) {
Expand Down
3 changes: 2 additions & 1 deletion src/AuditableObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ protected function dispatchAudit(Auditable $model)
return;
}

$model->preloadResolverData();
if (!Config::get('audit.queue.enable', false)) {
return Auditor::execute($model);
}
Expand All @@ -114,7 +115,7 @@ protected function dispatchAudit(Auditable $model)
}

// Unload the relations to prevent large amounts of unnecessary data from being serialized.
DispatchAudit::dispatch($model->preloadResolverData()->withoutRelations());
app()->make('events')->dispatch(new DispatchAudit($model->withoutRelations()));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/UserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface UserResolver
*
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public static function resolve(Auditable $auditable);
public static function resolve();
}
3 changes: 0 additions & 3 deletions src/Events/DispatchAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace OwenIt\Auditing\Events;

use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Foundation\Events\Dispatchable;

class DispatchAudit
{
use Dispatchable;

/**
* The Auditable model.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/UrlResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UrlResolver implements \OwenIt\Auditing\Contracts\Resolver
*/
public static function resolve(Auditable $auditable): string
{
if (! empty($auditable->preloadedResolverData['url'])) {
if (! empty($auditable->preloadedResolverData['url'] ?? null)) {
return $auditable->preloadedResolverData['url'];
}

Expand Down
6 changes: 1 addition & 5 deletions src/Resolvers/UserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ class UserResolver implements \OwenIt\Auditing\Contracts\UserResolver
/**
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public static function resolve(Auditable $auditable)
public static function resolve()
{
if (! empty($auditable->preloadedResolverData['user'])) {
return $auditable->preloadedResolverData['user'];
}

$guards = Config::get('audit.user.guards', [
\config('auth.defaults.guard')
]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ProcessDispatchAuditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function itGetsProperlyQueued()

$model = factory(Article::class)->create();

DispatchAudit::dispatch($model);
app()->make('events')->dispatch(new DispatchAudit($model));

Queue::assertPushed(CallQueuedListener::class, function ($job) use ($model) {
return $job->class == ProcessDispatchAudit::class
Expand All @@ -60,7 +60,7 @@ public function itCanHaveConnectionAndQueueSet()

$model = factory(Article::class)->create();

DispatchAudit::dispatch($model);
app()->make('events')->dispatch(new DispatchAudit($model));

Queue::assertPushedOn('audits', CallQueuedListener::class, function ($job) use ($model) {
$instantiatedJob = new $job->class;
Expand Down

0 comments on commit 66498a9

Please sign in to comment.