From 3d78deabdd5c0acadc9d8de90c33f4ed8454ff6a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 16 Jul 2014 22:08:12 +0200 Subject: [PATCH] Added method to remove notifications --- .../UserNotificationHandler.class.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php index 966a374984..a7322d3ccf 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -578,6 +578,45 @@ class UserNotificationHandler extends SingletonFactory { $this->markAsConfirmed($eventName, $objectType, $recipientIDs, $objectIDs); } + /** + * Removes notifications, this method should only be invoked for delete objects. + * + * @param string $objectType + * @param array $objectIDs + */ + public function removeNotifications($objectType, array $objectIDs) { + // check given object type + $objectTypeObj = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.notification.objectType', $objectType); + if ($objectTypeObj === null) { + throw new SystemException("Unknown object type ".$objectType." given"); + } + + // get event ids + $sql = "SELECT eventID + FROM wcf".WCF_N."_user_notification_event + WHERE objectTypeID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $objectTypeObj->objectTypeID + )); + + $eventIDs = array(); + while ($row = $statement->fetchArray()) { + $eventIDs[] = $row['eventID']; + } + + if (!empty($eventIDs)) { + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("eventID IN (?)", array($eventIDs)); + $conditions->add("objectID IN (?)", array($objectIDs)); + + $sql = "DELETE FROM wcf".WCF_N."_user_notification + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + } + } + /** * Marks notifications as confirmed * -- 2.20.1