From: Joshua Rüsweg Date: Fri, 10 May 2019 11:04:20 +0000 (+0200) Subject: Fix showOrder value for reactionTypes X-Git-Tag: 5.2.0_Alpha_1~98 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f171d29508ef45fca2fdd097b31f9b0d3064a62f;p=GitHub%2FWoltLab%2FWCF.git Fix showOrder value for reactionTypes See #2508 --- diff --git a/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php b/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php index dce9282938..bff6c926db 100644 --- a/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php @@ -72,7 +72,20 @@ class ReactionTypeAddForm extends AbstractFormBuilderForm { ShowOrderFormField::create() ->description('wcf.acp.reactionType.showOrder.description') ->required() - ->options(new ReactionTypeList()), + ->options(function () { + $list = new ReactionTypeList(); + $list->sqlOrderBy = 'showOrder ASC'; + $list->readObjects(); + + $returnValues = []; + + foreach ($list as $reactionType) { + $returnValues[$reactionType->showOrder + 1] = $reactionType->getTitle(); + } + + return $returnValues; + + }), IsDisabledFormField::create() ->label('wcf.acp.reactionType.isDisabled') ]); diff --git a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php index af26b2e01d..09488edd87 100644 --- a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php +++ b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php @@ -40,6 +40,16 @@ class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortab * @inheritDoc */ public function create() { + if (isset($this->parameters['data']['showOrder']) && $this->parameters['data']['showOrder'] !== null) { + $sql = "UPDATE wcf" . WCF_N . "_reaction_type + SET showOrder = showOrder + 1 + WHERE showOrder >= ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + $this->parameters['data']['showOrder'] + ]); + } + /** @var ReactionType $reactionType */ $reactionType = parent::create(); $reactionTypeEditor = new ReactionTypeEditor($reactionType); @@ -129,6 +139,27 @@ class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortab } } + // update show order + if (isset($this->parameters['data']['showOrder']) && $this->parameters['data']['showOrder'] !== null) { + $sql = "UPDATE wcf" . WCF_N . "_reaction_type + SET showOrder = showOrder + 1 + WHERE showOrder >= ? + AND reactionTypeID <> ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + $this->parameters['data']['showOrder'], + $object->reactionTypeID + ]); + + $sql = "UPDATE wcf" . WCF_N . "_reaction_type + SET showOrder = showOrder - 1 + WHERE showOrder >= ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + $object->showOrder + ]); + } + if (!empty($updateData)) { $object->update($updateData); }