]> BookStack Code Mirror - bookstack/blob - app/Activity/Notifications/Handlers/PageCreationNotificationHandler.php
e9aca2f231fae7509275db3b5ad0935149fc5d5d
[bookstack] / app / Activity / Notifications / Handlers / PageCreationNotificationHandler.php
1 <?php
2
3 namespace BookStack\Activity\Notifications\Handlers;
4
5 use BookStack\Activity\Models\Loggable;
6 use BookStack\Activity\Notifications\Messages\PageCreationNotification;
7 use BookStack\Activity\Tools\EntityWatchers;
8 use BookStack\Activity\WatchLevels;
9 use BookStack\Entities\Models\Page;
10 use BookStack\Users\Models\User;
11
12 class PageCreationNotificationHandler extends BaseNotificationHandler
13 {
14     public function handle(string $activityType, Loggable|string $detail, User $user): void
15     {
16         if (!($detail instanceof Page)) {
17             throw new \InvalidArgumentException("Detail for page create notifications must be a page");
18         }
19
20         $watchers = new EntityWatchers($detail, WatchLevels::NEW);
21         $this->sendNotificationToUserIds(PageCreationNotification::class, $watchers->getWatcherUserIds(), $user, $detail);
22     }
23 }