From 0027bc961f86c703da60df87eef66b348b62b94a Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 15 Apr 2021 14:33:16 +0200 Subject: [PATCH] Fix `UserNotification::markAllAsConfirmed()` for no unconfirmed notifications See 81982c717bbb55c36306ede938dc189f01f85592 --- .../UserNotificationAction.class.php | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php b/wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php index 10e9d218cd..db1d7a55aa 100644 --- a/wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php +++ b/wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php @@ -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'); -- 2.20.1