On a rare case courses will have duplicate sections those have the same id. Added some code to re-order sections if this is found when moving sections (Merged from MOODLE_15_STABLE)

This commit is contained in:
patrickslee 2005-10-14 03:12:41 +00:00
parent 33e9836968
commit 5390cbb7fc

View File

@ -1666,6 +1666,22 @@ function move_section($course, $section, $move) {
if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) {
course_set_display($course->id, $sectiondest);
}
// Check for duplicates.
// 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) {
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;
}
}
return true;
}