Permalink
Browse files

On a rare case courses will have duplicate sections those have the sa…

…me id. Added some code to re-order sections if this is found when moving sections (Merged from MOODLE_15_STABLE)
  • Loading branch information...
1 parent 33e9836 commit 5390cbb7fcc66b021cb65f71e7dfc535f6a44788 patrickslee committed Oct 14, 2005
Showing with 16 additions and 0 deletions.
  1. +16 −0 course/lib.php
View
@@ -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;
}

0 comments on commit 5390cbb

Please sign in to comment.