Skip to content

Commit cd7c458

Browse files
freekmurzeclaude
andcommitted
fix tapActivity being called twice
The tapActivity method was being called both in LogsActivity trait and in ActivityLogger::log(). Since log() already handles calling tapActivity when a subject is set, the duplicate call in LogsActivity is removed. Fixes #1440 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent abdbe79 commit cd7c458

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/Traits/LogsActivity.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,12 @@ protected static function bootLogsActivity(): void
7676
}
7777

7878
// Actual logging
79-
$logger = app(ActivityLogger::class)
79+
app(ActivityLogger::class)
8080
->useLog($logName)
8181
->event($eventName)
8282
->performedOn($model)
83-
->withProperties($event->changes);
84-
85-
if (method_exists($model, 'tapActivity')) {
86-
$logger->tap([$model, 'tapActivity'], $eventName);
87-
}
88-
89-
$logger->log($description);
83+
->withProperties($event->changes)
84+
->log($description);
9085

9186
// Reset log options so the model can be serialized.
9287
$model->activitylogOptions = null;

tests/LogsActivityTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,32 @@ public function tapActivity(Activity $activity, string $eventName)
437437
$this->assertEquals('my custom event', $firstActivity->event);
438438
});
439439

440+
it('will only call tapActivity once', function () {
441+
$callCount = 0;
442+
443+
$model = new class() extends Article {
444+
use LogsActivity;
445+
446+
public static $tapCallCount = 0;
447+
448+
public function getActivitylogOptions(): LogOptions
449+
{
450+
return LogOptions::defaults();
451+
}
452+
453+
public function tapActivity(Activity $activity, string $eventName)
454+
{
455+
static::$tapCallCount++;
456+
}
457+
};
458+
459+
$model::$tapCallCount = 0;
460+
$entity = new $model();
461+
$entity->save();
462+
463+
$this->assertEquals(1, $model::$tapCallCount);
464+
});
465+
440466
it('will not submit log when there is no changes', function () {
441467
$model = new class() extends Article {
442468
use LogsActivity;

0 commit comments

Comments
 (0)