From: skodak Date: Wed, 19 Jul 2006 12:30:39 +0000 (+0000) Subject: Bug #6093 - Removed course sections re-appear after moving existing sections; merged... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a987106d9ed2cd7bbf20b2253b35faaa6c3ba29a;p=moodle.git Bug #6093 - Removed course sections re-appear after moving existing sections; merged from MOODLE_16_STABLE --- diff --git a/course/lib.php b/course/lib.php index 316867c96b..f4d73b5991 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1789,20 +1789,17 @@ function move_section($course, $section, $move) { course_set_display($course->id, $sectiondest); } - // Check for duplicates. + // Check for duplicates and fix order if needed. // There is a very rare case that some sections in the same course have the same section id. - if (($count_section = count_records('course_sections', 'course', $course->id) - 1) != $course->numsections) { - $sections = get_records_select('course_sections', "course = $course->id AND section > 0", 'section ASC'); - $n = 1; - foreach ($sections as $section) { + $sections = get_records_select('course_sections', "course = $course->id", 'section ASC'); + $n = 0; + foreach ($sections as $section) { + if ($section->section != $n) { if (!set_field('course_sections', 'section', $n, 'id', $section->id)) { return false; } - $n++; - } - if (!set_field('course', 'numsections', $count_section, 'id', $course->id)) { - return false; } + $n++; } return true; }