In one of our courses, in a Moodle 3.1 instance, there are 7 sections in the course, and their id's are 1-6, and 110. Section 110 is an orphaned section, meaning that it doesn't appear in the course since numsections is defined to be 6.
However, in Moodle 3.3, the fact that the last section's id is not consecutive creates exceptions, since the code in course/format/lib.php, which renders the page, assumes the number of sections in the course is derived from the id of the last section:
/**It uses max(array_keys($sections)) whereas it would be better if it used count($sections)-1.
* Method used in the rendered and during backup instead of legacy 'numsections'
*
* Default renderer will treat sections with sectionnumber greater that the value returned by this
* method as "orphaned" and not display them on the course page unless in editing mode.
* Backup will store this value as 'numsections'.
*
* This method ensures that 3rd party course format plugins that still use 'numsections' continue to
* work but at the same time we no longer expect formats to have 'numsections' property.
*
* @return int
*/
public function get_last_section_number() {
$course = $this->get_course();
if (isset($course->numsections)) {
return $course->numsections;
}
$modinfo = get_fast_modinfo($course);
$sections = $modinfo->get_section_info_all();
return (int)max(array_keys($sections));
}
How can I overcome this problem?