From f85474f17165674ad4eea75990158d4ff066da28 Mon Sep 17 00:00:00 2001 From: Jeremiasz Major Date: Sat, 25 Feb 2023 22:54:15 +0100 Subject: [PATCH] Do not tap activities twice --- src/Traits/LogsActivity.php | 4 ---- tests/LogsActivityTest.php | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Traits/LogsActivity.php b/src/Traits/LogsActivity.php index 770ada80..2434ba76 100644 --- a/src/Traits/LogsActivity.php +++ b/src/Traits/LogsActivity.php @@ -81,10 +81,6 @@ protected static function bootLogsActivity(): void ->performedOn($model) ->withProperties($event->changes); - if (method_exists($model, 'tapActivity')) { - $logger->tap([$model, 'tapActivity'], $eventName); - } - $logger->log($description); // Reset log options so the model can be serialized. diff --git a/tests/LogsActivityTest.php b/tests/LogsActivityTest.php index eca70b19..6e7c97c3 100644 --- a/tests/LogsActivityTest.php +++ b/tests/LogsActivityTest.php @@ -304,6 +304,8 @@ public function getActivitylogOptions(): LogOptions $model = new class() extends Article { use LogsActivity; + public static int $tapActivityCallCount = 0; + public function getActivitylogOptions(): LogOptions { return LogOptions::defaults(); @@ -317,6 +319,8 @@ public function getActivitylogOptions(): LogOptions public function tapActivity(Activity $activity, string $eventName) { + self::$tapActivityCallCount++; + $properties = $this->properties; $properties['event'] = $eventName; $activity->properties = collect($properties); @@ -327,6 +331,8 @@ public function tapActivity(Activity $activity, string $eventName) $entity = new $model(); $entity->save(); + $this->assertSame(1, $model::$tapActivityCallCount); + $firstActivity = $entity->activities()->first(); $this->assertInstanceOf(Collection::class, $firstActivity->properties);