Commit | Line | Data |
---|---|---|
fc69b61d MW |
1 | <?php |
2 | namespace wcf\system\moderation\queue; | |
b91f1424 | 3 | use wcf\data\moderation\queue\ModerationQueue; |
fc69b61d MW |
4 | use wcf\data\moderation\queue\ModerationQueueAction; |
5 | use wcf\system\database\util\PreparedStatementConditionBuilder; | |
6 | use wcf\system\exception\SystemException; | |
7 | use wcf\system\WCF; | |
c4347b56 | 8 | use wcf\util\ClassUtil; |
fc69b61d MW |
9 | |
10 | /** | |
11 | * Default implementation for moderation queue handlers. | |
12 | * | |
13 | * @author Alexander Ebert | |
ca4ba303 | 14 | * @copyright 2001-2014 WoltLab GmbH |
fc69b61d | 15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
f4f05aa5 | 16 | * @package com.woltlab.wcf |
fc69b61d MW |
17 | * @subpackage system.moderation.queue |
18 | * @category Community Framework | |
19 | */ | |
20 | abstract class AbstractModerationQueueHandler implements IModerationQueueHandler { | |
9bf4ce63 AE |
21 | /** |
22 | * database object class name | |
23 | * @var string | |
24 | */ | |
25 | protected $className = ''; | |
26 | ||
fc69b61d MW |
27 | /** |
28 | * definition name | |
29 | * @var string | |
30 | */ | |
31 | protected $definitionName = ''; | |
32 | ||
33 | /** | |
34 | * object type | |
35 | * @var string | |
36 | */ | |
37 | protected $objectType = ''; | |
38 | ||
39 | /** | |
0ad90fc3 | 40 | * @see \wcf\system\moderation\queue\IModerationQueueHandler::identifyOrphans() |
9bf4ce63 AE |
41 | */ |
42 | public function identifyOrphans(array $queues) { | |
c4347b56 | 43 | if (empty($this->className) || !class_exists($this->className) || !ClassUtil::isInstanceOf($this->className, 'wcf\data\DatabaseObject')) { |
9bf4ce63 AE |
44 | throw new SystemException("DatabaseObject class name '" . $this->className . "' is missing or invalid"); |
45 | } | |
46 | ||
47 | $indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName')); | |
48 | $tableName = call_user_func(array($this->className, 'getDatabaseTableName')); | |
49 | ||
50 | $conditions = new PreparedStatementConditionBuilder(); | |
51 | $conditions->add($indexName . " IN (?)", array(array_keys($queues))); | |
52 | ||
53 | $sql = "SELECT " . $indexName . " | |
54 | FROM " . $tableName . " | |
55 | ".$conditions; | |
56 | $statement = WCF::getDB()->prepareStatement($sql); | |
57 | $statement->execute($conditions->getParameters()); | |
58 | while ($row = $statement->fetchArray()) { | |
59 | unset($queues[$row[$indexName]]); | |
60 | } | |
61 | ||
62 | return array_values($queues); | |
63 | } | |
64 | ||
65 | /** | |
0ad90fc3 | 66 | * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeQueues() |
fc69b61d MW |
67 | */ |
68 | public function removeQueues(array $objectIDs) { | |
69 | $objectTypeID = ModerationQueueManager::getInstance()->getObjectTypeID($this->definitionName, $this->objectType); | |
70 | if ($objectTypeID === null) { | |
71 | throw new SystemException("Object type '".$this->objectType."' is not valid for definition '".$this->definitionName."'"); | |
72 | } | |
73 | ||
74 | $conditions = new PreparedStatementConditionBuilder(); | |
75 | $conditions->add("objectTypeID = ?", array($objectTypeID)); | |
76 | $conditions->add("objectID IN (?)", array($objectIDs)); | |
77 | ||
78 | $sql = "SELECT queueID | |
79 | FROM wcf".WCF_N."_moderation_queue | |
80 | ".$conditions; | |
81 | $statement = WCF::getDB()->prepareStatement($sql); | |
82 | $statement->execute($conditions->getParameters()); | |
83 | $queueIDs = array(); | |
84 | while ($row = $statement->fetchArray()) { | |
85 | $queueIDs[] = $row['queueID']; | |
86 | } | |
87 | ||
88 | if (!empty($queueIDs)) { | |
89 | $queueAction = new ModerationQueueAction($queueIDs, 'delete'); | |
90 | $queueAction->executeAction(); | |
91 | } | |
92 | } | |
b91f1424 TD |
93 | |
94 | /** | |
95 | * @see \wcf\system\moderation\queue\IModerationQueueHandler::canRemoveContent() | |
96 | */ | |
97 | public function canRemoveContent(ModerationQueue $queue) { | |
98 | return true; | |
99 | } | |
fc69b61d | 100 | } |