2023-07-19 06:03:05 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Activity\Notifications\Handlers;
|
|
|
|
|
2023-08-15 09:39:39 -04:00
|
|
|
use BookStack\Activity\Models\Activity;
|
2023-07-19 06:03:05 -04:00
|
|
|
use BookStack\Activity\Models\Loggable;
|
2023-08-04 11:51:29 -04:00
|
|
|
use BookStack\Activity\Notifications\Messages\PageCreationNotification;
|
2023-08-04 07:27:29 -04:00
|
|
|
use BookStack\Activity\Tools\EntityWatchers;
|
|
|
|
use BookStack\Activity\WatchLevels;
|
2023-08-04 11:51:29 -04:00
|
|
|
use BookStack\Entities\Models\Page;
|
2023-08-04 07:27:29 -04:00
|
|
|
use BookStack\Users\Models\User;
|
2023-07-19 06:03:05 -04:00
|
|
|
|
2023-08-05 09:19:23 -04:00
|
|
|
class PageCreationNotificationHandler extends BaseNotificationHandler
|
2023-07-19 06:03:05 -04:00
|
|
|
{
|
2023-08-15 09:39:39 -04:00
|
|
|
public function handle(Activity $activity, Loggable|string $detail, User $user): void
|
2023-07-19 06:03:05 -04:00
|
|
|
{
|
2023-08-04 11:51:29 -04:00
|
|
|
if (!($detail instanceof Page)) {
|
|
|
|
throw new \InvalidArgumentException("Detail for page create notifications must be a page");
|
|
|
|
}
|
2023-08-04 07:27:29 -04:00
|
|
|
|
|
|
|
$watchers = new EntityWatchers($detail, WatchLevels::NEW);
|
2023-08-15 09:39:39 -04:00
|
|
|
$this->sendNotificationToUserIds(PageCreationNotification::class, $watchers->getWatcherUserIds(), $user, $detail, $detail);
|
2023-07-19 06:03:05 -04:00
|
|
|
}
|
|
|
|
}
|