/**
  * @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);
 }
Ejemplo n.º 3
0
 /**
  * Adds a comment.
  * 
  * @return	array
  */
 public function addComment()
 {
     if (!empty($this->validationErrors)) {
         if (!empty($this->parameters['data']['username'])) {
             WCF::getSession()->register('username', $this->parameters['data']['username']);
         }
         WCF::getTPL()->assign('errorType', $this->validationErrors);
         $guestDialog = $this->getGuestDialog();
         return array('useCaptcha' => $guestDialog['useCaptcha'], 'guestDialog' => $guestDialog['template']);
     }
     // create comment
     $this->createdComment = CommentEditor::create(array('objectTypeID' => $this->parameters['data']['objectTypeID'], 'objectID' => $this->parameters['data']['objectID'], 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID ?: null, 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->parameters['data']['username'], 'message' => $this->parameters['data']['message'], 'responses' => 0, 'responseIDs' => serialize(array())));
     // update counter
     $this->commentProcessor->updateCounter($this->parameters['data']['objectID'], 1);
     // fire activity event
     $objectType = ObjectTypeCache::getInstance()->getObjectType($this->parameters['data']['objectTypeID']);
     if ($this->createdComment->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.recentActivityEvent')) {
         UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType . '.recentActivityEvent', $this->createdComment->commentID);
     }
     // fire notification event
     if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.notification')) {
         $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType . '.notification');
         $userID = $notificationObjectType->getOwnerID($this->createdComment->commentID);
         if ($userID != WCF::getUser()->userID) {
             $notificationObject = new CommentUserNotificationObject($this->createdComment);
             UserNotificationHandler::getInstance()->fireEvent('comment', $objectType->objectType . '.notification', $notificationObject, array($userID), array('objectUserID' => $userID));
         }
     }
     if (!$this->createdComment->userID) {
         // save user name is session
         WCF::getSession()->register('username', $this->createdComment->username);
         // save last comment time for flood control
         WCF::getSession()->register('lastCommentTime', $this->createdComment->time);
         // reset captcha for future requests
         if ($this->captchaObjectType) {
             $this->captchaObjectType->getProcessor()->reset();
         }
     }
     return array('template' => $this->renderComment($this->createdComment));
 }