mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-57898 core_course: backup/restore support for course custom fields
This commit is part of work on Custom fields API, to minimize commit history in moodle core the work of a team of developers was split into several commits with different authors but the authorship of individual lines of code may be different from the commit author.
This commit is contained in:
parent
028ed12228
commit
5af9aa6341
@ -168,5 +168,10 @@ class backup_root_task extends backup_task {
|
||||
$competencies = new backup_competencies_setting();
|
||||
$competencies->set_ui(new backup_setting_ui_checkbox($competencies, get_string('rootsettingcompetencies', 'backup')));
|
||||
$this->add_setting($competencies);
|
||||
|
||||
// Define custom fields inclusion setting if custom fields are used.
|
||||
$customfields = new backup_customfield_setting('customfield', base_setting::IS_BOOLEAN, true);
|
||||
$customfields->set_ui(new backup_setting_ui_checkbox($customfields, get_string('rootsettingcustomfields', 'backup')));
|
||||
$this->add_setting($customfields);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,15 @@ class backup_users_setting extends backup_generic_setting {}
|
||||
class backup_groups_setting extends backup_generic_setting {
|
||||
}
|
||||
|
||||
/**
|
||||
* root setting to control if backup will include custom field information
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @copyright 2018 Daniel Neis Araujo
|
||||
*/
|
||||
class backup_customfield_setting extends backup_generic_setting {
|
||||
}
|
||||
|
||||
/**
|
||||
* root setting to control if backup will include activities or no.
|
||||
* A lot of other settings (_included at activity levels)
|
||||
|
@ -391,6 +391,11 @@ class backup_course_structure_step extends backup_structure_step {
|
||||
$tag = new backup_nested_element('tag', array('id'), array(
|
||||
'name', 'rawname'));
|
||||
|
||||
$customfields = new backup_nested_element('customfields');
|
||||
$customfield = new backup_nested_element('customfield', array('id'), array(
|
||||
'shortname', 'type', 'value', 'valueformat'
|
||||
));
|
||||
|
||||
// attach format plugin structure to $course element, only one allowed
|
||||
$this->add_plugin_structure('format', $course, false);
|
||||
|
||||
@ -425,6 +430,9 @@ class backup_course_structure_step extends backup_structure_step {
|
||||
$course->add_child($tags);
|
||||
$tags->add_child($tag);
|
||||
|
||||
$course->add_child($customfields);
|
||||
$customfields->add_child($customfield);
|
||||
|
||||
// Set the sources
|
||||
|
||||
$courserec = $DB->get_record('course', array('id' => $this->task->get_courseid()));
|
||||
@ -457,6 +465,10 @@ class backup_course_structure_step extends backup_structure_step {
|
||||
backup_helper::is_sqlparam('course'),
|
||||
backup::VAR_PARENTID));
|
||||
|
||||
$handler = core_course\customfield\course_handler::create();
|
||||
$fieldsforbackup = $handler->get_instance_data_for_backup($this->task->get_courseid());
|
||||
$customfield->set_source_array($fieldsforbackup);
|
||||
|
||||
// Some annotations
|
||||
|
||||
$course->annotate_ids('grouping', 'defaultgroupingid');
|
||||
|
@ -286,5 +286,9 @@ class restore_root_task extends restore_task {
|
||||
$competencies = new restore_competencies_setting($hascompetencies);
|
||||
$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);
|
||||
$customfields->set_ui(new backup_setting_ui_checkbox($customfields, get_string('rootsettingcustomfields', 'backup')));
|
||||
$this->add_setting($customfields);
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,15 @@ class restore_users_setting extends restore_generic_setting {}
|
||||
class restore_groups_setting extends restore_generic_setting {
|
||||
}
|
||||
|
||||
/**
|
||||
* root setting to control if restore will include custom field information
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @copyright 2018 Daniel Neis Araujo
|
||||
*/
|
||||
class restore_customfield_setting extends restore_generic_setting {
|
||||
}
|
||||
|
||||
/**
|
||||
* root setting to control if restore will create role assignments
|
||||
* or no (any level), depends of @restore_users_setting
|
||||
|
@ -1785,6 +1785,7 @@ class restore_course_structure_step extends restore_structure_step {
|
||||
$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');
|
||||
$allowed_module = new restore_path_element('allowed_module', '/course/allowed_modules/module');
|
||||
|
||||
// Apply for 'format' plugins optional paths at course level
|
||||
@ -1808,7 +1809,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, $allowed_module);
|
||||
return array($course, $category, $tag, $customfield, $allowed_module);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1932,6 +1933,16 @@ class restore_course_structure_step extends restore_structure_step {
|
||||
context_course::instance($this->get_courseid()), $data->rawname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process custom fields
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function process_customfield($data) {
|
||||
$handler = core_course\customfield\course_handler::create();
|
||||
$handler->restore_instance_data_from_backup($this->task, $data);
|
||||
}
|
||||
|
||||
public function process_allowed_module($data) {
|
||||
$data = (object)$data;
|
||||
|
||||
|
@ -275,6 +275,7 @@ $string['restoringcourse'] = 'Course restoration in progress';
|
||||
$string['restoringcourseshortname'] = 'restoring';
|
||||
$string['restorerolemappings'] = 'Restore role mappings';
|
||||
$string['rootenrolmanual'] = 'Restore as manual enrolments';
|
||||
$string['rootsettingcustomfields'] = 'Include custom fields';
|
||||
$string['rootsettingenrolments'] = 'Include enrolment methods';
|
||||
$string['rootsettingenrolments_always'] = 'Yes, always';
|
||||
$string['rootsettingenrolments_never'] = 'No, restore users as manual enrolments';
|
||||
|
Loading…
x
Reference in New Issue
Block a user