diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index cd097aba62b..e1e75bffc3c 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -571,10 +571,13 @@ class backup_course_structure_step extends backup_structure_step { FROM {course_format_options} WHERE courseid = ? AND sectionid = 0', [ backup::VAR_PARENTID ]); - $handler = core_course\customfield\course_handler::create(); - $fieldsforbackup = $handler->get_instance_data_for_backup($this->task->get_courseid()); - $handler->backup_define_structure($this->task->get_courseid(), $customfield); - $customfield->set_source_array($fieldsforbackup); + // Custom fields. + if ($this->get_setting_value('customfield')) { + $handler = core_course\customfield\course_handler::create(); + $fieldsforbackup = $handler->get_instance_data_for_backup($this->task->get_courseid()); + $handler->backup_define_structure($this->task->get_courseid(), $customfield); + $customfield->set_source_array($fieldsforbackup); + } // Some annotations @@ -1444,17 +1447,20 @@ class backup_groups_structure_step extends backup_structure_step { $member->set_source_table('groups_members', array('groupid' => backup::VAR_PARENTID)); } - $groupcustomfieldarray = $this->get_group_custom_fields_for_backup( - $group->get_source_sql(), - [$this->get_backupid()] - ); - $groupcustomfield->set_source_array($groupcustomfieldarray); + // Custom fields. + if ($this->get_setting_value('customfield')) { + $groupcustomfieldarray = $this->get_group_custom_fields_for_backup( + $group->get_source_sql(), + [$this->get_backupid()] + ); + $groupcustomfield->set_source_array($groupcustomfieldarray); - $groupingcustomfieldarray = $this->get_grouping_custom_fields_for_backup( - $grouping->get_source_sql(), - [$this->get_backupid()] - ); - $groupingcustomfield->set_source_array($groupingcustomfieldarray); + $groupingcustomfieldarray = $this->get_grouping_custom_fields_for_backup( + $grouping->get_source_sql(), + [$this->get_backupid()] + ); + $groupingcustomfield->set_source_array($groupingcustomfieldarray); + } } // Define id annotations (as final) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 1856dededda..2c5288b7669 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1159,11 +1159,15 @@ class restore_groups_structure_step extends restore_structure_step { $groupinfo = $this->get_setting_value('groups'); if ($groupinfo) { $paths[] = new restore_path_element('group', '/groups/group'); - $paths[] = new restore_path_element('groupcustomfield', '/groups/groupcustomfields/groupcustomfield'); $paths[] = new restore_path_element('grouping', '/groups/groupings/grouping'); - $paths[] = new restore_path_element('groupingcustomfield', - '/groups/groupings/groupingcustomfields/groupingcustomfield'); $paths[] = new restore_path_element('grouping_group', '/groups/groupings/grouping/grouping_groups/grouping_group'); + + // Custom fields. + if ($this->get_setting_value('customfield')) { + $paths[] = new restore_path_element('groupcustomfield', '/groups/groupcustomfields/groupcustomfield'); + $paths[] = new restore_path_element('groupingcustomfield', + '/groups/groupings/groupingcustomfields/groupingcustomfield'); + } } return $paths; } @@ -1906,12 +1910,19 @@ class restore_course_structure_step extends restore_structure_step { protected function define_structure() { + $paths = []; + $course = new restore_path_element('course', '/course'); - $category = new restore_path_element('category', '/course/category'); - $tag = new restore_path_element('tag', '/course/tags/tag'); - $customfield = new restore_path_element('customfield', '/course/customfields/customfield'); - $courseformatoptions = new restore_path_element('course_format_option', '/course/courseformatoptions/courseformatoption'); - $allowedmodule = new restore_path_element('allowed_module', '/course/allowed_modules/module'); + $paths[] = $course; + $paths[] = new restore_path_element('category', '/course/category'); + $paths[] = new restore_path_element('tag', '/course/tags/tag'); + $paths[] = new restore_path_element('course_format_option', '/course/courseformatoptions/courseformatoption'); + $paths[] = new restore_path_element('allowed_module', '/course/allowed_modules/module'); + + // Custom fields. + if ($this->get_setting_value('customfield')) { + $paths[] = new restore_path_element('customfield', '/course/customfields/customfield'); + } // Apply for 'format' plugins optional paths at course level $this->add_plugin_structure('format', $course); @@ -1934,7 +1945,7 @@ class restore_course_structure_step extends restore_structure_step { // Apply for admin tool plugins optional paths at course level. $this->add_plugin_structure('tool', $course); - return array($course, $category, $tag, $customfield, $allowedmodule, $courseformatoptions); + return $paths; } /**