'queues' => $queueList
));
+ // check if user storage is outdated
$totalCount = ModerationQueueManager::getInstance()->getOutstandingModerationCount();
if (count($queueList) < $totalCount) {
UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'outstandingModerationCount');
+
+ // check for orphaned queues
+ $queueCount = ModerationQueueManager::getInstance()->getOutstandingModerationCount();
+ if (count($queueList) < $queueCount) {
+ ModerationQueueManager::getInstance()->identifyOrphans();
+ }
}
return array(
<?php
namespace wcf\system\moderation\queue;
use wcf\data\moderation\queue\ModerationQueueAction;
+use wcf\data\DatabaseObject;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\SystemException;
use wcf\system\WCF;
* @category Community Framework
*/
abstract class AbstractModerationQueueHandler implements IModerationQueueHandler {
+ /**
+ * database object class name
+ * @var string
+ */
+ protected $className = '';
+
/**
* definition name
* @var string
*/
protected $objectType = '';
+ /**
+ * @see wcf\system\moderation\queue\IModerationQueueHandler::identifyOrphans()
+ */
+ public function identifyOrphans(array $queues) {
+ if (empty($this->className) || !class_exists($this->className) || !($this->className instanceof DatabaseObject)) {
+ throw new SystemException("DatabaseObject class name '" . $this->className . "' is missing or invalid");
+ }
+
+ $indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName'));
+ $tableName = call_user_func(array($this->className, 'getDatabaseTableName'));
+
+ $conditions = new PreparedStatementConditionBuilder();
+ $conditions->add($indexName . " IN (?)", array(array_keys($queues)));
+
+ $sql = "SELECT " . $indexName . "
+ FROM " . $tableName . "
+ ".$conditions;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditions->getParameters());
+ while ($row = $statement->fetchArray()) {
+ unset($queues[$row[$indexName]]);
+ }
+
+ return array_values($queues);
+ }
+
/**
* @see wcf\system\moderation\queue\IModerationQueueHandler::removeQueues()
*/
*/
public function getContainerID($objectID);
+ /**
+ * Validates object ids and returns orphaned queue ids.
+ *
+ * @param array<integer> $queues
+ * @return array<integer>
+ */
+ public function identifyOrphans(array $queues);
+
/**
* Returns true if given object id is valid.
*
WCF::getDB()->commitTransaction();
}
+ /**
+ * Identifies and removes orphaned queues.
+ */
+ public function identifyOrphans() {
+ $sql = "SELECT moderation_queue.queueID, moderation_queue.objectTypeID, moderation_queue.objectID
+ FROM wcf".WCF_N."_moderation_queue_to_user moderation_queue_to_user
+ LEFT JOIN wcf".WCF_N."_moderation_queue moderation_queue
+ ON (moderation_queue.queueID = moderation_queue_to_user.queueID)
+ WHERE moderation_queue_to_user.userID = ?
+ AND moderation_queue_to_user.isAffected = ?
+ AND moderation_queue.status <> ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array(
+ WCF::getUser()->userID,
+ 1,
+ ModerationQueue::STATUS_DONE
+ ));
+
+ $queues = array();
+ while ($row = $statement->fetchArray()) {
+ $objectTypeID = $row['objectTypeID'];
+ if (!isset($queues[$objectTypeID])) {
+ $queues[$objectTypeID] = array();
+ }
+
+ $queues[$objectTypeID][$row['queueID']] = $row['objectID'];
+ }
+
+ if (!empty($queues)) {
+ $queueIDs = array();
+ foreach ($queues as $objectTypeID => $objectQueues) {
+ $queueID = array_merge($queueIDs, $this->getProcessor($this->definitions[$this->objectTypes[$objectTypeID]->definitionID], null, $objectTypeID)->identifyOrphans());
+ }
+
+ $this->removeOrphans($queueIDs);
+ }
+ }
+
/**
* Removes a list of orphaned queue ids.
*
* @category Community Framework
*/
class CommentCommentModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
+ /**
+ * @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
+ */
+ protected $className = 'wcf\data\comment\Comment';
+
/**
* @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$definitionName
*/
* @category Community Framework
*/
class CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
+ /**
+ * @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
+ */
+ protected $className = 'wcf\data\comment\response\CommentResponse';
+
/**
* @see wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
*/