Fix error when creating notifications about comments
authorMarcel Werk <burntime@woltlab.com>
Thu, 8 Feb 2024 13:19:15 +0000 (14:19 +0100)
committerMarcel Werk <burntime@woltlab.com>
Thu, 8 Feb 2024 13:19:15 +0000 (14:19 +0100)
Not all notification object types implement `ICommentUserNotificationObjectType`.

See https://github.com/WoltLab/WCF/commit/3f10b1a29299f458c8f802d5385ecf40c9b61c13

wcfsetup/install/files/lib/data/comment/CommentAction.class.php

index a7dc018cee19453bed834567477d71e0f58b1c9a..36c4e0197a7e8e9f44cb9c1aeae936e5845b0bd3 100644 (file)
@@ -514,7 +514,6 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
             if (UserNotificationHandler::getInstance()->getEvent($objectType->objectType . '.notification', 'comment')) {
                 $notificationObject = new CommentUserNotificationObject($comment->getDecoratedObject());
                 $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType . '.notification');
-                \assert($notificationObjectType instanceof ICommentUserNotificationObjectType);
 
                 if ($notificationObjectType instanceof IMultiRecipientCommentUserNotificationObjectType) {
                     $recipientIDs = $notificationObjectType->getRecipientIDs($comment->getDecoratedObject());
@@ -522,7 +521,9 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                     $recipientIDs = [];
                 }
 
-                $recipientIDs[] = $notificationObjectType->getOwnerID($comment->commentID);
+                if ($notificationObjectType instanceof ICommentUserNotificationObjectType) {
+                    $recipientIDs[] = $notificationObjectType->getOwnerID($comment->commentID);
+                }
 
                 // make sure that the comment's author gets no notification
                 $recipientIDs = \array_diff($recipientIDs, [$comment->getUserID()]);
@@ -719,7 +720,6 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
             ) {
                 $notificationObject = new CommentResponseUserNotificationObject($response);
                 $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType . '.notification');
-                \assert($notificationObjectType instanceof ICommentUserNotificationObjectType);
 
                 if ($notificationObjectType instanceof IMultiRecipientCommentUserNotificationObjectType) {
                     $recipientIDs = $notificationObjectType->getRecipientIDs($comment);
@@ -729,7 +729,10 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
 
                 $recipientIDs[] = $comment->userID;
 
-                $userID = $notificationObjectType->getOwnerID($comment->commentID);
+                $userID = 0;
+                if ($notificationObjectType instanceof ICommentUserNotificationObjectType) {
+                    $userID = $notificationObjectType->getOwnerID($comment->commentID);
+                }
 
                 // make sure that the response's author gets no notification
                 $recipientIDs = \array_diff($recipientIDs, [$response->getUserID()]);
@@ -750,7 +753,7 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
 
                 // notify the container owner
                 if (UserNotificationHandler::getInstance()->getEvent($objectType->objectType . '.response.notification', 'commentResponseOwner')) {
-                    if ($userID != $comment->userID && $userID != $response->getUserID()) {
+                    if ($userID && $userID != $comment->userID && $userID != $response->getUserID()) {
                         UserNotificationHandler::getInstance()->fireEvent(
                             'commentResponseOwner',
                             $objectType->objectType . '.response.notification',