Permalink
Browse files

course sorting MDL-21011 "Re-sort courses by name" button eventually …

…lead sortorder to hit column maximum value
  • Loading branch information...
1 parent 9c09c3b commit 1ca30d589fb204338ccdcae627852ee9866b1ab6 Andrew Davis committed Jan 8, 2010
Showing with 23 additions and 0 deletions.
  1. +23 −0 lib/db/upgrade.php
View
@@ -3291,6 +3291,29 @@ function xmldb_main_upgrade($oldversion=0) {
upgrade_main_savepoint($result, 2007101563.03);
}
+ if ($result && $oldversion < 2007101571.01) {
+ // MDL-21011 bring down course sort orders away from maximum values
+ $sql = "SELECT * from {$CFG->prefix}course
+ ORDER BY sortorder ASC;";
+ if ($courses = get_records_sql($sql)) {
+ $i=1000;
+ $old_category = 0;
+ foreach ($courses as $course) {
+ if($course->category!=$old_category) {
+ //increase i to put a gap between courses in different categories
+ //don't think we need to but they had one before
+ $i += 1000;
+ $old_category = $course->category;
+ }
+ $course->sortorder = $i++;
+ execute_sql("UPDATE {$CFG->prefix}course SET sortorder=$i WHERE id={$course->id}");
+ }
+ }
+ unset($courses);
+
+ upgrade_main_savepoint($result, 2007101571.01);
+ }
+
return $result;
}

0 comments on commit 1ca30d5

Please sign in to comment.