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