Improved event access for user notifications
authorAlexander Ebert <ebert@woltlab.com>
Wed, 25 Dec 2019 16:26:04 +0000 (17:26 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 25 Dec 2019 16:26:04 +0000 (17:26 +0100)
Closes #3017

wcfsetup/install/files/lib/data/user/notification/UserNotificationEditor.class.php
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php

index 168e59ccdbb7c98f5e2aa8debbca64dffcd5e4d8..205fafd9209e7197268daccdaf94ba4a5e7bdfda 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace wcf\data\user\notification;
 use wcf\data\DatabaseObjectEditor;
-use wcf\system\WCF;
+use wcf\system\user\notification\UserNotificationHandler;
 
 /**
  * Provides functions to edit user notifications.
@@ -23,17 +23,10 @@ class UserNotificationEditor extends DatabaseObjectEditor {
        
        /**
         * Marks this notification as confirmed.
+        * 
+        * @deprecated 5.2 Please use `UserNotificationHandler::markAsConfirmedByIDs()` instead.
         */
        public function markAsConfirmed() {
-               $this->update([
-                       'confirmTime' => TIME_NOW,
-                       'mailNotified' => 1
-               ]);
-               
-               // delete notification_to_user assignment (mimic legacy notification system)
-               $sql = "DELETE FROM     wcf".WCF_N."_user_notification_to_user
-                       WHERE           notificationID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute([$this->notificationID]);
+               UserNotificationHandler::getInstance()->markAsConfirmedByIDs([$this->notificationID]);
        }
 }
index 378a7838bf858b821d3690b0d2d9893f6d516a5d..e94ff344a296d9d7d5e953130a89171656db686c 100644 (file)
@@ -122,6 +122,7 @@ class UserNotificationHandler extends SingletonFactory {
                        'userProfile' => $userProfile,
                        'event' => $event
                ];
+               // @deprecated 5.2 This event exposes incomplete data and should not be used, please use the following events instead.
                EventHandler::getInstance()->fireAction($this, 'fireEvent', $parameters);
                
                // find existing notifications
@@ -181,6 +182,11 @@ class UserNotificationHandler extends SingletonFactory {
                                        ]);
                                }
                                WCF::getDB()->commitTransaction();
+                               
+                               $triggerCountParameters = $parameters;
+                               $triggerCountParameters['updateTriggerCount'] = $notificationIDs;
+                               EventHandler::getInstance()->fireAction($this, 'updateTriggerCount', $parameters);
+                               unset($triggerCountParameters);
                        }
                }
                
@@ -268,6 +274,10 @@ class UserNotificationHandler extends SingletonFactory {
                        
                        // reset notification count
                        UserStorageHandler::getInstance()->reset(array_keys($recipients), 'userNotificationCount');
+                       
+                       $parameters['notifications'] = $notifications;
+                       $parameters['recipients'] = $recipients;
+                       EventHandler::getInstance()->fireAction($this, 'createdNotification', $parameters);
                }
        }
        
@@ -777,6 +787,14 @@ class UserNotificationHandler extends SingletonFactory {
                                UserStorageHandler::getInstance()->reset(array_unique($userIDs), 'userNotificationCount');
                        }
                        
+                       $parameters = [
+                               'eventIDs' => $eventIDs,
+                               'objectIDs' => $objectIDs,
+                               'objectType' => $objectType,
+                               'userIDs' => $userIDs,
+                       ];
+                       EventHandler::getInstance()->fireAction($this, 'removeNotifications', $parameters);
+                       
                        // delete notifications
                        $sql = "DELETE FROM     wcf".WCF_N."_user_notification
                                ".$conditions;
@@ -817,6 +835,15 @@ class UserNotificationHandler extends SingletonFactory {
                array_unshift($parameters, TIME_NOW);
                $statement->execute($parameters);
                
+               $parameters = [
+                       'event' => $event,
+                       'eventName' => $eventName,
+                       'objectIDs' => $objectIDs,
+                       'objectType' => $objectType,
+                       'recipientIDs' => $recipientIDs,
+               ];
+               EventHandler::getInstance()->fireAction($this, 'markAsConfirmed', $parameters);
+               
                // delete notification_to_user assignments (mimic legacy notification system)
                $sql = "DELETE FROM     wcf".WCF_N."_user_notification_to_user
                        WHERE           notificationID NOT IN (
@@ -840,6 +867,7 @@ class UserNotificationHandler extends SingletonFactory {
         * Marks a single notification id as confirmed.
         * 
         * @param       integer         $notificationID
+        * @deprecated 5.2 Please use `UserNotificationHandler::markAsConfirmedByIDs()` instead.
         */
        public function markAsConfirmedByID($notificationID) {
                $this->markAsConfirmedByIDs([$notificationID]);
@@ -867,6 +895,9 @@ class UserNotificationHandler extends SingletonFactory {
                array_unshift($parameters, TIME_NOW);
                $statement->execute($parameters);
                
+               $parameters = ['notificationIDs' => $notificationIDs];
+               EventHandler::getInstance()->fireAction($this, 'markAsConfirmedByIDs', $parameters);
+               
                // delete notification_to_user assignments (mimic legacy notification system)
                $sql = "DELETE FROM     wcf".WCF_N."_user_notification_to_user
                        ".$conditions;