// 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
);
$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()) {
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
+ )));
}
}