コード例 #1
0
 /**
  * Removes all comments for given objects.
  * 
  * @param	string		$objectType
  * @param	array<integer>	$objectIDs
  */
 public function deleteObjects($objectType, array $objectIDs)
 {
     $objectTypeID = $this->getObjectTypeID($objectType);
     $objectTypeObj = $this->getObjectType($objectTypeID);
     // get comment ids
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add('comment.objectTypeID = ?', array($objectTypeID));
     $commentList->getConditionBuilder()->add('comment.objectID IN (?)', array($objectIDs));
     $commentList->readObjectIDs();
     $commentIDs = $commentList->getObjectIDs();
     // no comments -> skip
     if (empty($commentIDs)) {
         return;
     }
     // get response ids
     $responseList = new CommentResponseList();
     $responseList->getConditionBuilder()->add('comment_response.commentID IN (?)', array($commentIDs));
     $responseList->readObjectIDs();
     $responseIDs = $responseList->getObjectIDs();
     // delete likes
     $notificationObjectTypes = array();
     if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.like.notification')) {
         $notificationObjectTypes[] = $objectTypeObj->objectType . '.like.notification';
     }
     LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment', $commentIDs, $notificationObjectTypes);
     // delete activity events
     if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.recentActivityEvent')) {
         UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.recentActivityEvent', $commentIDs);
     }
     // delete notifications
     if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.notification')) {
         UserNotificationHandler::getInstance()->removeNotifications($objectTypeObj->objectType . '.notification', $commentIDs);
     }
     if (!empty($responseIDs)) {
         // delete likes (for responses)
         $notificationObjectTypes = array();
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.like.notification')) {
             $notificationObjectTypes[] = $objectTypeObj->objectType . '.response.like.notification';
         }
         LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $responseIDs, $notificationObjectTypes);
         // delete activity events (for responses)
         if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.recentActivityEvent')) {
             UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.response.recentActivityEvent', $responseIDs);
         }
         // delete notifications (for responses)
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.notification')) {
             UserNotificationHandler::getInstance()->removeNotifications($objectTypeObj->objectType . '.response.notification', $responseIDs);
         }
     }
     // delete comments / responses
     CommentEditor::deleteAll($commentIDs);
 }
コード例 #2
0
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::delete()
  */
 public function delete()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     // update counters
     $processors = array();
     $groupCommentIDs = $commentIDs = array();
     foreach ($this->objects as $comment) {
         if (!isset($processors[$comment->objectTypeID])) {
             $objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID);
             $processors[$comment->objectTypeID] = $objectType->getProcessor();
             $groupCommentIDs[$comment->objectTypeID] = array();
         }
         $processors[$comment->objectTypeID]->updateCounter($comment->objectID, -1 * ($comment->responses + 1));
         $groupCommentIDs[$comment->objectTypeID][] = $comment->commentID;
         $commentIDs[] = $comment->commentID;
     }
     if (!empty($groupCommentIDs)) {
         $likeObjectIDs = array();
         $notificationObjectTypes = array();
         foreach ($groupCommentIDs as $objectTypeID => $objectIDs) {
             // remove activity events
             $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
             if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.recentActivityEvent')) {
                 UserActivityEventHandler::getInstance()->removeEvents($objectType->objectType . '.recentActivityEvent', $objectIDs);
             }
             $likeObjectIDs = array_merge($likeObjectIDs, $objectIDs);
             // delete notifications
             $objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID);
             if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.notification')) {
                 UserNotificationHandler::getInstance()->removeNotifications($objectType->objectType . '.notification', $objectIDs);
             }
             if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.like.notification')) {
                 $notificationObjectTypes[] = $objectType->objectType . '.like.notification';
             }
         }
         // remove likes
         LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment', $likeObjectIDs, $notificationObjectTypes);
     }
     // delete responses
     if (!empty($commentIDs)) {
         $commentResponseList = new CommentResponseList();
         $commentResponseList->getConditionBuilder()->add('comment_response.commentID IN (?)', array($commentIDs));
         $commentResponseList->readObjectIDs();
         if (count($commentResponseList->getObjectIDs())) {
             $action = new CommentResponseAction($commentResponseList->getObjectIDs(), 'delete', array('ignoreCounters' => true));
             $action->executeAction();
         }
     }
     return parent::delete();
 }