Make UserTrophyCondition more consistent
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 16 Oct 2017 18:23:50 +0000 (20:23 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 16 Oct 2017 18:24:33 +0000 (20:24 +0200)
This commit changes the array index from userTrophy to userTrophyIDs and notUserTrophy to notUserTrophyIDs when saving a trophy condition.

wcfsetup/install/files/acp/update_com.woltlab.wcf_beta1_to_beta2.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_beta1_to_beta2.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_beta1_to_beta2.php
new file mode 100644 (file)
index 0000000..6c812ed
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+use wcf\data\condition\ConditionEditor;
+use wcf\data\condition\ConditionList;
+
+/**
+ * Rewrites the condition data from userTrophy to userTrophyIDs to make it more consistent.
+ * The rewrite is only needed if the Core is updated from 3.1.0 Beta 1 to 3.1.0 Beta 2.
+ * 
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core
+ */
+$conditionList = new ConditionList();
+$conditionList->readObjects();
+
+foreach ($conditionList->getObjects() as $condition) {
+       if ($condition->userTrophy !== null || $condition->notUserTrophy !== null) {
+               $conditionData = $condition->conditionData;
+               
+               if (isset($conditionData['userTrophy'])) {
+                       $conditionData['userTrophyIDs'] = $conditionData['userTrophy'];
+                       unset($conditionData['userTrophy']);
+               }
+               
+               if (isset($conditionData['notUserTrophy'])) {
+                       $conditionData['notUserTrophyIDs'] = $conditionData['notUserTrophy'];
+                       unset($conditionData['notUserTrophy']);
+               }
+               
+               $editor = new ConditionEditor($condition);
+               $editor->update([
+                       'conditionData' => serialize($conditionData)
+               ]);
+       }
+}
+
+ConditionEditor::resetCache();
\ No newline at end of file
index ef1db184fcc35acdb6972a49a945c2fca4101fbf..808de82b45d0662a8a1c1d70ad238b378416a408 100644 (file)
@@ -26,29 +26,29 @@ class UserTrophyCondition extends AbstractMultipleFieldsCondition implements ICo
         * @inheritDoc
         */
        protected $descriptions = [
-               'userTrophy' => 'wcf.user.condition.userTrophy.description',
-               'notUserTrophy' => 'wcf.user.condition.notUserTrophy.description'
+               'userTrophyIDs' => 'wcf.user.condition.userTrophyIDs.description',
+               'notUserTrophyIDs' => 'wcf.user.condition.notUserTrophyIDs.description'
        ];
        
        /**
         * @inheritDoc
         */
        protected $labels = [
-               'userTrophy' => 'wcf.user.condition.userTrophy',
-               'notUserTrophy' => 'wcf.user.condition.notUserTrophy'
+               'userTrophyIDs' => 'wcf.user.condition.userTrophyIDs',
+               'notUserTrophyIDs' => 'wcf.user.condition.notUserTrophyIDs'
        ];
        
        /**
         * ids of the selected trophies the user has earned
         * @var integer[]
         */
-       protected $userTrophy = [];
+       protected $userTrophyIDs = [];
        
        /**
         * ids of the selected trophies the user has not earned
         * @var integer[]
         */
-       protected $notUserTrophy = [];
+       protected $notUserTrophyIDs = [];
        
        /**
         * selectable trophies
@@ -64,11 +64,11 @@ class UserTrophyCondition extends AbstractMultipleFieldsCondition implements ICo
                        throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
                }
                
-               if (isset($conditionData['userTrophy'])) {
-                       $objectList->getConditionBuilder()->add('user_table.userID IN (SELECT userID FROM wcf'.WCF_N.'_user_trophy WHERE trophyID IN (?) GROUP BY userID HAVING COUNT(userID) = ?)', [$conditionData['userTrophy'], count($conditionData['userTrophy'])]);
+               if (isset($conditionData['userTrophyIDs'])) {
+                       $objectList->getConditionBuilder()->add('user_table.userID IN (SELECT userID FROM wcf'.WCF_N.'_user_trophy WHERE trophyID IN (?) GROUP BY userID HAVING COUNT(userID) = ?)', [$conditionData['userTrophyIDs'], count($conditionData['userTrophyIDs'])]);
                }
-               if (isset($conditionData['notUserTrophy'])) {
-                       $objectList->getConditionBuilder()->add('user_table.userID NOT IN (SELECT userID FROM wcf'.WCF_N.'_user_trophy WHERE trophyID IN (?))', [$conditionData['notUserTrophy']]);
+               if (isset($conditionData['notUserTrophyIDs'])) {
+                       $objectList->getConditionBuilder()->add('user_table.userID NOT IN (SELECT userID FROM wcf'.WCF_N.'_user_trophy WHERE trophyID IN (?))', [$conditionData['notUserTrophyIDs']]);
                }
        }
        
@@ -79,11 +79,11 @@ class UserTrophyCondition extends AbstractMultipleFieldsCondition implements ICo
                $trophies = UserTrophyList::getUserTrophies([$user->getObjectID()], false)[$user->getObjectID()];
                $trophyIDs = array_keys($trophies);
                
-               if (!empty($condition->conditionData['userTrophy']) && !empty(array_diff($condition->conditionData['userTrophy'], $trophyIDs))) {
+               if (!empty($condition->conditionData['userTrophyIDs']) && !empty(array_diff($condition->conditionData['userTrophyIDs'], $trophyIDs))) {
                        return false;
                }
                
-               if (!empty($condition->conditionData['notUserTrophy']) && !empty(array_intersect($condition->conditionData['notUserTrophy'], $trophyIDs))) {
+               if (!empty($condition->conditionData['notUserTrophyIDs']) && !empty(array_intersect($condition->conditionData['notUserTrophyIDs'], $trophyIDs))) {
                        return false;
                }
                
@@ -96,11 +96,11 @@ class UserTrophyCondition extends AbstractMultipleFieldsCondition implements ICo
        public function getData() {
                $data = [];
                
-               if (!empty($this->userTrophy)) {
-                       $data['userTrophy'] = $this->userTrophy;
+               if (!empty($this->userTrophyIDs)) {
+                       $data['userTrophyIDs'] = $this->userTrophyIDs;
                }
-               if (!empty($this->notUserTrophy)) {
-                       $data['notUserTrophy'] = $this->notUserTrophy;
+               if (!empty($this->notUserTrophyIDs)) {
+                       $data['notUserTrophyIDs'] = $this->notUserTrophyIDs;
                }
                
                if (!empty($data)) {
@@ -119,20 +119,20 @@ class UserTrophyCondition extends AbstractMultipleFieldsCondition implements ICo
                }
                
                return <<<HTML
-<dl{$this->getErrorClass('userTrophy')}>
-       <dt>{$this->getLabel('userTrophy')}</dt>
+<dl{$this->getErrorClass('userTrophyIDs')}>
+       <dt>{$this->getLabel('userTrophyIDs')}</dt>
        <dd>
-               {$this->getOptionElements('userTrophy')}
-               {$this->getDescriptionElement('userTrophy')}
-               {$this->getErrorMessageElement('userTrophy')}
+               {$this->getOptionElements('userTrophyIDs')}
+               {$this->getDescriptionElement('userTrophyIDs')}
+               {$this->getErrorMessageElement('userTrophyIDs')}
        </dd>
 </dl>
-<dl{$this->getErrorClass('notUserTrophy')}>
-       <dt>{$this->getLabel('notUserTrophy')}</dt>
+<dl{$this->getErrorClass('notUserTrophyIDs')}>
+       <dt>{$this->getLabel('notUserTrophyIDs')}</dt>
        <dd>
-               {$this->getOptionElements('notUserTrophy')}
-               {$this->getDescriptionElement('notUserTrophy')}
-               {$this->getErrorMessageElement('notUserTrophy')}
+               {$this->getOptionElements('notUserTrophyIDs')}
+               {$this->getDescriptionElement('notUserTrophyIDs')}
+               {$this->getErrorMessageElement('notUserTrophyIDs')}
        </dd>
 </dl>
 HTML;
@@ -179,27 +179,27 @@ HTML;
         * @inheritDoc
         */
        public function readFormParameters() {
-               if (isset($_POST['userTrophy'])) $this->userTrophy = ArrayUtil::toIntegerArray($_POST['userTrophy']);
-               if (isset($_POST['notUserTrophy'])) $this->notUserTrophy = ArrayUtil::toIntegerArray($_POST['notUserTrophy']);
+               if (isset($_POST['userTrophyIDs'])) $this->userTrophyIDs = ArrayUtil::toIntegerArray($_POST['userTrophyIDs']);
+               if (isset($_POST['notUserTrophyIDs'])) $this->notUserTrophyIDs = ArrayUtil::toIntegerArray($_POST['notUserTrophyIDs']);
        }
        
        /**
         * @inheritDoc
         */
        public function reset() {
-               $this->userTrophy = [];
-               $this->notUserTrophy = [];
+               $this->userTrophyIDs = [];
+               $this->notUserTrophyIDs = [];
        }
        
        /**
         * @inheritDoc
         */
        public function setData(Condition $condition) {
-               if ($condition->userTrophy !== null) {
-                       $this->userTrophy = $condition->userTrophy;
+               if ($condition->userTrophyIDs !== null) {
+                       $this->userTrophyIDs = $condition->userTrophyIDs;
                }
-               if ($condition->notUserTrophy !== null) {
-                       $this->notUserTrophy = $condition->notUserTrophy;
+               if ($condition->notUserTrophyIDs !== null) {
+                       $this->notUserTrophyIDs = $condition->notUserTrophyIDs;
                }
        }
        
@@ -208,25 +208,25 @@ HTML;
         */
        public function validate() {
                $trophies = $this->getTrophies();
-               foreach ($this->userTrophy as $trophyID) {
+               foreach ($this->userTrophyIDs as $trophyID) {
                        if (!isset($trophies[$trophyID])) {
-                               $this->errorMessages['userTrophy'] = 'wcf.global.form.error.noValidSelection';
+                               $this->errorMessages['userTrophyIDs'] = 'wcf.global.form.error.noValidSelection';
                                
-                               throw new UserInputException('userTrophy', 'noValidSelection');
+                               throw new UserInputException('userTrophyIDs', 'noValidSelection');
                        }
                }
-               foreach ($this->notUserTrophy as $trophyID) {
+               foreach ($this->notUserTrophyIDs as $trophyID) {
                        if (!isset($trophies[$trophyID])) {
-                               $this->errorMessages['notUserTrophy'] = 'wcf.global.form.error.noValidSelection';
+                               $this->errorMessages['notUserTrophyIDs'] = 'wcf.global.form.error.noValidSelection';
                                
-                               throw new UserInputException('notUserTrophy', 'noValidSelection');
+                               throw new UserInputException('notUserTrophyIDs', 'noValidSelection');
                        }
                }
                
-               if (count(array_intersect($this->notUserTrophy, $this->userTrophy))) {
-                       $this->errorMessages['notUserTrophy'] = 'wcf.user.condition.notUserTrophy.error.userTrophyIntersection';
+               if (count(array_intersect($this->notUserTrophyIDs, $this->userTrophyIDs))) {
+                       $this->errorMessages['notUserTrophyIDs'] = 'wcf.user.condition.notUserTrophy.error.userTrophyIntersection';
                        
-                       throw new UserInputException('notUserTrophy', 'userTrophyIntersection');
+                       throw new UserInputException('notUserTrophyIDs', 'userTrophyIntersection');
                }
        }
        
index be00135057749c658054a0b89e029cac65cbbb19..0ea06f4d780a1c5c2896e88b95cb0a59173661ff 100644 (file)
@@ -3890,11 +3890,11 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.condition.state.isEnabled"><![CDATA[Aktiviert]]></item>
                <item name="wcf.user.condition.state.isEnabled.error.conflict"><![CDATA[„Aktiviert“ und „Nicht aktiviert“ können nicht gleichzeitig ausgewählt werden.]]></item>
                <item name="wcf.user.condition.state.isNotBanned"><![CDATA[Nicht gesperrt]]></item>
-               <item name="wcf.user.condition.userTrophy"><![CDATA[hat Trophäe]]></item>
-               <item name="wcf.user.condition.userTrophy.description"><![CDATA[Benutzer müssen alle ausgewählten Trophäen mindestens ein mal erhalten haben.]]></item>
-               <item name="wcf.user.condition.notUserTrophy"><![CDATA[hat nicht Trophäe]]></item>
-               <item name="wcf.user.condition.notUserTrophy.description"><![CDATA[Benutzer dürfen keine der ausgewählten Trophäen erhalten haben.]]></item>
-               <item name="wcf.user.condition.notUserTrophy.error.userTrophyIntersection"><![CDATA[Die ausgewählten Trophäen in „hat Trophäe“ und „hat nicht Trophäe“ sind widersprüchlich.]]></item>
+               <item name="wcf.user.condition.userTrophyIDs"><![CDATA[hat Trophäe]]></item>
+               <item name="wcf.user.condition.userTrophyIDs.description"><![CDATA[Benutzer müssen alle ausgewählten Trophäen mindestens ein mal erhalten haben.]]></item>
+               <item name="wcf.user.condition.notUserTrophyIDs"><![CDATA[hat nicht Trophäe]]></item>
+               <item name="wcf.user.condition.notUserTrophyIDs.description"><![CDATA[Benutzer dürfen keine der ausgewählten Trophäen erhalten haben.]]></item>
+               <item name="wcf.user.condition.notUserTrophyIDs.error.userTrophyIntersection"><![CDATA[Die ausgewählten Trophäen in „hat Trophäe“ und „hat nicht Trophäe“ sind widersprüchlich.]]></item>
                <item name="wcf.user.condition.trophyPoints"><![CDATA[Trophäen]]></item>
        </category>
        
index 75822ef8d4d8e61f82468029682a36e8325df036..6eb6767cc3db9e46fe677d8e71cae47d7008f85a 100644 (file)
@@ -3882,11 +3882,11 @@ Open the link below to access the user profile:
                <item name="wcf.user.condition.state.isEnabled"><![CDATA[Approved]]></item>
                <item name="wcf.user.condition.state.isEnabled.error.conflict"><![CDATA[You cannot simultaneously select “Approved” and “Awaiting Approval”.]]></item>
                <item name="wcf.user.condition.state.isNotBanned"><![CDATA[Not Banned]]></item>
-               <item name="wcf.user.condition.userTrophy"><![CDATA[User has Trophy]]></item>
-               <item name="wcf.user.condition.userTrophy.description"><![CDATA[User has received the selected trophies.]]></item>
-               <item name="wcf.user.condition.notUserTrophy"><![CDATA[User does not have Trophy]]></item>
-               <item name="wcf.user.condition.notUserTrophy.description"><![CDATA[User has not received the selected trophies.]]></item>
-               <item name="wcf.user.condition.notUserTrophy.error.userTrophyIntersection"><![CDATA[The selected trophies in “User has Trophy” and “User does not have Trophy” are conflicting.]]></item>
+               <item name="wcf.user.condition.userTrophyIDs"><![CDATA[User has Trophy]]></item>
+               <item name="wcf.user.condition.userTrophyIDs.description"><![CDATA[User has received the selected trophies.]]></item>
+               <item name="wcf.user.condition.notUserTrophyIDs"><![CDATA[User does not have Trophy]]></item>
+               <item name="wcf.user.condition.notUserTrophyIDs.description"><![CDATA[User has not received the selected trophies.]]></item>
+               <item name="wcf.user.condition.notUserTrophyIDs.error.userTrophyIntersection"><![CDATA[The selected trophies in “User has Trophy” and “User does not have Trophy” are conflicting.]]></item>
                <item name="wcf.user.condition.trophyPoints"><![CDATA[Trophies]]></item>
        </category>