From c278f7a01578ad343c367c38e05e3ec22b0b82f4 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 13 Aug 2011 08:44:34 +0200 Subject: [PATCH] GroupOptions are now UserGroupOptions While the database objects have already been renamed from Group to UserGroup, the options weren't. --- ...{groupoptions.xsd => usergroupoptions.xsd} | 0 ...{groupoptions.xml => usergroupoptions.xml} | 2 +- .../BooleanUserGroupOptionType.class.php} | 10 +- .../IUserGroupOptionType.class.php} | 6 +- ...initeIntegerUserGroupOptionType.class.php} | 12 +- ...verseIntegerUserGroupOptionType.class.php} | 11 +- .../IntegerUserGroupOptionType.class.php} | 10 +- ...verseIntegerUserGroupOptionType.class.php} | 10 +- .../TextUserGroupOptionType.class.php} | 10 +- .../TextareaUserGroupOptionType.class.php} | 11 +- .../UserGroupsUserGroupOptionType.class.php} | 10 +- ...OptionsPackageInstallationPlugin.class.php | 164 ++++++++++++++++++ 12 files changed, 211 insertions(+), 45 deletions(-) rename XSD/{groupoptions.xsd => usergroupoptions.xsd} (100%) rename com.woltlab.wcf/{groupoptions.xml => usergroupoptions.xml} (99%) rename wcfsetup/install/files/lib/system/option/{group/BooleanGroupOptionType.class.php => userGroup/BooleanUserGroupOptionType.class.php} (60%) rename wcfsetup/install/files/lib/system/option/{group/IGroupOptionType.class.php => userGroup/IUserGroupOptionType.class.php} (79%) rename wcfsetup/install/files/lib/system/option/{group/InfiniteIntegerGroupOptionType.class.php => userGroup/InfiniteIntegerUserGroupOptionType.class.php} (57%) rename wcfsetup/install/files/lib/system/option/{group/InfiniteInverseIntegerGroupOptionType.class.php => userGroup/InfiniteInverseIntegerUserGroupOptionType.class.php} (60%) rename wcfsetup/install/files/lib/system/option/{group/IntegerGroupOptionType.class.php => userGroup/IntegerUserGroupOptionType.class.php} (55%) rename wcfsetup/install/files/lib/system/option/{group/InverseIntegerGroupOptionType.class.php => userGroup/InverseIntegerUserGroupOptionType.class.php} (54%) rename wcfsetup/install/files/lib/system/option/{group/TextGroupOptionType.class.php => userGroup/TextUserGroupOptionType.class.php} (62%) rename wcfsetup/install/files/lib/system/option/{group/TextareaGroupOptionType.class.php => userGroup/TextareaUserGroupOptionType.class.php} (61%) rename wcfsetup/install/files/lib/system/option/{group/GroupsGroupOptionType.class.php => userGroup/UserGroupsUserGroupOptionType.class.php} (86%) create mode 100644 wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionsPackageInstallationPlugin.class.php diff --git a/XSD/groupoptions.xsd b/XSD/usergroupoptions.xsd similarity index 100% rename from XSD/groupoptions.xsd rename to XSD/usergroupoptions.xsd diff --git a/com.woltlab.wcf/groupoptions.xml b/com.woltlab.wcf/usergroupoptions.xml similarity index 99% rename from com.woltlab.wcf/groupoptions.xml rename to com.woltlab.wcf/usergroupoptions.xml index ffdf9c1c78..aa0ca09f40 100644 --- a/com.woltlab.wcf/groupoptions.xml +++ b/com.woltlab.wcf/usergroupoptions.xml @@ -1,5 +1,5 @@ - + diff --git a/wcfsetup/install/files/lib/system/option/group/BooleanGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/BooleanUserGroupOptionType.class.php similarity index 60% rename from wcfsetup/install/files/lib/system/option/group/BooleanGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/BooleanUserGroupOptionType.class.php index 44b122f413..82e30199cd 100644 --- a/wcfsetup/install/files/lib/system/option/group/BooleanGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/BooleanUserGroupOptionType.class.php @@ -1,21 +1,21 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class BooleanGroupOptionType extends BooleanOptionType implements IGroupOptionType { +class BooleanUserGroupOptionType extends BooleanOptionType implements IUserGroupOptionType { /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { foreach ($values as $value) { diff --git a/wcfsetup/install/files/lib/system/option/group/IGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/IUserGroupOptionType.class.php similarity index 79% rename from wcfsetup/install/files/lib/system/option/group/IGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/IUserGroupOptionType.class.php index 77a64cb6c6..1700ca5abc 100644 --- a/wcfsetup/install/files/lib/system/option/group/IGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/IUserGroupOptionType.class.php @@ -1,5 +1,5 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -interface IGroupOptionType extends IOptionType { +interface IUserGroupOptionType extends IOptionType { /** * Merges the different values of an option to a single value. * diff --git a/wcfsetup/install/files/lib/system/option/group/InfiniteIntegerGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/InfiniteIntegerUserGroupOptionType.class.php similarity index 57% rename from wcfsetup/install/files/lib/system/option/group/InfiniteIntegerGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/InfiniteIntegerUserGroupOptionType.class.php index c88b2b2eee..317541682f 100644 --- a/wcfsetup/install/files/lib/system/option/group/InfiniteIntegerGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/InfiniteIntegerUserGroupOptionType.class.php @@ -1,9 +1,9 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class InfiniteIntegerGroupOptionType extends IntegerGroupOptionType { +class InfiniteIntegerUserGroupOptionType extends IntegerUserGroupOptionType { /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { if (in_array(-1, $values)) return -1; diff --git a/wcfsetup/install/files/lib/system/option/group/InfiniteInverseIntegerGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/InfiniteInverseIntegerUserGroupOptionType.class.php similarity index 60% rename from wcfsetup/install/files/lib/system/option/group/InfiniteInverseIntegerGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/InfiniteInverseIntegerUserGroupOptionType.class.php index 18d24fbff6..33a1543610 100644 --- a/wcfsetup/install/files/lib/system/option/group/InfiniteInverseIntegerGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/InfiniteInverseIntegerUserGroupOptionType.class.php @@ -1,20 +1,21 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class InfiniteInverseIntegerGroupOptionType extends InverseIntegerGroupOptionType { +class InfiniteInverseIntegerUserGroupOptionType extends InverseIntegerUserGroupOptionType { /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { foreach ($values as $key => $value) { diff --git a/wcfsetup/install/files/lib/system/option/group/IntegerGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/IntegerUserGroupOptionType.class.php similarity index 55% rename from wcfsetup/install/files/lib/system/option/group/IntegerGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/IntegerUserGroupOptionType.class.php index c618038225..4ff7b8fa1d 100644 --- a/wcfsetup/install/files/lib/system/option/group/IntegerGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/IntegerUserGroupOptionType.class.php @@ -1,21 +1,21 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class IntegerGroupOptionType extends IntegerOptionType implements IGroupOptionType { +class IntegerUserGroupOptionType extends IntegerOptionType implements IUserGroupOptionType { /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { return max($values); diff --git a/wcfsetup/install/files/lib/system/option/group/InverseIntegerGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/InverseIntegerUserGroupOptionType.class.php similarity index 54% rename from wcfsetup/install/files/lib/system/option/group/InverseIntegerGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/InverseIntegerUserGroupOptionType.class.php index 5f0192ad5f..e05c19e86e 100644 --- a/wcfsetup/install/files/lib/system/option/group/InverseIntegerGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/InverseIntegerUserGroupOptionType.class.php @@ -1,21 +1,21 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class InverseIntegerGroupOptionType extends IntegerOptionType implements IGroupOptionType { +class InverseIntegerUserGroupOptionType extends IntegerOptionType implements IUserGroupOptionType { /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { return min($values); diff --git a/wcfsetup/install/files/lib/system/option/group/TextGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/TextUserGroupOptionType.class.php similarity index 62% rename from wcfsetup/install/files/lib/system/option/group/TextGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/TextUserGroupOptionType.class.php index c33c385e78..03a2e21ed0 100644 --- a/wcfsetup/install/files/lib/system/option/group/TextGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/TextUserGroupOptionType.class.php @@ -1,21 +1,21 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class TextGroupOptionType extends TextOptionType implements IGroupOptionType { +class TextUserGroupOptionType extends TextOptionType implements IUserGroupOptionType { /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { $result = ''; diff --git a/wcfsetup/install/files/lib/system/option/group/TextareaGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/TextareaUserGroupOptionType.class.php similarity index 61% rename from wcfsetup/install/files/lib/system/option/group/TextareaGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/TextareaUserGroupOptionType.class.php index 5c35a90370..87bd510a93 100644 --- a/wcfsetup/install/files/lib/system/option/group/TextareaGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/TextareaUserGroupOptionType.class.php @@ -1,21 +1,22 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class TextareaGroupOptionType extends TextareaOptionType implements IGroupOptionType { +class TextareaUserGroupOptionType extends TextareaOptionType implements IUserGroupOptionType { /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { $result = ''; diff --git a/wcfsetup/install/files/lib/system/option/group/GroupsGroupOptionType.class.php b/wcfsetup/install/files/lib/system/option/userGroup/UserGroupsUserGroupOptionType.class.php similarity index 86% rename from wcfsetup/install/files/lib/system/option/group/GroupsGroupOptionType.class.php rename to wcfsetup/install/files/lib/system/option/userGroup/UserGroupsUserGroupOptionType.class.php index ffae580206..7d6e00a1a7 100644 --- a/wcfsetup/install/files/lib/system/option/group/GroupsGroupOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/userGroup/UserGroupsUserGroupOptionType.class.php @@ -1,5 +1,5 @@ * @package com.woltlab.wcf - * @subpackage system.option.group + * @subpackage system.option.userGroup * @category Community Framework */ -class GroupsGroupOptionType extends AbstractOptionType implements IGroupOptionType { +class UserGroupsUserGroupOptionType extends AbstractOptionType implements IUserGroupOptionType { /** * @see wcf\system\option\IOptionType::getFormElement() */ @@ -66,7 +66,7 @@ class GroupsGroupOptionType extends AbstractOptionType implements IGroupOptionTy } /** - * @see wcf\system\option\group\IGroupOptionType::merge() + * @see wcf\system\option\userGroup\IUserGroupOptionType::merge() */ public function merge(array $values) { $result = array(); diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionsPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionsPackageInstallationPlugin.class.php new file mode 100644 index 0000000000..16d2147334 --- /dev/null +++ b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionsPackageInstallationPlugin.class.php @@ -0,0 +1,164 @@ + + * @package com.woltlab.wcf + * @subpackage system.package.plugin + * @category Community Framework + */ +class UserGroupOptionsPackageInstallationPlugin extends AbstractOptionPackageInstallationPlugin { + /** + * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName + */ + public $tableName = 'user_group_option'; + + public static $reservedTags = array('name', 'optiontype', 'defaultvalue', 'admindefaultvalue', 'validationpattern', 'showorder', 'categoryname', 'selectoptions', 'enableoptions', 'permissions', 'options', 'attrs', 'cdata'); + + /** + * Deletes group-option-categories and/or group-options which where installed by the package. + */ + public function uninstall() { + // Delete value-entries using categories or options + // which will be deleted. + $sql = "DELETE FROM wcf".WCF_N."_user_group_option_value + WHERE optionID IN ( + SELECT optionID + FROM wcf".WCF_N."_user_group_option + WHERE packageID = ? + )"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($this->installation->getPackageID())); + + parent::uninstall(); + } + + /** + * @see wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveOption() + */ + protected function saveOption($option, $categoryName, $existingOptionID = 0) { + // default values + $optionName = $optionType = $defaultValue = $adminDefaultValue = $validationPattern = $enableOptions = $permissions = $options = ''; + $showOrder = null; + + // get values + if (isset($option['name'])) $optionName = $option['name']; + if (isset($option['optiontype'])) $optionType = $option['optiontype']; + if (isset($option['defaultvalue'])) $defaultValue = $option['defaultvalue']; + if (isset($option['admindefaultvalue'])) $adminDefaultValue = $option['admindefaultvalue']; + if (isset($option['validationpattern'])) $validationPattern = $option['validationpattern']; + if (!empty($option['showorder'])) $showOrder = intval($option['showorder']); + $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName'); + if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions']; + if (isset($option['permissions'])) $permissions = $option['permissions']; + if (isset($option['options'])) $options = $option['options']; + + // check if optionType exists + $className = 'wcf\system\option\userGroup\\'.StringUtil::toUpperCase($optionType).'UserGroupOptionType'; + if (!class_exists($className)) { + throw new SystemException("unable to find class '".$className."'"); + } + + // collect additional tags and their values + $additionalData = array(); + foreach ($option as $tag => $value) { + if (!in_array($tag, self::$reservedTags)) $additionalData[$tag] = $value; + } + + // check if the otion exist already and was installed by this package + $sql = "SELECT optionID + FROM wcf".WCF_N."_user_group_option + WHERE optionName = ? + AND packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $optionName, + $this->installation->getPackageID() + )); + $row = $statement->fetchArray(); + + $data = array( + 'categoryName' => $categoryName, + 'optionType' => $optionType, + 'defaultValue' => $defaultValue, + 'adminDefaultValue' => $adminDefaultValue, + 'validationPattern' => $validationPattern, + 'showOrder' => $showOrder, + 'enableOptions' => $enableOptions, + 'permissions' => $permissions, + 'options' => $options, + 'additionalData' => serialize($additionalData) + ); + + if (!empty($row['optionID'])) { + // update existing option + $optionID = $row['optionID']; + + $groupOption = new UserGroupOption(null, $row); + $groupOptionEditor = new UserGroupOptionEditor($groupOption); + $groupOptionEditor->update($data); + } + else { + // add new option + $data['packageID'] = $this->installation->getPackageID(); + $data['optionName'] = $optionName; + + $groupOptionEditor = UserGroupOptionEditor::create($data); + $optionID = $groupOptionEditor->optionID; + + // get default group ("everyone") + $sql = "SELECT groupID + FROM wcf".WCF_N."_user_group + WHERE groupType = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array(UserGroup::EVERYONE)); + $row = $statement->fetchArray(); + + // save default value + $sql = "INSERT INTO wcf".WCF_N."_user_group_option_value + (groupID, optionID, optionValue) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($row['groupID'], $optionID, $defaultValue)); + + if ($adminDefaultValue && $defaultValue != $adminDefaultValue) { + $sql = "SELECT groupID + FROM wcf".WCF_N."_user_group_option_value + WHERE optionID = ( + SELECT optionID + FROM wcf".WCF_N."_user_group_option + WHERE optionName = ? + ) + AND optionValue = '1'"; + $statement2 = WCF::getDB()->prepareStatement($sql); + $statement2->execute(array('admin.general.canUseAcp')); + + $acpGroups = array(); + while ($row = $statement2->fetchArray()) { + $acpGroups[] = $row['groupID']; + } + + $statement2->execute(array('admin.user.canEditGroup')); + while ($row = $statement2->fetchArray()) { + if (!in_array($row['groupID'], $acpGroups)) { + continue; + } + + $statement->execute(array( + $row['groupID'], + $optionID, + $adminDefaultValue + )); + } + } + } + } +} -- 2.20.1