Skip to content

NOW MANAGED ON CODEBERG

Notifications: Fixed attempted null usage issue where int expected

Dan Brown5bf2d801cf0e
diff --git a/app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php b/app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php
index bc12c8566..daacfba56 100644
--- a/app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php
+++ b/app/Activity/Notifications/Handlers/CommentCreationNotificationHandler.php
@@ -27,7 +27,7 @@ class CommentCreationNotificationHandler extends BaseNotificationHandler
$watcherIds = $watchers->getWatcherUserIds();
// Page owner if user preferences allow
- if (!$watchers->isUserIgnoring($page->owned_by) && $page->ownedBy) {
+ if ($page->owned_by && !$watchers->isUserIgnoring($page->owned_by) && $page->ownedBy) {
$userNotificationPrefs = new UserNotificationPreferences($page->ownedBy);
if ($userNotificationPrefs->notifyOnOwnPageComments()) {
$watcherIds[] = $page->owned_by;
@@ -36,7 +36,7 @@ class CommentCreationNotificationHandler extends BaseNotificationHandler
// Parent comment creator if preferences allow
$parentComment = $detail->parent()->first();
- if ($parentComment && !$watchers->isUserIgnoring($parentComment->created_by) && $parentComment->createdBy) {
+ if ($parentComment && $parentComment->created_by && !$watchers->isUserIgnoring($parentComment->created_by) && $parentComment->createdBy) {
$parentCommenterNotificationsPrefs = new UserNotificationPreferences($parentComment->createdBy);
if ($parentCommenterNotificationsPrefs->notifyOnCommentReplies()) {
$watcherIds[] = $parentComment->created_by;
diff --git a/app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php b/app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php
index 20dc0fc4d..c9489d70e 100644
--- a/app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php
+++ b/app/Activity/Notifications/Handlers/PageUpdateNotificationHandler.php
@@ -39,8 +39,8 @@ class PageUpdateNotificationHandler extends BaseNotificationHandler
$watchers = new EntityWatchers($detail, WatchLevels::UPDATES);
$watcherIds = $watchers->getWatcherUserIds();
- // Add page owner if preferences allow
- if (!$watchers->isUserIgnoring($detail->owned_by) && $detail->ownedBy) {
+ // Add the page owner if preferences allow
+ if ($detail->owned_by && !$watchers->isUserIgnoring($detail->owned_by) && $detail->ownedBy) {
$userNotificationPrefs = new UserNotificationPreferences($detail->ownedBy);
if ($userNotificationPrefs->notifyOnOwnPageChanges()) {
$watcherIds[] = $detail->owned_by;
diff --git a/app/Entities/Models/Entity.php b/app/Entities/Models/Entity.php
index b47a029ec..641fe29d5 100644
--- a/app/Entities/Models/Entity.php
+++ b/app/Entities/Models/Entity.php
@@ -44,9 +44,9 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property Carbon $created_at
* @property Carbon $updated_at
* @property Carbon $deleted_at
- * @property int $created_by
- * @property int $updated_by
- * @property int $owned_by
+ * @property int|null $created_by
+ * @property int|null $updated_by
+ * @property int|null $owned_by
* @property Collection $tags
*
* @method static Entity|Builder visible()
diff --git a/tests/Activity/WatchTest.php b/tests/Activity/WatchTest.php
index f6f3b71c1..8be09f890 100644
--- a/tests/Activity/WatchTest.php
+++ b/tests/Activity/WatchTest.php
@@ -327,6 +327,24 @@ class WatchTest extends TestCase
});
}
+ public function test_notify_watch_page_ignore_when_no_page_owner()
+ {
+ $editor = $this->users->editor();
+ $entities = $this->entities->createChainBelongingToUser($editor);
+ $entities['page']->owned_by = null;
+ $entities['page']->save();
+
+ $watches = new UserEntityWatchOptions($editor, $entities['page']);
+ $watches->updateLevelByValue(WatchLevels::IGNORE);
+
+ $notifications = Notification::fake();
+ $this->asAdmin();
+
+ $this->entities->updatePage($entities['page'], ['name' => 'My updated page', 'html' => 'Hello']);
+
+ $notifications->assertNothingSent();
+ }
+
public function test_notifications_sent_in_right_language()
{
$editor = $this->users->editor();