From 0e580f32e48031096aad0b21556ec9dd7d2192bc Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 12 Apr 2013 19:23:50 +0200 Subject: [PATCH] Removed obsolete code --- .../option/category/UserOptionCategory.class.php | 12 +++++------- ...AbstractOptionPackageInstallationPlugin.class.php | 12 +++++++----- .../UserOptionPackageInstallationPlugin.class.php | 9 +++++++-- wcfsetup/setup/db/install.sql | 6 +++--- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/wcfsetup/install/files/lib/data/user/option/category/UserOptionCategory.class.php b/wcfsetup/install/files/lib/data/user/option/category/UserOptionCategory.class.php index c11e8ac3eb..a43151f000 100644 --- a/wcfsetup/install/files/lib/data/user/option/category/UserOptionCategory.class.php +++ b/wcfsetup/install/files/lib/data/user/option/category/UserOptionCategory.class.php @@ -51,21 +51,19 @@ class UserOptionCategory extends DatabaseObject { } /** - * 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); } diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php index 6839a70268..e9e4253534 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php @@ -201,17 +201,19 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag */ 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, diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php index fc92fb15e0..75deba0ef4 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserOptionPackageInstallationPlugin.class.php @@ -4,6 +4,7 @@ use wcf\data\user\option\category\UserOptionCategory; 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; /** @@ -41,8 +42,12 @@ class UserOptionPackageInstallationPlugin extends AbstractOptionPackageInstallat // 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); } diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 1badc9cd8b..4017fafa7c 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -313,7 +313,7 @@ CREATE TABLE wcf1_option_category ( 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; @@ -670,7 +670,7 @@ CREATE TABLE wcf1_user_group_option_category ( 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; @@ -716,7 +716,7 @@ CREATE TABLE wcf1_user_option_category ( 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; -- 2.20.1