Skip to content

Commit

Permalink
course sorting MDL-21011 "Re-sort courses by name" button eventually …
Browse files Browse the repository at this point in the history
…lead sortorder to hit column maximum value
  • Loading branch information
Andrew Davis committed Jan 8, 2010
1 parent 9c09c3b commit 1ca30d5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1ca30d5

Please sign in to comment.