/**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
     $comment = CommentEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
     ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $comment->commentID);
     return $comment->commentID;
 }
 /**
  * @see	\wcf\system\faker\IFaker::fake()
  */
 public function fake()
 {
     $objectID = $this->getObjectID();
     $creationTime = $this->getCreationTime();
     $sql = "SELECT\t\tuserID, username, registrationDate\n\t\t\tFROM\t\twcf" . WCF_N . "_user\n\t\t\tORDER BY\tuserID ASC";
     $statement = \wcf\system\WCF::getDB()->prepareStatement($sql, 1, $this->generator->numberBetween(0, $this->userCount - 1));
     $statement->execute();
     $sender = $statement->fetchObject('\\wcf\\data\\user\\User');
     // create comment
     $comment = \wcf\data\comment\CommentEditor::create(array('objectTypeID' => $this->objectTypeID, 'objectID' => $objectID, 'time' => $this->generator->numberBetween(max($sender->registrationDate, $creationTime), TIME_NOW), 'userID' => $sender->userID, 'username' => $sender->username, 'message' => $this->generator->realText($this->generator->numberBetween(10, 5000)), 'responses' => 0, 'responseIDs' => serialize(array())));
     // update counter
     $this->objectType->getProcessor()->updateCounter($this->objectTypeID, 1);
 }
 /**
  * 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);
 }
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::delete()
  */
 public function delete()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     if (empty($this->objects)) {
         return 0;
     }
     $ignoreCounters = !empty($this->parameters['ignoreCounters']);
     // read object type ids for comments
     $commentIDs = array();
     foreach ($this->objects as $response) {
         $commentIDs[] = $response->commentID;
     }
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     // update counters
     $processors = $responseIDs = $updateComments = array();
     foreach ($this->objects as $response) {
         $objectTypeID = $comments[$response->commentID]->objectTypeID;
         if (!isset($processors[$objectTypeID])) {
             $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
             $processors[$objectTypeID] = $objectType->getProcessor();
             $responseIDs[$objectTypeID] = array();
         }
         $responseIDs[$objectTypeID][] = $response->responseID;
         if (!$ignoreCounters) {
             $processors[$objectTypeID]->updateCounter($comments[$response->commentID]->objectID, -1);
             if (!isset($updateComments[$response->commentID])) {
                 $updateComments[$response->commentID] = 0;
             }
             $updateComments[$response->commentID]++;
         }
     }
     // remove responses
     $count = parent::delete();
     // update comment responses and cached response ids
     if (!$ignoreCounters) {
         foreach ($comments as $comment) {
             $commentEditor = new CommentEditor($comment);
             $commentEditor->updateResponseIDs();
             $commentEditor->updateCounters(array('responses' => -1 * $updateComments[$comment->commentID]));
         }
     }
     $likeObjectIDs = array();
     $notificationObjectTypes = array();
     foreach ($responseIDs as $objectTypeID => $objectIDs) {
         // remove activity events
         $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
         if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent')) {
             UserActivityEventHandler::getInstance()->removeEvents($objectType->objectType . '.response.recentActivityEvent', $objectIDs);
         }
         // delete notifications
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.notification')) {
             UserNotificationHandler::getInstance()->removeNotifications($objectType->objectType . '.response.notification', $objectIDs);
         }
         $likeObjectIDs = array_merge($likeObjectIDs, $objectIDs);
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.like.notification')) {
             $notificationObjectTypes[] = $objectType->objectType . '.response.like.notification';
         }
     }
     // remove likes
     if (!empty($likeObjectIDs)) {
         LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $likeObjectIDs, $notificationObjectTypes);
     }
     return $count;
 }
 /**
  * Edits a comment or response.
  * 
  * @return	array
  */
 public function edit()
 {
     $returnValues = array('action' => 'saved');
     if ($this->response === null) {
         $editor = new CommentEditor($this->comment);
         $editor->update(array('message' => $this->parameters['data']['message']));
         $comment = new Comment($this->comment->commentID);
         $returnValues['commentID'] = $this->comment->commentID;
         $returnValues['message'] = $comment->getFormattedMessage();
     } else {
         $editor = new CommentResponseEditor($this->response);
         $editor->update(array('message' => $this->parameters['data']['message']));
         $response = new CommentResponse($this->response->responseID);
         $returnValues['responseID'] = $this->response->responseID;
         $returnValues['message'] = $response->getFormattedMessage();
     }
     return $returnValues;
 }