From 559027a76c8b62c05dc8bddddf30a342987be9e9 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Tue, 4 Jan 2005 22:52:29 +0000 Subject: [PATCH] Merged from MOODLE_14_STABLE 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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/course/category.php b/course/category.php index 0ec92c7bcd..920ad1a22b 100644 --- a/course/category.php +++ b/course/category.php @@ -137,7 +137,19 @@ 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(); -- 2.39.5