Browse files

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.
  • Loading branch information...
1 parent 3e6e38b commit 6afd79df8dc19a01330cae0bcedb858fe28e445f @danpoltawski danpoltawski committed Dec 10, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 backup/moodle2/restore_stepslib.php
@@ -2782,9 +2782,9 @@ protected function process_grade_item($data) {
$gradeitem = new grade_item($data, false);
- //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

0 comments on commit 6afd79d

Please sign in to comment.