MDL-35768 Backup and restore of section format-specific options

This commit is contained in:
Marina Glancy 2012-10-11 16:03:15 +08:00
parent aea2e3c30d
commit 0360443020
2 changed files with 18 additions and 0 deletions

View File

@ -394,6 +394,11 @@ class backup_section_structure_step extends backup_structure_step {
$section->add_child($avail);
$section->add_child($availfield);
// Add nested elements for course_format_options table
$formatoptions = new backup_nested_element('course_format_options', array('id'), array(
'format', 'name', 'value'));
$section->add_child($formatoptions);
// Define sources
$section->set_source_table('course_sections', array('id' => backup::VAR_SECTIONID));
$avail->set_source_table('course_sections_availability', array('coursesectionid' => backup::VAR_SECTIONID));
@ -402,6 +407,10 @@ class backup_section_structure_step extends backup_structure_step {
FROM {course_sections_avail_fields} csaf
LEFT JOIN {user_info_field} uif ON uif.id = csaf.customfieldid
WHERE csaf.coursesectionid = ?', array(backup::VAR_SECTIONID));
$formatoptions->set_source_sql('SELECT cfo.id, cfo.format, cfo.name, cfo.value
FROM {course_format_options} cfo, {course} c
WHERE cfo.sectionid = ? AND cfo.courseid = c.id AND cfo.format = c.format',
array(backup::VAR_SECTIONID));
// Aliases
$section->set_source_alias('section', 'number');

View File

@ -1100,6 +1100,7 @@ class restore_section_structure_step extends restore_structure_step {
$paths[] = new restore_path_element('availability', '/section/availability');
$paths[] = new restore_path_element('availability_field', '/section/availability_field');
}
$paths[] = new restore_path_element('course_format_options', '/section/course_format_options');
// Apply for 'format' plugins optional paths at section level
$this->add_plugin_structure('format', $section);
@ -1233,6 +1234,14 @@ class restore_section_structure_step extends restore_structure_step {
}
}
public function process_course_format_options($data) {
global $DB;
$data = (object)$data;
$data->sectionid = $this->task->get_sectionid();
$data->courseid = $this->get_courseid();
$newid = $DB->insert_record('course_format_options', $data);
}
protected function after_execute() {
// Add section related files, with 'course_section' itemid to match
$this->add_related_files('course', 'section', 'course_section');