Hi,
I had the same problem, but I'm not sure if commenting out those lines will always work. Course sections can be merged, and section numbers must be reorganized.
I'm testing a different temporary approach. In /backup/moodle2/restore_stepslib.php:1853, I modified the displace_delegated_sections_after function to update all section numbers in two steps: first assigning them temporary negative values to avoid conflicts, and then assigning the correct positive values in a second pass.
protected function displace_delegated_sections_after(int $sectionnum): void { global $DB; $sectionstomove = $DB->get_records_select( 'course_sections', 'course = ? AND component IS NOT NULL', [$this->get_courseid()], 'section DESC', 'id, section' ); $idxSection = $sectionnum; foreach ($sectionstomove as $section) { $sectionnum++; $section->section = -$sectionnum; // Temporary negative value to avoid conflicts $DB->update_record('course_sections', $section); } $sectionnum = $idxSection; foreach ($sectionstomove as $section) { $sectionnum++; $section->section = $sectionnum; // Assign correct positive value $DB->update_record('course_sections', $section); }}
Activities are imported with their respective sub-sections, and sometimes a new sub-section is created instead of using an already existing one.
I would appreciate any feedback or suggestions on whether this approach will work reliably or if there’s a better way to handle this.