From a6c482aedc1046ea11b8823449c5321c2b1b4dfc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 31 Aug 2017 15:59:20 +0200 Subject: [PATCH] Return objects with correct counters in UserNotificationAction::createStackable() --- .../UserNotificationAction.class.php | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 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 373a0eba01..b94d434893 100644 --- a/wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php +++ b/wcfsetup/install/files/lib/data/user/notification/UserNotificationAction.class.php @@ -131,28 +131,26 @@ class UserNotificationAction extends AbstractDatabaseObjectAction { $sql = "INSERT IGNORE INTO wcf".WCF_N."_user_notification_author (notificationID, authorID, time) VALUES (?, ?, ?)"; - $statement = WCF::getDB()->prepareStatement($sql); - - WCF::getDB()->beginTransaction(); - foreach ($notifications as $notificationData) { - $statement->execute([ - $notificationData['object']->notificationID, - $this->parameters['authorID'] ?: null, - TIME_NOW - ]); - } - WCF::getDB()->commitTransaction(); + $authorStatement = WCF::getDB()->prepareStatement($sql); // update trigger count $sql = "UPDATE wcf".WCF_N."_user_notification SET timesTriggered = timesTriggered + ?, guestTimesTriggered = guestTimesTriggered + ? WHERE notificationID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - + $triggerStatement = WCF::getDB()->prepareStatement($sql); + WCF::getDB()->beginTransaction(); + $notificationIDs = []; foreach ($notifications as $notificationData) { - $statement->execute([ + $notificationIDs[] = $notificationData['object']->notificationID; + + $authorStatement->execute([ + $notificationData['object']->notificationID, + $this->parameters['authorID'] ?: null, + TIME_NOW + ]); + $triggerStatement->execute([ 1, $this->parameters['authorID'] ? 0 : 1, $notificationData['object']->notificationID @@ -160,6 +158,16 @@ class UserNotificationAction extends AbstractDatabaseObjectAction { } WCF::getDB()->commitTransaction(); + $notificationList = new UserNotificationList(); + $notificationList->setObjectIDs($notificationIDs); + $notificationList->readObjects(); + $updatedNotifications = $notificationList->getObjects(); + + $notifications = array_map(function ($notificationData) use ($updatedNotifications) { + $notificationData['object'] = $updatedNotifications[$notificationData['object']->notificationID]; + return $notificationData; + }, $notifications); + return $notifications; } -- 2.20.1