1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-04 05:22:38 +03:00

Notifications: Fixed error on comment notification

Fixes an error where a used relation (entity) on the comment was
resulting in null due to eager loading the notification when
deserializing from the queue, where Laravel was then mis-matching the
names when performing the eager loading.

For #5918
This commit is contained in:
Dan Brown
2025-11-25 21:08:45 +00:00
parent 98a09bcc37
commit 9de294343d
2 changed files with 14 additions and 1 deletions

View File

@@ -41,7 +41,19 @@ class Comment extends Model implements Loggable, OwnableInterface
*/ */
public function entity(): MorphTo 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');
} }
/** /**

View File

@@ -20,6 +20,7 @@ abstract class BaseNotificationHandler implements NotificationHandler
{ {
$users = User::query()->whereIn('id', array_unique($userIds))->get(); $users = User::query()->whereIn('id', array_unique($userIds))->get();
/** @var User $user */
foreach ($users as $user) { foreach ($users as $user) {
// Prevent sending to the user that initiated the activity // Prevent sending to the user that initiated the activity
if ($user->id === $initiator->id) { if ($user->id === $initiator->id) {