From b1ad2f10c32e048929b74de0125ef8de563bbc4d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 26 Dec 2012 23:24:56 +0100 Subject: [PATCH] Optimized UserGroupOptionPackageInstallationPlugin Closes #1010 --- ...pOptionPackageInstallationPlugin.class.php | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php index 2b6a48d2d8..f75180033d 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php @@ -19,6 +19,12 @@ use wcf\util\StringUtil; * @category Community Framework */ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInstallationPlugin { + /** + * group id of group 'Everyone' + * @var integer + */ + protected $everyoneGroupID = null; + /** * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName */ @@ -106,20 +112,16 @@ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInst $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)); + $statement->execute(array( + $this->getEveryoneGroupID(), + $optionID, + $defaultValue + )); if ($adminDefaultValue && $defaultValue != $adminDefaultValue) { $adminGroupIDs = self::getAdminGroupIDs(); @@ -137,6 +139,26 @@ class UserGroupOptionPackageInstallationPlugin extends AbstractOptionPackageInst } } + /** + * Returns group id of 'Everyone' group. + * + * @return integer + */ + protected function getEveryoneGroupID() { + if ($this->everyoneGroupID === null) { + $sql = "SELECT groupID + FROM wcf".WCF_N."_user_group + WHERE groupType = ?"; + $statement = WCF::getDB()->prepareStatement($sql, 1); + $statement->execute(array(UserGroup::EVERYONE)); + $row = $statement->fetchArray(); + + $this->everyoneGroupID = $row['groupID']; + } + + return $this->everyoneGroupID; + } + /** * Returns an array of ids of admin groups. * -- 2.20.1