X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/422e50302a05ac6cc0d0a02fa9155b3379ea4ddd..refs/pull/5721/head:/app/Activity/Tools/ActivityLogger.php diff --git a/app/Activity/Tools/ActivityLogger.php b/app/Activity/Tools/ActivityLogger.php index 315e8bfdf..415d11084 100644 --- a/app/Activity/Tools/ActivityLogger.php +++ b/app/Activity/Tools/ActivityLogger.php @@ -6,7 +6,7 @@ use BookStack\Activity\DispatchWebhookJob; use BookStack\Activity\Models\Activity; use BookStack\Activity\Models\Loggable; use BookStack\Activity\Models\Webhook; -use BookStack\App\Model; +use BookStack\Activity\Notifications\NotificationManager; use BookStack\Entities\Models\Entity; use BookStack\Facades\Theme; use BookStack\Theming\ThemeEvents; @@ -15,10 +15,16 @@ use Illuminate\Support\Facades\Log; class ActivityLogger { + public function __construct( + protected NotificationManager $notifications + ) { + $this->notifications->loadDefaultHandlers(); + } + /** * Add a generic activity event to the database. */ - public function add(string $type, $detail = '') + public function add(string $type, string|Loggable $detail = ''): void { $detailToStore = ($detail instanceof Loggable) ? $detail->logDescriptor() : $detail; @@ -26,14 +32,15 @@ class ActivityLogger $activity->detail = $detailToStore; if ($detail instanceof Entity) { - $activity->entity_id = $detail->id; - $activity->entity_type = $detail->getMorphClass(); + $activity->loggable_id = $detail->id; + $activity->loggable_type = $detail->getMorphClass(); } $activity->save(); $this->setNotification($type); $this->dispatchWebhooks($type, $detail); + $this->notifications->handle($activity, $detail, user()); Theme::dispatch(ThemeEvents::ACTIVITY_LOGGED, $type, $detail); } @@ -57,9 +64,9 @@ class ActivityLogger public function removeEntity(Entity $entity): void { $entity->activity()->update([ - 'detail' => $entity->name, - 'entity_id' => null, - 'entity_type' => null, + 'detail' => $entity->name, + 'loggable_id' => null, + 'loggable_type' => null, ]); }