From: Matthias Schmidt <gravatronics@live.com>
Date: Fri, 2 Sep 2016 16:40:26 +0000 (+0200)
Subject: Add InvalidObjectTypeException
X-Git-Tag: 3.0.0_Beta_1~328
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=79bbb75a33453d8623efea94cda588234e2e6168;p=GitHub%2FWoltLab%2FWCF.git

Add InvalidObjectTypeException
---

diff --git a/wcfsetup/install/files/lib/acp/page/AbstractCategoryListPage.class.php b/wcfsetup/install/files/lib/acp/page/AbstractCategoryListPage.class.php
index 9950882d85..07ed5c3080 100644
--- a/wcfsetup/install/files/lib/acp/page/AbstractCategoryListPage.class.php
+++ b/wcfsetup/install/files/lib/acp/page/AbstractCategoryListPage.class.php
@@ -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
index 0000000000..e48c00912c
--- /dev/null
+++ b/wcfsetup/install/files/lib/system/exception/InvalidObjectTypeException.class.php
@@ -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
diff --git a/wcfsetup/install/files/lib/system/html/AbstractHtmlProcessor.class.php b/wcfsetup/install/files/lib/system/html/AbstractHtmlProcessor.class.php
index acb0cc09aa..561ff912b3 100644
--- a/wcfsetup/install/files/lib/system/html/AbstractHtmlProcessor.class.php
+++ b/wcfsetup/install/files/lib/system/html/AbstractHtmlProcessor.class.php
@@ -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 = [
diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php
index c00c57bb7e..c378588cb7 100644
--- a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php
+++ b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php
@@ -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();
diff --git a/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php b/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php
index 65706ee8ed..c1d619ec51 100644
--- a/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php
+++ b/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php
@@ -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();
diff --git a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueActivationManager.class.php b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueActivationManager.class.php
index d284cb5cd7..499e95fb95 100644
--- a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueActivationManager.class.php
+++ b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueActivationManager.class.php
@@ -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);
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 b0a54aee6c..932394dccd 100644
--- a/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php
+++ b/wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php
@@ -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;
diff --git a/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php b/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php
index bb11efeacd..af07adab54 100644
--- a/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php
+++ b/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php
@@ -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;
diff --git a/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php b/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php
index a79bedc31d..c1512ae844 100644
--- a/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php
+++ b/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php
@@ -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
diff --git a/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php
index 26ede4ebe0..3bbe403b75 100644
--- a/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php
+++ b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleContentHandler.class.php
@@ -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();