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