}
/**
- * Returns an instance of UserOptionCategory by name and package id.
+ * Returns an instance of UserOptionCategory by name.
*
* @param string $categoryName
- * @param integer $packageID
* @return wcf\data\user\option\category\UserOptionCategory
*/
- public static function getCategoryByName($categoryName, $packageID) {
+ public static function getCategoryByName($categoryName) {
$sql = "SELECT *
FROM wcf".WCF_N."_user_option_category
- WHERE categoryName = ?
- AND packageID = ?";
+ WHERE categoryName = ?";
$statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute(array($categoryName, $packageID));
+ $statement->execute(array($categoryName));
$row = $statement->fetchArray();
- if (!$row) $row = array();
+ if ($row === falsch) return null;
return new UserOptionCategory(null, $row);
}
*/
protected function saveCategory($category) {
// search existing category
- $sql = "SELECT categoryID
+ $sql = "SELECT categoryID, packageID
FROM wcf".WCF_N."_".$this->tableName."_category
- WHERE categoryName = ?
- AND packageID = ?";
+ WHERE categoryName = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(
- $category['categoryName'],
- $this->installation->getPackageID()
+ $category['categoryName']
));
$row = $statement->fetchArray();
if (empty($row['categoryID'])) {
+ if ($row['categoryID'] != $this->installation->getPackageID()) {
+ throw new SystemException("Cannot override existing category '".$category['categoryName']."'");
+ }
+
// insert new category
$sql = "INSERT INTO wcf".WCF_N."_".$this->tableName."_category
(packageID, categoryName, parentCategoryName, permissions,
use wcf\data\user\option\category\UserOptionCategoryEditor;
use wcf\data\user\option\UserOption;
use wcf\data\user\option\UserOptionEditor;
+use wcf\system\exception\SystemException;
use wcf\system\WCF;
/**
// append show order if explicitly stated
if ($category['showOrder'] !== null) $data['showOrder'] = $category['showOrder'];
- $userOptionCategory = UserOptionCategory::getCategoryByName($category['categoryName'], $this->installation->getPackageID());
- if ($userOptionCategory->categoryID) {
+ $userOptionCategory = UserOptionCategory::getCategoryByName($category['categoryName']);
+ if ($userOptionCategory !== null) {
+ if ($userOptionCategory->packageID != $this->installation->getPackageID()) {
+ throw new SystemException("Cannot override existing category '".$category['categoryName']."'");
+ }
+
$categoryEditor = new UserOptionCategoryEditor($userOptionCategory);
$categoryEditor->update($data);
}
showOrder INT(10) NOT NULL DEFAULT 0,
permissions TEXT,
options TEXT,
- UNIQUE KEY categoryName (categoryName, packageID)
+ UNIQUE KEY categoryName (categoryName)
);
DROP TABLE IF EXISTS wcf1_package;
showOrder INT(10) NOT NULL DEFAULT 0,
permissions TEXT,
options TEXT,
- UNIQUE KEY categoryName (categoryName, packageID)
+ UNIQUE KEY categoryName (categoryName)
);
DROP TABLE IF EXISTS wcf1_user_group_option_value;
showOrder INT(10) NOT NULL DEFAULT 0,
permissions TEXT,
options TEXT,
- UNIQUE KEY categoryName (categoryName, packageID)
+ UNIQUE KEY categoryName (categoryName)
);
DROP TABLE IF EXISTS wcf1_user_option_value;