2 namespace wcf\system\moderation\queue;
3 use wcf\data\comment\response\CommentResponse;
4 use wcf\data\comment\response\CommentResponseAction;
5 use wcf\data\comment\response\ViewableCommentResponse;
6 use wcf\data\comment\Comment;
7 use wcf\data\moderation\queue\ModerationQueue;
8 use wcf\data\moderation\queue\ViewableModerationQueue;
9 use wcf\system\cache\runtime\CommentResponseRuntimeCache;
10 use wcf\system\cache\runtime\CommentRuntimeCache;
11 use wcf\system\database\util\PreparedStatementConditionBuilder;
15 * An implementation of IModerationQueueHandler for comment responses.
17 * @author Alexander Ebert
18 * @copyright 2001-2018 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\System\Moderation\Queue
22 class AbstractCommentResponseModerationQueueHandler extends AbstractCommentCommentModerationQueueHandler {
26 protected $className = CommentResponse::class;
31 protected $objectType = 'com.woltlab.wcf.comment.response';
36 public function assignQueues(array $queues) {
39 // read comments and responses
41 foreach ($queues as $queue) {
42 $responseIDs[] = $queue->objectID;
45 $conditions = new PreparedStatementConditionBuilder();
46 $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
48 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
49 FROM wcf".WCF_N."_comment_response comment_response
50 LEFT JOIN wcf".WCF_N."_comment comment
51 ON (comment.commentID = comment_response.commentID)
53 $statement = WCF::getDB()->prepareStatement($sql);
54 $statement->execute($conditions->getParameters());
55 $comments = $responses = [];
56 while ($row = $statement->fetchArray()) {
57 $comments[$row['commentID']] = new Comment(null, $row);
58 $responses[$row['responseID']] = new CommentResponse(null, $row);
61 $orphanedQueueIDs = [];
62 foreach ($queues as $queue) {
65 if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
66 $orphanedQueueIDs[] = $queue->queueID;
70 $comment = $comments[$responses[$queue->objectID]->commentID];
71 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
75 $assignments[$queue->queueID] = $assignUser;
78 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
79 ModerationQueueManager::getInstance()->setAssignment($assignments);
85 public function getRelatedContent(ViewableModerationQueue $queue) {
86 WCF::getTPL()->assign([
87 'message' => ViewableCommentResponse::getResponse($queue->objectID)
90 return WCF::getTPL()->fetch('moderationComment');
96 public function isValid($objectID) {
97 if ($this->getResponse($objectID) === null) {
105 * Returns a comment response object by response id or null if response id is invalid.
107 * @param integer $objectID
108 * @return CommentResponse|null
110 protected function getResponse($objectID) {
111 return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
117 public function populate(array $queues) {
119 foreach ($queues as $object) {
120 $objectIDs[] = $object->objectID;
123 $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
126 foreach ($responses as $response) {
127 if ($response !== null) {
128 $commentIDs[] = $response->commentID;
133 if (!empty($commentIDs)) {
134 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
137 foreach ($queues as $object) {
138 if ($responses[$object->objectID] !== null) {
139 $response = $responses[$object->objectID];
140 $response->setComment($comments[$response->commentID]);
142 $object->setAffectedObject($response);
145 $object->setIsOrphaned();
153 public function removeContent(ModerationQueue $queue, $message) {
154 if ($this->isValid($queue->objectID)) {
155 $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
156 $responseAction->executeAction();