Optimized UserGroupOptionPackageInstallationPlugin
authorAlexander Ebert <ebert@woltlab.com>
Wed, 26 Dec 2012 22:24:56 +0000 (23:24 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 26 Dec 2012 22:24:56 +0000 (23:24 +0100)
Closes #1010

wcfsetup/install/files/lib/system/package/plugin/UserGroupOptionPackageInstallationPlugin.class.php

index 2b6a48d2d88878afc1f2a843cfbe611817c15bac..f75180033d9edf9ec29386270e3e3209bbec4c1b 100644 (file)
@@ -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.
         *