diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 22015c82005..39bdb0030b2 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1629,8 +1629,11 @@ class restore_section_structure_step extends restore_structure_step { $data, true); } } - $section->component = $data->component ?? null; - $section->itemid = $data->itemid ?? null; + // Moodle 4.4 implement basic delegated section logic but it is not able to restore + // them from a backup. To prevent unexpected retoration errors, all sections with + // a component will be restored as a normal section. + $section->component = null; + $section->itemid = null; $newitemid = $DB->insert_record('course_sections', $section); $section->id = $newitemid; diff --git a/backup/moodle2/tests/restore_stepslib_test.php b/backup/moodle2/tests/restore_stepslib_test.php index 3ffcbe6ae58..02023cd6220 100644 --- a/backup/moodle2/tests/restore_stepslib_test.php +++ b/backup/moodle2/tests/restore_stepslib_test.php @@ -113,15 +113,6 @@ class restore_stepslib_test extends \advanced_testcase { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(['numsections' => 2, 'format' => 'topics']); - // Section 2 has an existing delegate class. - course_update_section( - $course, - $DB->get_record('course_sections', ['course' => $course->id, 'section' => 2]), - [ - 'component' => 'test_component', - 'itemid' => 1, - ] - ); $backupid = $this->backup_course($course); $newcourseid = $this->restore_replacing_content($backupid); @@ -133,8 +124,6 @@ class restore_stepslib_test extends \advanced_testcase { $validatefields = ['name', 'summary', 'summaryformat', 'visible', 'component', 'itemid']; - $this->assertEquals($originalsections[1]->name, $restoredsections[1]->name); - foreach ($validatefields as $field) { $this->assertEquals($originalsections[1]->$field, $restoredsections[1]->$field); $this->assertEquals($originalsections[2]->$field, $restoredsections[2]->$field);