cb6c267df00e905cc2f41e04faf9665bc7aca516
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\moderation\queue\report;
3 use wcf\data\article\ArticleAction;
4 use wcf\data\article\ViewableArticle;
5 use wcf\data\moderation\queue\ModerationQueue;
6 use wcf\data\moderation\queue\ViewableModerationQueue;
7 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
8 use wcf\system\moderation\queue\AbstractModerationQueueHandler;
9 use wcf\system\moderation\queue\ModerationQueueManager;
10 use wcf\system\WCF;
11
12 /**
13 * An implementation of IModerationQueueReportHandler for articles.
14 *
15 * @author Joshua Ruesweg
16 * @copyright 2001-2018 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Suite\System\Moderation\Queue\Report
19 * @since 3.2
20 */
21 class ArticleModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
22 /**
23 * @inheritDoc
24 */
25 protected $definitionName = 'com.woltlab.wcf.moderation.report';
26
27 /**
28 * @inheritDoc
29 */
30 protected $objectType = 'com.woltlab.wcf.article';
31
32 /**
33 * @inheritDoc
34 */
35 public function canReport($objectID) {
36 if (!$this->isValid($objectID)) {
37 return false;
38 }
39
40 if (!$this->getReportedObject($objectID)->canRead()) {
41 return false;
42 }
43
44 return true;
45 }
46
47 /**
48 * @inheritDoc
49 */
50 public function getReportedContent(ViewableModerationQueue $queue) {
51 WCF::getTPL()->assign([
52 'article' => $this->getArticle($queue->getAffectedObject()->articleID),
53 ]);
54
55 return WCF::getTPL()->fetch('moderationArticle');
56 }
57
58 /**
59 * @inheritDoc
60 *
61 * @return ViewableArticle|null
62 */
63 public function getReportedObject($objectID) {
64 if ($this->isValid($objectID)) {
65 return $this->getArticle($objectID);
66 }
67
68 return null;
69 }
70
71 /**
72 * @param $articleID
73 * @return ViewableArticle|null
74 */
75 public function getArticle($articleID) {
76 return ViewableArticleRuntimeCache::getInstance()->getObject($articleID);
77 }
78
79 /**
80 * @inheritDoc
81 */
82 public function assignQueues(array $queues) {
83 $assignments = $orphanedQueueIDs = [];
84
85 // first cache all articles
86 foreach ($queues as $queue) {
87 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($queue->objectID);
88 }
89
90 // now process articles
91 foreach ($queues as $queue) {
92 $article = ViewableArticleRuntimeCache::getInstance()->getObject($queue->objectID);
93
94 if ($article === null) {
95 $orphanedQueueIDs[] = $queue->queueID;
96 }
97 else {
98 if ($article->canDelete()) {
99 $assignments[$queue->queueID] = true;
100 }
101 else {
102 $assignments[$queue->queueID] = false;
103 }
104 }
105 }
106
107 ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
108 ModerationQueueManager::getInstance()->setAssignment($assignments);
109 }
110
111 /**
112 * @inheritDoc
113 */
114 public function getContainerID($objectID) {
115 if ($this->isValid($objectID)) {
116 return $this->getArticle($objectID)->getCategory()->categoryID;
117 }
118
119 return 0;
120 }
121
122 /**
123 * @inheritDoc
124 */
125 public function isValid($objectID) {
126 if ($this->getArticle($objectID) === null) {
127 return false;
128 }
129
130 return true;
131 }
132
133 /**
134 * @inheritDoc
135 */
136 public function populate(array $queues) {
137 // first cache all articles
138 foreach ($queues as $queue) {
139 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($queue->objectID);
140 }
141
142 foreach ($queues as $object) {
143 $article = ViewableArticleRuntimeCache::getInstance()->getObject($object->objectID);
144 if ($article !== null) {
145 $object->setAffectedObject($article->getDecoratedObject());
146 }
147 else {
148 $object->setIsOrphaned();
149 }
150 }
151 }
152
153 /**
154 * @inheritDoc
155 */
156 public function canRemoveContent(ModerationQueue $queue) {
157 if ($this->isValid($queue->objectID)) {
158 return $this->getArticle($queue->objectID)->canDelete();
159 }
160
161 return false;
162 }
163
164 /**
165 * @inheritDoc
166 */
167 public function removeContent(ModerationQueue $queue, $message) {
168 if ($this->isValid($queue->objectID)) {
169 (new ArticleAction([$this->getArticle($queue->objectID)->getDecoratedObject()], 'trash'))->executeAction();
170 }
171 }
172 }