From f171d29508ef45fca2fdd097b31f9b0d3064a62f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Fri, 10 May 2019 13:04:20 +0200 Subject: [PATCH] Fix showOrder value for reactionTypes See #2508 --- .../acp/form/ReactionTypeAddForm.class.php | 15 ++++++++- .../type/ReactionTypeAction.class.php | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) 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); } -- 2.20.1