From 71b3fabad7123da741f3ce4152017dc2232b539a Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 13 Apr 2014 19:59:54 +0200 Subject: [PATCH] Add possibility to report contents again If a moderation queue report entry is marked as done, the reported content can be reported again. --- .../ModerationQueueReportAction.class.php | 4 +- .../ModerationQueueReportManager.class.php | 77 ++++++++++++++++++- wcfsetup/setup/db/install.sql | 4 +- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueReportAction.class.php b/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueReportAction.class.php index 1b3cc570ad..ad887837fb 100644 --- a/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueReportAction.class.php +++ b/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueReportAction.class.php @@ -91,7 +91,7 @@ class ModerationQueueReportAction extends ModerationQueueAction { */ public function prepareReport() { // content was already reported - $alreadyReported = (ModerationQueueReportManager::getInstance()->isAlreadyReported($this->parameters['objectType'], $this->parameters['objectID'])) ? 1 : 0; + $alreadyReported = (ModerationQueueReportManager::getInstance()->hasPendingReport($this->parameters['objectType'], $this->parameters['objectID'])) ? 1 : 0; WCF::getTPL()->assign(array( 'alreadyReported' => $alreadyReported, @@ -119,7 +119,7 @@ class ModerationQueueReportAction extends ModerationQueueAction { public function report() { // if the specified content was already reported, e.g. a different user reported this // item meanwhile, silently ignore it. Just display a success and the user is happy :) - if (!ModerationQueueReportManager::getInstance()->isAlreadyReported($this->parameters['objectType'], $this->parameters['objectID'])) { + if (!ModerationQueueReportManager::getInstance()->hasPendingReport($this->parameters['objectType'], $this->parameters['objectID'])) { ModerationQueueReportManager::getInstance()->addReport( $this->parameters['objectType'], $this->parameters['objectID'], diff --git a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php index 3ca563ed2b..e213adb0d0 100644 --- a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php +++ b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php @@ -1,5 +1,7 @@ prepareStatement($sql); $statement->execute(array( - $objectTypeID, - $objectID + $objectTypeID, + $objectID )); $row = $statement->fetchArray(); return ($row['count'] == 0 ? false : true); } + /** + * Returns true if the object with the given data has a pending report. + * A pending report has a status other than done. + * + * @param string $objectType + * @param integer $objectID + * @return boolean + */ + public function hasPendingReport($objectType, $objectID) { + $objectTypeID = $this->getObjectTypeID($objectType); + + $sql = "SELECT status + FROM wcf".WCF_N."_moderation_queue + WHERE objectTypeID = ? + AND objectID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $objectTypeID, + $objectID + )); + $status = $statement->fetchColumn(); + + return $status !== false && $status != ModerationQueue::STATUS_DONE; + } + /** * Returns true if current user can report given content. * @@ -105,4 +132,50 @@ class ModerationQueueReportManager extends AbstractModerationQueueManager { $additionalData ); } + + /** + * @see \wcf\system\moderation\queue\AbstractModerationQueueManager::addEntry() + */ + protected function addEntry($objectTypeID, $objectID, $containerID = 0, array $additionalData = array()) { + $sql = "SELECT queueID + FROM wcf".WCF_N."_moderation_queue + WHERE objectTypeID = ? + AND objectID = ? + AND status <> ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $objectTypeID, + $objectID, + ModerationQueue::STATUS_DONE + )); + $row = $statement->fetchArray(); + + if ($row === false) { + $objectAction = new ModerationQueueAction(array(), 'create', array( + 'data' => array( + 'objectTypeID' => $objectTypeID, + 'objectID' => $objectID, + 'containerID' => $containerID, + 'userID' => (WCF::getUser()->userID ?: null), + 'time' => TIME_NOW, + 'additionalData' => serialize($additionalData) + ) + )); + $objectAction->executeAction(); + } + else { + $objectAction = new ModerationQueueAction(array($row['queueID']), 'update', array( + 'data' => array( + 'status' => ModerationQueue::STATUS_OUTSTANDING, + 'containerID' => $containerID, + 'userID' => (WCF::getUser()->userID ?: null), + 'time' => TIME_NOW, + 'additionalData' => serialize($additionalData) + ) + )); + $objectAction->executeAction(); + } + + ModerationQueueManager::getInstance()->resetModerationCount(); + } } diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index fe09ea57c4..e1d3822ad9 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -458,9 +458,7 @@ CREATE TABLE wcf1_moderation_queue ( lastChangeTime INT(10) NOT NULL DEFAULT 0, -- additional data, e.g. message if reporting content - additionalData TEXT, - - UNIQUE KEY affectedObject (objectTypeID, objectID) + additionalData TEXT ); DROP TABLE IF EXISTS wcf1_moderation_queue_to_user; -- 2.20.1