From ac15ca875841824272dea56221a43fe3731dc595 Mon Sep 17 00:00:00 2001 From: GabrielJenik Date: Fri, 10 Jul 2020 14:56:12 -0300 Subject: [PATCH 1/2] Fixed issue #16454: Sometimes, question_order is assigned from survey_id When deleting a question, the order of questions in the group were reassigned by calling updateQuestionOrder, but the survey ID was passed as starting position. --- application/models/Question.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/Question.php b/application/models/Question.php index 6b7612cbb69..71e8a4920cb 100644 --- a/application/models/Question.php +++ b/application/models/Question.php @@ -428,7 +428,7 @@ public function delete() $this->removeFromLastVisited(); if (parent::delete()) { - Question::model()->updateQuestionOrder($this->gid, $this->sid); + Question::model()->updateQuestionOrder($this->gid); return true; } return false; From 1b975c60d3c4128fc72a542b07d3d981bb2eae9c Mon Sep 17 00:00:00 2001 From: GabrielJenik Date: Fri, 10 Jul 2020 14:57:44 -0300 Subject: [PATCH 2/2] Fixed issue #16454: Sometimes, question_order is assigned from survey_id updateQuestionOrder definition was modified to use 1 as default value. Now reordering will follow the same schema as when questions are added, both starting from 1. --- application/models/Question.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/application/models/Question.php b/application/models/Question.php index 71e8a4920cb..92278254b2e 100644 --- a/application/models/Question.php +++ b/application/models/Question.php @@ -250,10 +250,12 @@ public static function updateSortOrder($gid, $surveyid) /** * Fix sort order for questions in a group + * All questions in the group will be assigned a sequential question order, + * starting in the specified value * @param int $gid - * @param int $position + * @param int $startingOrder the starting question order. */ - public function updateQuestionOrder($gid, $position = 0) + public function updateQuestionOrder($gid, $startingOrder = 1) { $data = Yii::app()->db->createCommand()->select('qid') ->where(array('and', 'gid=:gid', 'parent_qid=0')) @@ -262,7 +264,7 @@ public function updateQuestionOrder($gid, $position = 0) ->bindParam(':gid', $gid, PDO::PARAM_INT) ->query(); - $position = intval($position); + $position = intval($startingOrder); foreach ($data->readAll() as $row) { Yii::app()->db->createCommand()->update( $this->tableName(),