From: Matthias Schmidt Date: Mon, 18 Aug 2014 06:32:20 +0000 (+0200) Subject: Delete orphaned notifications automatically X-Git-Tag: 2.1.0_Alpha_1~435 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=372d24ab1d25bc364b6ca5dc92dc5819a41c3e51;p=GitHub%2FWoltLab%2FWCF.git Delete orphaned notifications automatically --- 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 4510c05833..2fafb9bc36 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -375,12 +375,19 @@ class UserNotificationHandler extends SingletonFactory { // build notification data $notifications = array(); + $deleteNotifications = array(); foreach ($notificationObjects as $notification) { + $object = $objectTypes[$notification->objectType]['objects'][$notification->objectID]; + if ($object->__unknownNotificationObject) { + $deleteNotifications[] = $notification; + continue; + } + $className = $eventObjects[$notification->eventID]->className; $class = new $className($eventObjects[$notification->eventID]); $class->setObject( $notification, - $objectTypes[$notification->objectType]['objects'][$notification->objectID], + $object, (isset($authors[$notification->authorID]) ? $authors[$notification->authorID] : $unknownAuthor), $notification->additionalData ); @@ -414,6 +421,14 @@ class UserNotificationHandler extends SingletonFactory { $notifications[] = $data; } + if (!empty($deleteNotifications)) { + $notificationAction = new UserNotificationAction($deleteNotifications, 'delete'); + $notificationAction->executeAction(); + + // reset notification counter + UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'userNotificationCount'); + } + // check access foreach ($notifications as $index => $notificationData) { if (!$notificationData['event']->checkAccess()) { diff --git a/wcfsetup/install/files/lib/system/user/notification/object/type/AbstractUserNotificationObjectType.class.php b/wcfsetup/install/files/lib/system/user/notification/object/type/AbstractUserNotificationObjectType.class.php index 2d041c0179..3b9a755dd6 100644 --- a/wcfsetup/install/files/lib/system/user/notification/object/type/AbstractUserNotificationObjectType.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/object/type/AbstractUserNotificationObjectType.class.php @@ -47,7 +47,13 @@ class AbstractUserNotificationObjectType extends AbstractObjectTypeProcessor imp foreach ($objectIDs as $objectID) { // append empty objects for unknown ids if (!isset($objects[$objectID])) { - $objects[$objectID] = new static::$decoratorClassName(new static::$objectClassName(null, array($indexName => $objectID))); + // '__unknownNotificationObject' tells the notification API + // that the object does not exist anymore so that the related + // notification can be deleted automatically + $objects[$objectID] = new static::$decoratorClassName(new static::$objectClassName(null, array( + '__unknownNotificationObject' => true, + $indexName => $objectID + ))); } }