Commit | Line | Data |
---|---|---|
fc69b61d | 1 | <?php |
a9229942 | 2 | |
fc69b61d | 3 | namespace wcf\system\moderation\queue; |
a9229942 TD |
4 | |
5 | use wcf\data\DatabaseObject; | |
b91f1424 | 6 | use wcf\data\moderation\queue\ModerationQueue; |
fc69b61d | 7 | use wcf\data\moderation\queue\ModerationQueueAction; |
9b8e50a6 | 8 | use wcf\system\cache\runtime\UserProfileRuntimeCache; |
fc69b61d | 9 | use wcf\system\database\util\PreparedStatementConditionBuilder; |
79bbb75a | 10 | use wcf\system\exception\InvalidObjectTypeException; |
fc69b61d | 11 | use wcf\system\exception\SystemException; |
ce207cd8 MS |
12 | use wcf\system\moderation\queue\activation\IModerationQueueActivationHandler; |
13 | use wcf\system\moderation\queue\report\IModerationQueueReportHandler; | |
fc69b61d MW |
14 | use wcf\system\WCF; |
15 | ||
16 | /** | |
17 | * Default implementation for moderation queue handlers. | |
a9229942 TD |
18 | * |
19 | * @author Alexander Ebert | |
20 | * @copyright 2001-2019 WoltLab GmbH | |
21 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
fc69b61d | 22 | */ |
a9229942 TD |
23 | abstract class AbstractModerationQueueHandler implements IModerationQueueHandler |
24 | { | |
25 | /** | |
26 | * database object class name | |
27 | * @var string | |
28 | */ | |
29 | protected $className = ''; | |
30 | ||
31 | /** | |
32 | * definition name | |
33 | * @var string | |
34 | */ | |
35 | protected $definitionName = ''; | |
36 | ||
37 | /** | |
38 | * object type | |
39 | * @var string | |
40 | */ | |
41 | protected $objectType = ''; | |
42 | ||
43 | /** | |
44 | * required permission for assigned users | |
45 | * @var string | |
46 | */ | |
47 | protected $requiredPermission = 'mod.general.canUseModeration'; | |
48 | ||
49 | /** | |
50 | * @inheritDoc | |
51 | */ | |
52 | public function identifyOrphans(array $queues) | |
53 | { | |
54 | if ( | |
55 | empty($this->className) | |
56 | || !\class_exists($this->className) | |
57 | || !\is_subclass_of($this->className, DatabaseObject::class) | |
58 | ) { | |
59 | throw new SystemException("DatabaseObject class name '" . $this->className . "' is missing or invalid"); | |
60 | } | |
61 | ||
62 | $indexName = \call_user_func([$this->className, 'getDatabaseTableIndexName']); | |
63 | $tableName = \call_user_func([$this->className, 'getDatabaseTableName']); | |
64 | ||
65 | $conditions = new PreparedStatementConditionBuilder(); | |
66 | $conditions->add($indexName . " IN (?)", [\array_keys($queues)]); | |
67 | ||
68 | $sql = "SELECT " . $indexName . " | |
69 | FROM " . $tableName . " | |
70 | " . $conditions; | |
71 | $statement = WCF::getDB()->prepareStatement($sql); | |
72 | $statement->execute($conditions->getParameters()); | |
73 | while ($row = $statement->fetchArray()) { | |
74 | unset($queues[$row[$indexName]]); | |
75 | } | |
76 | ||
77 | return \array_values($queues); | |
78 | } | |
79 | ||
80 | /** | |
81 | * @inheritDoc | |
82 | */ | |
83 | public function removeQueues(array $objectIDs) | |
84 | { | |
85 | $objectTypeID = ModerationQueueManager::getInstance() | |
86 | ->getObjectTypeID($this->definitionName, $this->objectType); | |
87 | if ($objectTypeID === null) { | |
88 | throw new InvalidObjectTypeException($this->objectType, $this->definitionName); | |
89 | } | |
90 | ||
91 | $conditions = new PreparedStatementConditionBuilder(); | |
92 | $conditions->add("objectTypeID = ?", [$objectTypeID]); | |
93 | $conditions->add("objectID IN (?)", [$objectIDs]); | |
94 | ||
95 | $sql = "SELECT queueID | |
96 | FROM wcf" . WCF_N . "_moderation_queue | |
97 | " . $conditions; | |
98 | $statement = WCF::getDB()->prepareStatement($sql); | |
99 | $statement->execute($conditions->getParameters()); | |
100 | $queueIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); | |
101 | ||
102 | if (!empty($queueIDs)) { | |
103 | $queueAction = new ModerationQueueAction($queueIDs, 'delete'); | |
104 | $queueAction->executeAction(); | |
105 | } | |
106 | } | |
107 | ||
108 | /** | |
109 | * @inheritDoc | |
110 | */ | |
111 | public function canRemoveContent(ModerationQueue $queue) | |
112 | { | |
113 | return true; | |
114 | } | |
115 | ||
116 | /** | |
117 | * @inheritDoc | |
118 | */ | |
119 | public function isAffectedUser(ModerationQueue $queue, $userID) | |
120 | { | |
9b8e50a6 | 121 | $userProfile = UserProfileRuntimeCache::getInstance()->getObject($userID); |
a9229942 | 122 | |
9b8e50a6 | 123 | return $userProfile->getPermission($this->requiredPermission); |
a9229942 TD |
124 | } |
125 | ||
126 | /** | |
127 | * @inheritDoc | |
128 | * @since 3.0 | |
129 | */ | |
130 | public function getCommentNotificationLanguageItemPrefix() | |
131 | { | |
132 | // this implementation exists to provide backwards compatibility; | |
133 | // as there are no abstract implementations of the two interfaces, | |
134 | // this is the best approach | |
135 | if ($this instanceof IModerationQueueActivationHandler) { | |
136 | return 'wcf.moderation.activation.notification'; | |
137 | } elseif ($this instanceof IModerationQueueReportHandler) { | |
138 | return 'wcf.moderation.report.notification'; | |
139 | } | |
140 | ||
141 | return 'wcf.moderation.notification'; | |
142 | } | |
30394f98 MW |
143 | |
144 | /** | |
145 | * @inheritDoc | |
146 | */ | |
147 | public function getCommentNotificationTypeNameLanguageItem(): string | |
148 | { | |
149 | if ($this instanceof IModerationQueueActivationHandler) { | |
150 | return 'wcf.moderation.activation'; | |
151 | } elseif ($this instanceof IModerationQueueReportHandler) { | |
152 | return 'wcf.moderation.report'; | |
153 | } | |
154 | ||
155 | return 'wcf.moderation.moderation'; | |
156 | } | |
fc69b61d | 157 | } |