From: Alexander Ebert Date: Wed, 16 Jul 2014 20:08:12 +0000 (+0200) Subject: Added method to remove notifications X-Git-Tag: 2.1.0_Alpha_1~558^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3d78deabdd5c0acadc9d8de90c33f4ed8454ff6a;p=GitHub%2FWoltLab%2FWCF.git Added method to remove notifications --- 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 *