Skip to content

Commit 5bf2d80

Browse files
committed
Notifications: Fixed attempted null usage issue where int expected
1 parent 1421ba8 commit 5bf2d80

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function handle(Activity $activity, Loggable|string $detail, User $user):
2727
$watcherIds = $watchers->getWatcherUserIds();
2828

2929
// Page owner if user preferences allow
30-
if (!$watchers->isUserIgnoring($page->owned_by) && $page->ownedBy) {
30+
if ($page->owned_by && !$watchers->isUserIgnoring($page->owned_by) && $page->ownedBy) {
3131
$userNotificationPrefs = new UserNotificationPreferences($page->ownedBy);
3232
if ($userNotificationPrefs->notifyOnOwnPageComments()) {
3333
$watcherIds[] = $page->owned_by;
@@ -36,7 +36,7 @@ public function handle(Activity $activity, Loggable|string $detail, User $user):
3636

3737
// Parent comment creator if preferences allow
3838
$parentComment = $detail->parent()->first();
39-
if ($parentComment && !$watchers->isUserIgnoring($parentComment->created_by) && $parentComment->createdBy) {
39+
if ($parentComment && $parentComment->created_by && !$watchers->isUserIgnoring($parentComment->created_by) && $parentComment->createdBy) {
4040
$parentCommenterNotificationsPrefs = new UserNotificationPreferences($parentComment->createdBy);
4141
if ($parentCommenterNotificationsPrefs->notifyOnCommentReplies()) {
4242
$watcherIds[] = $parentComment->created_by;

app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function handle(Activity $activity, Loggable|string $detail, User $user):
3939
$watchers = new EntityWatchers($detail, WatchLevels::UPDATES);
4040
$watcherIds = $watchers->getWatcherUserIds();
4141

42-
// Add page owner if preferences allow
43-
if (!$watchers->isUserIgnoring($detail->owned_by) && $detail->ownedBy) {
42+
// Add the page owner if preferences allow
43+
if ($detail->owned_by && !$watchers->isUserIgnoring($detail->owned_by) && $detail->ownedBy) {
4444
$userNotificationPrefs = new UserNotificationPreferences($detail->ownedBy);
4545
if ($userNotificationPrefs->notifyOnOwnPageChanges()) {
4646
$watcherIds[] = $detail->owned_by;

app/Entities/Models/Entity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
* @property Carbon $created_at
4545
* @property Carbon $updated_at
4646
* @property Carbon $deleted_at
47-
* @property int $created_by
48-
* @property int $updated_by
49-
* @property int $owned_by
47+
* @property int|null $created_by
48+
* @property int|null $updated_by
49+
* @property int|null $owned_by
5050
* @property Collection $tags
5151
*
5252
* @method static Entity|Builder visible()

tests/Activity/WatchTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,24 @@ public function test_notify_watch_parent_book_new()
327327
});
328328
}
329329

330+
public function test_notify_watch_page_ignore_when_no_page_owner()
331+
{
332+
$editor = $this->users->editor();
333+
$entities = $this->entities->createChainBelongingToUser($editor);
334+
$entities['page']->owned_by = null;
335+
$entities['page']->save();
336+
337+
$watches = new UserEntityWatchOptions($editor, $entities['page']);
338+
$watches->updateLevelByValue(WatchLevels::IGNORE);
339+
340+
$notifications = Notification::fake();
341+
$this->asAdmin();
342+
343+
$this->entities->updatePage($entities['page'], ['name' => 'My updated page', 'html' => 'Hello']);
344+
345+
$notifications->assertNothingSent();
346+
}
347+
330348
public function test_notifications_sent_in_right_language()
331349
{
332350
$editor = $this->users->editor();

0 commit comments

Comments
 (0)