]> git.mjollnir.org Git - moodle.git/commitdiff
Merged from MOODLE_14_STABLE
authormartinlanghoff <martinlanghoff>
Tue, 4 Jan 2005 22:52:29 +0000 (22:52 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 4 Jan 2005 22:52:29 +0000 (22:52 +0000)
Fixes bug 2334 http://moodle.org/bugs/bug.php?op=show&bugid=2334

Courses will sometimes fail to be moved across categories if there are collisions in the sortorder field, due to a combined unique index.

With this fix, the 'category move' logic is aware of sortorder and will do The Right Thing(tm) putting the course at the beginning of the category: MIN(sortorder)-1 WHERE category=$destcategory->id .

Also added further cleanup patches.

course/category.php

index 0ec92c7bcd459f1b619dc98737086580bd94c7b0..920ad1a22b5a79708d3cce3ea93eebbccce3f5e3 100644 (file)
                     if (! $course  = get_record("course", "id", $courseid)) {
                         notify("Error finding course $courseid");
                     } else {
-                        if (!set_field("course", "category", $destcategory->id, "id", $course->id)) {
+                        // figure out a sortorder that we can use in the destination category
+                        $sortorder = get_field_sql('SELECT MIN(sortorder)-1 AS min
+                                                    FROM ' . $CFG->prefix . 'course WHERE category=' . $destcategory->id);
+                        if ($sortorder < 1) { 
+                            // rather than let the db default to 0
+                            // set it to > 100 and avoid extra work in fix_coursesortorder()
+                            $sortorder = 200;
+                        }
+
+                        $course->category  = $destcategory->id;
+                        $course->sortorder = $sortorder;
+                        if (!update_record('course', $course)) {
                             notify("An error occurred - course not moved!");
                         }
                         fix_course_sortorder();