This commit is contained in:
Jun Pataleta
2024-09-27 12:40:12 +08:00
3 changed files with 49 additions and 24 deletions
+20 -14
View File
@@ -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)
+9 -1
View File
@@ -300,8 +300,16 @@ class restore_root_task extends restore_task {
$competencies->set_ui(new backup_setting_ui_checkbox($competencies, get_string('rootsettingcompetencies', 'backup')));
$this->add_setting($competencies);
$customfields = new restore_customfield_setting('customfields', base_setting::IS_BOOLEAN, $defaultvalue);
// Custom fields.
$defaultvalue = false;
$changeable = false;
if (isset($rootsettings['customfield']) && $rootsettings['customfield']) { // Only enabled when available.
$defaultvalue = true;
$changeable = true;
}
$customfields = new restore_customfield_setting('customfield', base_setting::IS_BOOLEAN, $defaultvalue);
$customfields->set_ui(new backup_setting_ui_checkbox($customfields, get_string('rootsettingcustomfield', 'backup')));
$customfields->get_ui()->set_changeable($changeable);
$this->add_setting($customfields);
// Define Content bank content.
+20 -9
View File
@@ -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;
}
/**