From: Tim Düsterhus Date: Thu, 31 Aug 2017 13:59:20 +0000 (+0200) Subject: Return objects with correct counters in UserNotificationAction::createStackable() X-Git-Tag: 3.1.0_Alpha_3~27^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a6c482aedc1046ea11b8823449c5321c2b1b4dfc;p=GitHub%2FWoltLab%2FWCF.git Return objects with correct counters in UserNotificationAction::createStackable() --- 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; }