Add InvalidObjectTypeException
authorMatthias Schmidt <gravatronics@live.com>
Fri, 2 Sep 2016 16:40:26 +0000 (18:40 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 2 Sep 2016 16:40:30 +0000 (18:40 +0200)
wcfsetup/install/files/lib/acp/page/AbstractCategoryListPage.class.php
wcfsetup/install/files/lib/system/exception/InvalidObjectTypeException.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/AbstractHtmlProcessor.class.php
wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php
wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php
wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueActivationManager.class.php
wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php
wcfsetup/install/files/lib/system/tagging/TagEngine.class.php
wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php
wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php

index 9950882d85d3e6ae97da70363b90f67eea4a30f9..07ed5c3080f546ce5e69a6b14da10209cc599905 100644 (file)
@@ -4,8 +4,8 @@ use wcf\data\category\CategoryNodeTree;
 use wcf\data\object\type\ObjectType;
 use wcf\page\AbstractPage;
 use wcf\system\category\CategoryHandler;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\exception\PermissionDeniedException;
-use wcf\system\exception\SystemException;
 use wcf\system\user\collapsible\content\UserCollapsibleContentHandler;
 use wcf\system\WCF;
 
@@ -132,7 +132,7 @@ abstract class AbstractCategoryListPage extends AbstractPage {
        public function readData() {
                $this->objectType = CategoryHandler::getInstance()->getObjectTypeByName($this->objectTypeName);
                if ($this->objectType === null) {
-                       throw new SystemException("Unknown category object type with name '".$this->objectTypeName."'");
+                       throw new InvalidObjectTypeException($this->objectTypeName, 'com.woltlab.wcf.category');
                }
                
                // check permissions
diff --git a/wcfsetup/install/files/lib/system/exception/InvalidObjectTypeException.class.php b/wcfsetup/install/files/lib/system/exception/InvalidObjectTypeException.class.php
new file mode 100644 (file)
index 0000000..e48c009
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace wcf\system\exception;
+
+/**
+ * Exception implementation for cases when an object type of a certain object type
+ * definition is expected but the object type is of a different object type definition.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Exception
+ * @since      3.0
+ */
+class InvalidObjectTypeException extends \UnexpectedValueException {
+       /**
+        * InvalidObjectTypeException constructor.
+        * 
+        * @param       string          $objectType             invalid object type name
+        * @param       string          $definitionName         name of the required object type definition
+        */
+       public function __construct($objectType, $definitionName) {
+               parent::__construct("Invalid object type '{$objectType}' for definition '{$definitionName}'.");
+       }
+}
\ No newline at end of file
index acb0cc09aa746744522e0c99327dfc1cdd5eab6d..561ff912b33e4bcc647001db1072dae1b43c8ea1 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace wcf\system\html;
 use wcf\data\object\type\ObjectTypeCache;
-use wcf\system\exception\SystemException;
+use wcf\system\exception\InvalidObjectTypeException;
 
 /**
  * Default implementation for html processors.
@@ -28,12 +28,12 @@ abstract class AbstractHtmlProcessor implements IHtmlProcessor {
         * 
         * @param       string          $objectType     object type identifier
         * @param       integer         $objectID       object id
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function setContext($objectType, $objectID) {
                $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $objectType);
                if ($objectTypeID === null) {
-                       throw new SystemException("Invalid object type '" . $objectType . "' for definition 'com.woltlab.wcf.message'.");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.message');
                }
                
                $this->context = [
index c00c57bb7e9dd0fc11123f153f85ce86c19f3730..c378588cb753e3ea818991d84a8ed17d085cb009 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\system\message\embedded\object;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\bbcode\BBCodeParser;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
@@ -147,13 +148,14 @@ class MessageEmbeddedObjectManager extends SingletonFactory {
        /**
         * Loads the embedded objects for given messages.
         * 
-        * @param       string                  $messageObjectType
-        * @param       integer[]               $messageIDs
+        * @param       string          $messageObjectType
+        * @param       integer[]       $messageIDs
+        * @throws      InvalidObjectTypeException
         */
        public function loadObjects($messageObjectType, array $messageIDs) {
                $messageObjectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $messageObjectType);
                if ($messageObjectTypeID === null) {
-                       throw new \UnexpectedValueException("Expected a valid object type for definition 'com.woltlab.wcf.message'.");
+                       throw new InvalidObjectTypeException($messageObjectType, 'com.woltlab.wcf.message');
                }
                
                $conditionBuilder = new PreparedStatementConditionBuilder();
index 65706ee8edc46c6515994598a64b008a3d61e2a1..c1d619ec51571084d56748511990bce9caff058c 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\user\User;
 use wcf\data\user\UserProfile;
 use wcf\data\DatabaseObject;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\exception\SystemException;
 use wcf\system\moderation\queue\activation\IModerationQueueActivationHandler;
 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
@@ -76,7 +77,7 @@ abstract class AbstractModerationQueueHandler implements IModerationQueueHandler
        public function removeQueues(array $objectIDs) {
                $objectTypeID = ModerationQueueManager::getInstance()->getObjectTypeID($this->definitionName, $this->objectType);
                if ($objectTypeID === null) {
-                       throw new SystemException("Object type '".$this->objectType."' is not valid for definition '".$this->definitionName."'");
+                       throw new InvalidObjectTypeException($this->objectType, $this->definitionName);
                }
                
                $conditions = new PreparedStatementConditionBuilder();
index d284cb5cd7c280c9c315a942126b8ab81ed0d1ab..499e95fb951ddf933bbca2ceb27cb7f2971e626b 100644 (file)
@@ -2,7 +2,7 @@
 namespace wcf\system\moderation\queue;
 use wcf\data\moderation\queue\ModerationQueue;
 use wcf\data\moderation\queue\ViewableModerationQueue;
-use wcf\system\exception\SystemException;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\request\LinkHandler;
 
 /**
@@ -51,11 +51,11 @@ class ModerationQueueActivationManager extends AbstractModerationQueueManager {
         * @param       string          $objectType
         * @param       integer         $objectID
         * @param       array           $additionalData
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function addModeratedContent($objectType, $objectID, array $additionalData = []) {
                if (!$this->isValid($objectType)) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for definition 'com.woltlab.wcf.moderation.activation'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.moderation.activation');
                }
                
                $this->addEntry(
@@ -71,11 +71,11 @@ class ModerationQueueActivationManager extends AbstractModerationQueueManager {
         * 
         * @param       string          $objectType
         * @param       integer[]       $objectIDs
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function removeModeratedContent($objectType, array $objectIDs) {
                if (!$this->isValid($objectType)) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for definition 'com.woltlab.wcf.moderation.activation'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.moderation.activation');
                }
                
                $this->removeEntries($this->getObjectTypeID($objectType), $objectIDs);
index b0a54aee6ca4c69f4d949b24b56c8f1b9082649e..932394dccd04c4c6cb59922603a4cad1dd0df522 100644 (file)
@@ -3,7 +3,7 @@ namespace wcf\system\moderation\queue;
 use wcf\data\moderation\queue\ModerationQueue;
 use wcf\data\moderation\queue\ModerationQueueAction;
 use wcf\data\moderation\queue\ViewableModerationQueue;
-use wcf\system\exception\SystemException;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
 
@@ -117,11 +117,11 @@ class ModerationQueueReportManager extends AbstractModerationQueueManager {
         * @param       integer         $objectID
         * @param       string          $message
         * @param       array           $additionalData
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function addReport($objectType, $objectID, $message, array $additionalData = []) {
                if (!$this->isValid($objectType)) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for definition 'com.woltlab.wcf.moderation.report'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.moderation.report');
                }
                
                $additionalData['message'] = $message;
index bb11efeacd50d128007da4ece661528b8f94f0dc..af07adab5463064f414ea0db9ca8cf7a8c145d11 100644 (file)
@@ -4,7 +4,7 @@ use wcf\data\object\type\ObjectTypeCache;
 use wcf\data\tag\Tag;
 use wcf\data\tag\TagAction;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\exception\SystemException;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
 
@@ -188,13 +188,13 @@ class TagEngine extends SingletonFactory {
         * 
         * @param       string          $objectType
         * @return      integer
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function getObjectTypeID($objectType) {
                // get object type
                $objectTypeObj = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.tagging.taggableObject', $objectType);
                if ($objectTypeObj === null) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for definition 'com.woltlab.wcf.tagging.taggableObject'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.tagging.taggableObject');
                }
                
                return $objectTypeObj->objectTypeID;
index a79bedc31d19bcf514d0de29a1482705fad10b11..c1512ae84496df416fab2f596eb832dd5bcb457d 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\object\type\ObjectType;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\data\user\UserProfileAction;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\exception\SystemException;
 use wcf\system\user\group\assignment\UserGroupAssignmentHandler;
 use wcf\system\SingletonFactory;
@@ -48,12 +49,12 @@ class UserActivityPointHandler extends SingletonFactory {
         * @param       integer         $objectID
         * @param       integer         $userID
         * @param       mixed[]         $additionalData
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function fireEvent($objectType, $objectID, $userID = null, array $additionalData = []) {
                $objectTypeObj = $this->getObjectTypeByName($objectType);
                if ($objectTypeObj === null) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for object type definition 'com.woltlab.wcf.user.activityPointEvent'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.user.activityPointEvent');
                }
                
                if ($userID === null) $userID = WCF::getUser()->userID;
@@ -101,12 +102,12 @@ class UserActivityPointHandler extends SingletonFactory {
         * @param       string          $objectType
         * @param       integer[]       $itemsToUser
         * @param       boolean         $updateUsers
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function fireEvents($objectType, array $itemsToUser, $updateUsers = true) {
                $objectTypeObj = $this->getObjectTypeByName($objectType);
                if ($objectTypeObj === null) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for object type definition 'com.woltlab.wcf.user.activityPointEvent'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.user.activityPointEvent');
                }
                
                if (empty($itemsToUser)) {
@@ -151,7 +152,7 @@ class UserActivityPointHandler extends SingletonFactory {
         * 
         * @param       string                  $objectType
         * @param       integer[]               $userToItems
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function removeEvents($objectType, array $userToItems) {
                if (empty($userToItems)) return;
@@ -159,7 +160,7 @@ class UserActivityPointHandler extends SingletonFactory {
                // get and validate object type
                $objectTypeObj = $this->getObjectTypeByName($objectType);
                if ($objectTypeObj === null) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for object type definition 'com.woltlab.wcf.user.activityPointEvent'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.user.activityPointEvent');
                }
                
                // remove activity points
@@ -212,13 +213,13 @@ class UserActivityPointHandler extends SingletonFactory {
         * Resets activity points and items for a given object type.
         * 
         * @param       string          $objectType
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function reset($objectType) {
                // get and validate object type
                $objectTypeObj = $this->getObjectTypeByName($objectType);
                if ($objectTypeObj === null) {
-                       throw new SystemException("Object type '".$objectType."' is not valid for object type definition 'com.woltlab.wcf.user.activityPointEvent'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.user.activityPointEvent');
                }
                
                $sql = "UPDATE  wcf".WCF_N."_user_activity_point
index 26ede4ebe00e050cb1734f6149c6a42a64c84c9e..3bbe403b7586dfbd06225f9b1c9b274a63e014f3 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system\user\collapsible\content;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\InvalidObjectTypeException;
 use wcf\system\exception\SystemException;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\SingletonFactory;
@@ -50,12 +51,12 @@ class UserCollapsibleContentHandler extends SingletonFactory {
         * @param       string          $objectType
         * @param       string          $objectID
         * @return      boolean
-        * @throws      SystemException
+        * @throws      InvalidObjectTypeException
         */
        public function isCollapsed($objectType, $objectID) {
                $objectTypeID = $this->getObjectTypeID($objectType);
                if ($objectTypeID === null) {
-                       throw new SystemException("Unknown object type '".$objectType."' for definition 'com.woltlab.wcf.collapsibleContent'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.collapsibleContent');
                }
                
                return in_array($objectID, $this->getCollapsedContent($objectTypeID));
@@ -257,7 +258,7 @@ class UserCollapsibleContentHandler extends SingletonFactory {
        public function resetAll($objectType, $objectID = null) {
                $objectTypeID = $this->getObjectTypeID($objectType);
                if (!$objectTypeID) {
-                       throw new SystemException("Unknown collapsible object type '".$objectType."'");
+                       throw new InvalidObjectTypeException($objectType, 'com.woltlab.wcf.collapsibleContent');
                }
                
                $conditionBuilder = new PreparedStatementConditionBuilder();