From: Joshua Rüsweg Date: Mon, 16 Oct 2017 18:23:50 +0000 (+0200) Subject: Make UserTrophyCondition more consistent X-Git-Tag: 3.1.0_Beta_2~36 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1dfc868c87017186e20340757ff47dc34b933e65;p=GitHub%2FWoltLab%2FWCF.git Make UserTrophyCondition more consistent This commit changes the array index from userTrophy to userTrophyIDs and notUserTrophy to notUserTrophyIDs when saving a trophy condition. --- 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 index 0000000000..6c812ed0ce --- /dev/null +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_beta1_to_beta2.php @@ -0,0 +1,38 @@ + + * @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 diff --git a/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php index ef1db184fc..808de82b45 100644 --- a/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php @@ -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 <<getErrorClass('userTrophy')}> -
{$this->getLabel('userTrophy')}
+getErrorClass('userTrophyIDs')}> +
{$this->getLabel('userTrophyIDs')}
- {$this->getOptionElements('userTrophy')} - {$this->getDescriptionElement('userTrophy')} - {$this->getErrorMessageElement('userTrophy')} + {$this->getOptionElements('userTrophyIDs')} + {$this->getDescriptionElement('userTrophyIDs')} + {$this->getErrorMessageElement('userTrophyIDs')}
-getErrorClass('notUserTrophy')}> -
{$this->getLabel('notUserTrophy')}
+getErrorClass('notUserTrophyIDs')}> +
{$this->getLabel('notUserTrophyIDs')}
- {$this->getOptionElements('notUserTrophy')} - {$this->getDescriptionElement('notUserTrophy')} - {$this->getErrorMessageElement('notUserTrophy')} + {$this->getOptionElements('notUserTrophyIDs')} + {$this->getDescriptionElement('notUserTrophyIDs')} + {$this->getErrorMessageElement('notUserTrophyIDs')}
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'); } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index be00135057..0ea06f4d78 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3890,11 +3890,11 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email} - - - - - + + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 75822ef8d4..6eb6767cc3 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3882,11 +3882,11 @@ Open the link below to access the user profile: - - - - - + + + + +