From e238b2cb928a1024b766032549168d04062a970c Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 10 Dec 2013 11:54:13 +0800 Subject: [PATCH] MDL-43306 restore: fix grade item sortorder restoration Previously, restore was blindly inserting the old sort order into the database, causing duplicate sortorders which lead to unpredicatble sorting results. Now we will use the api function to add it after the original sortorder, this means if a duplicate exists in the original location, this item will appear after it. --- backup/moodle2/restore_stepslib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index a4e42ef0bb7..47aed2dda29 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2782,9 +2782,9 @@ class restore_activity_grades_structure_step extends restore_structure_step { $gradeitem = new grade_item($data, false); $gradeitem->insert('restore'); - //sortorder is automatically assigned when inserting. Re-instate the previous sortorder - $gradeitem->sortorder = $data->sortorder; - $gradeitem->update('restore'); + // Reinstate the grade item close to its original sortorder, if something already exists + // in the original sortorer then it will be first. + $gradeitem->move_after_sortorder($data->sortorder); // Set mapping, saving the original category id into parentitemid // gradebook restore (final task) will need it to reorganise items -- 2.43.0