Add clipboard support for moderation (#4121)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / moderation / queue / ModerationQueueActivationAction.class.php
1 <?php
2
3 namespace wcf\data\moderation\queue;
4
5 use wcf\system\exception\PermissionDeniedException;
6 use wcf\system\exception\UserInputException;
7 use wcf\system\moderation\queue\ModerationQueueActivationManager;
8 use wcf\system\WCF;
9 use wcf\util\StringUtil;
10
11 /**
12 * Executes actions for reports.
13 *
14 * @author Alexander Ebert
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Data\Moderation\Queue
18 */
19 class ModerationQueueActivationAction extends ModerationQueueAction
20 {
21 /**
22 * @inheritDoc
23 */
24 protected $allowGuestAccess = ['enableContent', 'removeContent'];
25
26 /**
27 * moderation queue editor object
28 * @var ModerationQueueEditor
29 */
30 public $queue;
31
32 /**
33 * Validates parameters to enable content.
34 */
35 public function validateEnableContent()
36 {
37 if (empty($this->objects)) {
38 $this->readObjects();
39
40 if (empty($this->objects)) {
41 throw new UserInputException('objectIDs');
42 }
43 }
44
45 foreach ($this->getObjects() as $moderationQueueEditor) {
46 if (!$moderationQueueEditor->canEdit()) {
47 throw new PermissionDeniedException();
48 }
49 }
50 }
51
52 /**
53 * Enables content.
54 */
55 public function enableContent()
56 {
57 WCF::getDB()->beginTransaction();
58 foreach ($this->getObjects() as $moderationQueueEditor) {
59 ModerationQueueActivationManager::getInstance()->enableContent(
60 $moderationQueueEditor->getDecoratedObject()
61 );
62
63 $moderationQueueEditor->markAsConfirmed();
64 }
65 WCF::getDB()->commitTransaction();
66
67 $this->unmarkItems();
68 }
69
70 /**
71 * Validates parameters to delete reported content.
72 */
73 public function validateRemoveContent()
74 {
75 $this->readString('message', true);
76 $this->validateEnableContent();
77 }
78
79 /**
80 * Deletes reported content.
81 */
82 public function removeContent()
83 {
84 // mark content as deleted
85 ModerationQueueActivationManager::getInstance()->removeContent(
86 $this->queue->getDecoratedObject(),
87 $this->parameters['message']
88 );
89
90 $this->queue->markAsRejected();
91
92 $this->unmarkItems();
93 }
94
95 /**
96 * Validates the `removeActivationContent` action.
97 *
98 * @since 5.4
99 */
100 public function validateRemoveActivationContent(): void
101 {
102 if (empty($this->objects)) {
103 $this->readObjects();
104
105 if (empty($this->objects)) {
106 throw new UserInputException('objectIDs');
107 }
108 }
109
110 foreach ($this->getObjects() as $moderationQueueEditor) {
111 if (
112 !$moderationQueueEditor->canEdit()
113 || !ModerationQueueActivationManager::getInstance()->canRemoveContent($moderationQueueEditor->getDecoratedObject())
114 ) {
115 throw new PermissionDeniedException();
116 }
117 }
118
119 $this->parameters['message'] = StringUtil::trim($this->parameters['message'] ?? '');
120 }
121
122 /**
123 * Deletes disabled content via clipboard.
124 *
125 * @since 5.4
126 */
127 public function removeActivationContent(): void
128 {
129 WCF::getDB()->beginTransaction();
130 foreach ($this->getObjects() as $moderationQueueEditor) {
131 ModerationQueueActivationManager::getInstance()->removeContent(
132 $moderationQueueEditor->getDecoratedObject(),
133 $this->parameters['message']
134 );
135
136 $moderationQueueEditor->markAsConfirmed();
137 }
138 WCF::getDB()->commitTransaction();
139
140 $this->unmarkItems();
141 }
142 }