Fix `UserNotification::markAllAsConfirmed()` for no unconfirmed notifications
authorMatthias Schmidt <gravatronics@live.com>
Thu, 15 Apr 2021 12:33:16 +0000 (14:33 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 15 Apr 2021 12:33:16 +0000 (14:33 +0200)
See 81982c717bbb55c36306ede938dc189f01f85592

wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php

index 10e9d218cdbc861533374ad426c40a20ba46ee93..db1d7a55aab914eee4fe3242012e2296993faad9 100644 (file)
@@ -252,30 +252,32 @@ class UserNotificationAction extends AbstractDatabaseObjectAction {
                ]);
                $notificationIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
                
-               // Step 2) Mark the notifications as read.
-               $condition = new PreparedStatementConditionBuilder();
-               $condition->add('notificationID IN (?)', [$notificationIDs]);
-               
-               $sql = "UPDATE  wcf".WCF_N."_user_notification
-                       SET     confirmTime = ?
-                       {$condition}";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(\array_merge(
-                       [TIME_NOW],
-                       $condition->getParameters()
-               ));
-               
-               // Step 3) Delete notification_to_user assignments (mimic legacy notification system)
-               
-               // This conditions technically is not required, because notificationIDs are unique.
-               // As this is not enforced at the database layer we play safe until this legacy table
-               // finally is removed.
-               $condition->add('userID = ?', [WCF::getUser()->userID]);
-               
-               $sql = "DELETE FROM     wcf".WCF_N."_user_notification_to_user
-                       {$condition}";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute($condition->getParameters());
+               if (!empty($notificationIDs)) {
+                       // Step 2) Mark the notifications as read.
+                       $condition = new PreparedStatementConditionBuilder();
+                       $condition->add('notificationID IN (?)', [$notificationIDs]);
+                       
+                       $sql = "UPDATE  wcf".WCF_N."_user_notification
+                               SET     confirmTime = ?
+                               {$condition}";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(\array_merge(
+                               [TIME_NOW],
+                               $condition->getParameters()
+                       ));
+                       
+                       // Step 3) Delete notification_to_user assignments (mimic legacy notification system)
+                       
+                       // This conditions technically is not required, because notificationIDs are unique.
+                       // As this is not enforced at the database layer we play safe until this legacy table
+                       // finally is removed.
+                       $condition->add('userID = ?', [WCF::getUser()->userID]);
+                       
+                       $sql = "DELETE FROM     wcf".WCF_N."_user_notification_to_user
+                               {$condition}";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute($condition->getParameters());
+               }
                
                // Step 4) Clear cached values.
                UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'userNotificationCount');