Skip to content

NOW MANAGED ON CODEBERG

Notifications: Fixed error on comment notification

Dan Brown9de294343dd7
diff --git a/app/Activity/Models/Comment.php b/app/Activity/Models/Comment.php
index 4d6c7fa41..0f8e5d785 100644
--- a/app/Activity/Models/Comment.php
+++ b/app/Activity/Models/Comment.php
@@ -41,7 +41,19 @@ class Comment extends Model implements Loggable, OwnableInterface
*/
public function entity(): MorphTo
{
- return $this->morphTo('commentable');
+ // We specifically define null here to avoid the different name (commentable)
+ // being used by Laravel eager loading instead of the method name, which it was doing
+ // in some scenarios like when deserialized when going through the queue system.
+ // So we instead specify the type and id column names to use.
+ // Related to:
+ // https://github.com/laravel/framework/pull/24815
+ // https://github.com/laravel/framework/issues/27342
+ // https://github.com/laravel/framework/issues/47953
+ // (and probably more)
+
+ // Ultimately, we could just align the method name to 'commentable' but that would be a potential
+ // breaking change and not really worthwhile in a patch due to the risk of creating extra problems.
+ return $this->morphTo(null, 'commentable_type', 'commentable_id');
}
/**
diff --git a/app/Activity/Notifications/Handlers/BaseNotificationHandler.php b/app/Activity/Notifications/Handlers/BaseNotificationHandler.php
index bc6f2e22f..efa46b0d6 100644
--- a/app/Activity/Notifications/Handlers/BaseNotificationHandler.php
+++ b/app/Activity/Notifications/Handlers/BaseNotificationHandler.php
@@ -20,6 +20,7 @@ abstract class BaseNotificationHandler implements NotificationHandler
{
$users = User::query()->whereIn('id', array_unique($userIds))->get();
+ /** @var User $user */
foreach ($users as $user) {
// Prevent sending to the user that initiated the activity
if ($user->id === $initiator->id) {