2 declare(strict_types=1);
3 namespace wcf\system\moderation\queue;
4 use wcf\data\comment\response\CommentResponse;
5 use wcf\data\comment\response\CommentResponseAction;
6 use wcf\data\comment\response\ViewableCommentResponse;
7 use wcf\data\comment\Comment;
8 use wcf\data\moderation\queue\ModerationQueue;
9 use wcf\data\moderation\queue\ViewableModerationQueue;
10 use wcf\system\cache\runtime\CommentResponseRuntimeCache;
11 use wcf\system\cache\runtime\CommentRuntimeCache;
12 use wcf\system\database\util\PreparedStatementConditionBuilder;
16 * An implementation of IModerationQueueHandler for comment responses.
18 * @author Alexander Ebert
19 * @copyright 2001-2018 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package WoltLabSuite\Core\System\Moderation\Queue
23 class AbstractCommentResponseModerationQueueHandler extends AbstractCommentCommentModerationQueueHandler {
27 protected $className = CommentResponse::class;
32 protected $objectType = 'com.woltlab.wcf.comment.response';
37 public function assignQueues(array $queues) {
40 // read comments and responses
42 foreach ($queues as $queue) {
43 $responseIDs[] = $queue->objectID;
46 $conditions = new PreparedStatementConditionBuilder();
47 $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
49 $sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
50 FROM wcf".WCF_N."_comment_response comment_response
51 LEFT JOIN wcf".WCF_N."_comment comment
52 ON (comment.commentID = comment_response.commentID)
54 $statement = WCF::getDB()->prepareStatement($sql);
55 $statement->execute($conditions->getParameters());
56 $comments = $responses = [];
57 while ($row = $statement->fetchArray()) {
58 $comments[$row['commentID']] = new Comment(null, $row);
59 $responses[$row['responseID']] = new CommentResponse(null, $row);
62 $orphanedQueueIDs = [];
63 foreach ($queues as $queue) {
66 if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
67 $orphanedQueueIDs[] = $queue->queueID;
71 $comment = $comments[$responses[$queue->objectID]->commentID];
72 if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
76 $assignments[$queue->queueID] = $assignUser;
79 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
80 ModerationQueueManager::getInstance()->setAssignment($assignments);
86 public function getRelatedContent(ViewableModerationQueue $queue) {
87 WCF::getTPL()->assign([
88 'message' => ViewableCommentResponse::getResponse($queue->objectID)
91 return WCF::getTPL()->fetch('moderationComment');
97 public function isValid($objectID) {
98 if ($this->getResponse($objectID) === null) {
106 * Returns a comment response object by response id or null if response id is invalid.
108 * @param integer $objectID
109 * @return CommentResponse|null
111 protected function getResponse($objectID) {
112 return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
118 public function populate(array $queues) {
120 foreach ($queues as $object) {
121 $objectIDs[] = $object->objectID;
124 $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
127 foreach ($responses as $response) {
128 if ($response !== null) {
129 $commentIDs[] = $response->commentID;
134 if (!empty($commentIDs)) {
135 $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
138 foreach ($queues as $object) {
139 if ($responses[$object->objectID] !== null) {
140 $response = $responses[$object->objectID];
141 $response->setComment($comments[$response->commentID]);
143 $object->setAffectedObject($response);
146 $object->setIsOrphaned();
154 public function removeContent(ModerationQueue $queue, $message) {
155 if ($this->isValid($queue->objectID)) {
156 $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
157 $responseAction->executeAction();