--- /dev/null
+<?php
+namespace wcf\system\cache\runtime;
+use wcf\data\comment\response\CommentResponse;
+use wcf\data\comment\response\CommentResponseList;
+
+/**
+ * Runtime cache implementation for comment responses.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cache.runtime
+ * @category Community Framework
+ * @since 2.2
+ *
+ * @method CommentResponse getObject($objectID)
+ * @method CommentResponse[] getObjects(array $objectIDs)
+ */
+class CommentResponseRuntimeCache extends AbstractRuntimeCache {
+ /**
+ * @inheritDoc
+ */
+ protected $listClassName = CommentResponseList::class;
+}
--- /dev/null
+<?php
+namespace wcf\system\cache\runtime;
+use wcf\data\user\User;
+use wcf\data\user\UserList;
+
+/**
+ * Runtime cache implementation for users.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cache.runtime
+ * @category Community Framework
+ * @since 2.2
+ *
+ * @method User getObject($objectID)
+ * @method User[] getObjects(array $objectIDs)
+ */
+class UserRuntimeCache extends AbstractRuntimeCache {
+ /**
+ * @inheritDoc
+ */
+ protected $listClassName = UserList::class;
+}
use wcf\data\moderation\queue\ModerationQueue;
use wcf\data\moderation\queue\ViewableModerationQueue;
use wcf\data\object\type\ObjectTypeCache;
-use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\cache\runtime\CommentRuntimeCache;
+use wcf\system\comment\manager\ICommentManager;
use wcf\system\moderation\queue\AbstractModerationQueueHandler;
use wcf\system\moderation\queue\ModerationQueueManager;
use wcf\system\WCF;
* An implementation of IModerationQueueReportHandler for comments.
*
* @author Alexander Ebert
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.moderation.queue
*/
class CommentCommentModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
+ * @inheritDoc
*/
- protected $className = 'wcf\data\comment\Comment';
+ protected $className = Comment::class;
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$definitionName
+ * @inheritDoc
*/
protected $definitionName = 'com.woltlab.wcf.moderation.report';
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
+ * @inheritDoc
*/
protected $objectType = 'com.woltlab.wcf.comment.comment';
- /**
- * list of comments
- * @var array<\wcf\data\comment\Comment>
- */
- protected static $comments = array();
-
/**
* list of comment managers
- * @var array<\wcf\system\comment\manager\ICommentManager>
+ * @var ICommentManager[]
*/
- protected static $commentManagers = array();
+ protected static $commentManagers = [];
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
+ * @inheritDoc
*/
public function assignQueues(array $queues) {
- $assignments = array();
+ $assignments = [];
// read comments
- $commentIDs = array();
+ $commentIDs = [];
foreach ($queues as $queue) {
$commentIDs[] = $queue->objectID;
}
- $conditions = new PreparedStatementConditionBuilder();
- $conditions->add("commentID IN (?)", array($commentIDs));
-
- $sql = "SELECT commentID, objectTypeID, objectID
- FROM wcf".WCF_N."_comment
- ".$conditions;
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute($conditions->getParameters());
- $comments = array();
- while ($row = $statement->fetchArray()) {
- $comments[$row['commentID']] = new Comment(null, $row);
- }
+ $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
- $orphanedQueueIDs = array();
+ $orphanedQueueIDs = [];
foreach ($queues as $queue) {
$assignUser = false;
- if (!isset($comments[$queue->objectID])) {
+ if ($comments[$queue->objectID] === null) {
$orphanedQueueIDs[] = $queue->queueID;
continue;
}
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
+ * @inheritDoc
*/
public function canReport($objectID) {
if (!$this->isValid($objectID)) {
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
+ * @inheritDoc
*/
public function getContainerID($objectID) {
return 0;
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
+ * @inheritDoc
*/
public function getReportedContent(ViewableModerationQueue $queue) {
- WCF::getTPL()->assign(array(
+ WCF::getTPL()->assign([
'message' => ViewableComment::getComment($queue->objectID)
- ));
+ ]);
return WCF::getTPL()->fetch('moderationComment');
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
+ * @inheritDoc
*/
public function getReportedObject($objectID) {
return $this->getComment($objectID);
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::isValid()
+ * @inheritDoc
*/
public function isValid($objectID) {
if ($this->getComment($objectID) === null) {
* Returns a comment object by comment id or null if comment id is invalid.
*
* @param integer $objectID
- * @return \wcf\data\comment\Comment
+ * @return Comment|null
*/
protected function getComment($objectID) {
- if (!array_key_exists($objectID, self::$comments)) {
- self::$comments[$objectID] = new Comment($objectID);
- if (!self::$comments[$objectID]->commentID) {
- self::$comments[$objectID] = null;
- }
- }
-
- return self::$comments[$objectID];
+ return CommentRuntimeCache::getInstance()->getObject($objectID);
}
/**
* Returns a comment manager for given comment.
*
- * @param \wcf\data\comment\Comment $comment
- * @return \wcf\system\comment\manager\ICommentManager
+ * @param Comment $comment
+ * @return ICommentManager
*/
protected function getCommentManager(Comment $comment) {
if (!isset(self::$commentManagers[$comment->objectTypeID])) {
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate()
+ * @inheritDoc
*/
public function populate(array $queues) {
- $objectIDs = array();
+ $objectIDs = [];
foreach ($queues as $object) {
$objectIDs[] = $object->objectID;
}
// fetch comments
- $commentList = new CommentList();
- $commentList->setObjectIDs($objectIDs);
- $commentList->readObjects();
- $comments = $commentList->getObjects();
-
+ $comments = CommentRuntimeCache::getInstance()->getObjects($objectIDs);
foreach ($queues as $object) {
- if (isset($comments[$object->objectID])) {
+ if ($comments[$object->objectID] !== null) {
$object->setAffectedObject($comments[$object->objectID]);
}
else {
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
+ * @inheritDoc
*/
public function removeContent(ModerationQueue $queue, $message) {
if ($this->isValid($queue->objectID)) {
- $commentAction = new CommentAction(array($this->getComment($queue->objectID)), 'delete');
+ $commentAction = new CommentAction([$this->getComment($queue->objectID)], 'delete');
$commentAction->executeAction();
}
}
use wcf\data\comment\CommentList;
use wcf\data\moderation\queue\ModerationQueue;
use wcf\data\moderation\queue\ViewableModerationQueue;
+use wcf\system\cache\runtime\CommentResponseRuntimeCache;
+use wcf\system\cache\runtime\CommentRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\moderation\queue\ModerationQueueManager;
use wcf\system\WCF;
* An implementation of IModerationQueueReportHandler for comment responses.
*
* @author Alexander Ebert
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.moderation.queue
*/
class CommentResponseModerationQueueReportHandler extends CommentCommentModerationQueueReportHandler {
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
+ * @inheritDoc
*/
- protected $className = 'wcf\data\comment\response\CommentResponse';
+ protected $className = CommentResponse::class;
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
+ * @inheritDoc
*/
protected $objectType = 'com.woltlab.wcf.comment.response';
/**
- * list of comment responses
- * @var array<\wcf\data\comment\response\CommentResponse>
- */
- protected static $responses = array();
-
- /**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
+ * @inheritDoc
*/
public function assignQueues(array $queues) {
- $assignments = array();
+ $assignments = [];
// read comments and responses
- $responseIDs = array();
+ $responseIDs = [];
foreach ($queues as $queue) {
$responseIDs[] = $queue->objectID;
}
$conditions = new PreparedStatementConditionBuilder();
- $conditions->add("comment_response.responseID IN (?)", array($responseIDs));
+ $conditions->add("comment_response.responseID IN (?)", [$responseIDs]);
$sql = "SELECT comment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID
FROM wcf".WCF_N."_comment_response comment_response
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $comments = $responses = array();
+ $comments = $responses = [];
while ($row = $statement->fetchArray()) {
$comments[$row['commentID']] = new Comment(null, $row);
$responses[$row['responseID']] = new CommentResponse(null, $row);
}
- $orphanedQueueIDs = array();
+ $orphanedQueueIDs = [];
foreach ($queues as $queue) {
$assignUser = false;
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
+ * @inheritDoc
*/
public function canReport($objectID) {
if (!$this->isValid($objectID)) {
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
+ * @inheritDoc
*/
public function getContainerID($objectID) {
return 0;
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
+ * @inheritDoc
*/
public function getReportedContent(ViewableModerationQueue $queue) {
- WCF::getTPL()->assign(array(
+ WCF::getTPL()->assign([
'message' => ViewableCommentResponse::getResponse($queue->objectID)
- ));
+ ]);
return WCF::getTPL()->fetch('moderationComment');
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
+ * @inheritDoc
*/
public function getReportedObject($objectID) {
return $this->getResponse($objectID);
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::isValid()
+ * @inheritDoc
*/
public function isValid($objectID) {
if ($this->getResponse($objectID) === null) {
* Returns a comment response object by response id or null if response id is invalid.
*
* @param integer $objectID
- * @return \wcf\data\comment\response\CommentResponse
+ * @return CommentResponse|null
*/
protected function getResponse($objectID) {
- if (!array_key_exists($objectID, self::$responses)) {
- self::$responses[$objectID] = new CommentResponse($objectID);
- if (!self::$responses[$objectID]->responseID) {
- self::$responses[$objectID] = null;
- }
- }
-
- return self::$responses[$objectID];
+ return CommentResponseRuntimeCache::getInstance()->getObject($objectID);
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate()
+ * @inheritDoc
*/
public function populate(array $queues) {
- $objectIDs = array();
+ $objectIDs = [];
foreach ($queues as $object) {
$objectIDs[] = $object->objectID;
}
- // fetch responses
- $responseList = new CommentResponseList();
- $responseList->setObjectIDs($objectIDs);
- $responseList->readObjects();
- $responses = $responseList->getObjects();
+ $responses = CommentResponseRuntimeCache::getInstance()->getObjects($objectIDs);
- // fetch comments
- $commentIDs = array();
+ $commentIDs = [];
foreach ($responses as $response) {
- $commentIDs[] = $response->commentID;
+ if ($response !== null) {
+ $commentIDs[] = $response->commentID;
+ }
}
if (!empty($commentIDs)) {
- $commentList = new CommentList();
- $commentList->setObjectIDs($commentIDs);
- $commentList->readObjects();
- $comments = $commentList->getObjects();
+ $comments = CommentRuntimeCache::getInstance()->getObjects($commentIDs);
}
foreach ($queues as $object) {
- if (isset($responses[$object->objectID])) {
+ if ($responses[$object->objectID] !== null) {
$response = $responses[$object->objectID];
$response->setComment($comments[$response->commentID]);
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
+ * @inheritDoc
*/
public function removeContent(ModerationQueue $queue, $message) {
if ($this->isValid($queue->objectID)) {
- $responseAction = new CommentResponseAction(array($this->getResponse($queue->objectID)), 'delete');
+ $responseAction = new CommentResponseAction([$this->getResponse($queue->objectID)], 'delete');
$responseAction->executeAction();
}
}
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\user\UserProfile;
+use wcf\system\cache\runtime\UserRuntimeCache;
use wcf\system\exception\SystemException;
use wcf\system\moderation\queue\AbstractModerationQueueHandler;
use wcf\system\moderation\queue\ModerationQueueManager;
* An implementation of IModerationQueueReportHandler for user profiles.
*
* @author Marcel Werk
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.moderation.queue
*/
class UserModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
+ * @inheritDoc
*/
- protected $className = 'wcf\data\user\User';
+ protected $className = User::class;
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$definitionName
+ * @inheritDoc
*/
protected $definitionName = 'com.woltlab.wcf.moderation.report';
/**
- * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
+ * @inheritDoc
*/
protected $objectType = 'com.woltlab.wcf.user';
/**
- * list of users
- * @var array<\wcf\data\user\User>
- */
- protected static $users = array();
-
- /**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
+ * @inheritDoc
*/
public function assignQueues(array $queues) {
- $assignments = array();
+ $assignments = [];
foreach ($queues as $queue) {
$assignUser = false;
if (WCF::getSession()->getPermission('mod.general.canUseModeration')) {
$assignUser = true;
}
-
+
$assignments[$queue->queueID] = $assignUser;
}
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
+ * @inheritDoc
*/
public function canReport($objectID) {
if (!$this->isValid($objectID)) {
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
+ * @inheritDoc
*/
public function getContainerID($objectID) {
return 0;
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
+ * @inheritDoc
*/
public function getReportedContent(ViewableModerationQueue $queue) {
- WCF::getTPL()->assign(array(
+ WCF::getTPL()->assign([
'user' => new UserProfile($queue->getAffectedObject())
- ));
+ ]);
return WCF::getTPL()->fetch('moderationUser');
}
/**
- * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
+ * @inheritDoc
*/
public function getReportedObject($objectID) {
if ($this->isValid($objectID)) {
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::isValid()
+ * @inheritDoc
*/
public function isValid($objectID) {
if ($this->getUser($objectID) === null) {
* Returns a user object by user id or null if user id is invalid.
*
* @param integer $objectID
- * @return \wcf\data\user\User
+ * @return User|null
*/
protected function getUser($objectID) {
- if (!array_key_exists($objectID, self::$users)) {
- self::$users[$objectID] = new User($objectID);
- if (!self::$users[$objectID]->userID) {
- self::$users[$objectID] = null;
- }
- }
-
- return self::$users[$objectID];
+ return UserRuntimeCache::getInstance()->getObject($objectID);
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate()
+ * @inheritDoc
*/
public function populate(array $queues) {
- $objectIDs = array();
+ $objectIDs = [];
foreach ($queues as $object) {
$objectIDs[] = $object->objectID;
}
- // fetch users
- $userList = new UserList();
- $userList->setObjectIDs($objectIDs);
- $userList->readObjects();
- $users = $userList->getObjects();
-
+ $users = UserRuntimeCache::getInstance()->getObjects($objectIDs);
foreach ($queues as $object) {
- if (isset($users[$object->objectID])) {
+ if ($users[$object->objectID] !== null) {
$object->setAffectedObject($users[$object->objectID]);
}
else {
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::canRemoveContent()
+ * @inheritDoc
*/
public function canRemoveContent(ModerationQueue $queue) {
return false;
}
/**
- * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
+ * @inheritDoc
*/
public function removeContent(ModerationQueue $queue, $message) {
throw new SystemException("it's not allowed to delete users using the moderation");