MDL-47337 course: merge section options during restore

This commit is contained in:
Marina Glancy
2015-01-15 15:11:22 +08:00
parent 0582523ced
commit c301086a1f
+25 -7
View File
@@ -1386,13 +1386,31 @@ class restore_section_structure_step extends restore_structure_step {
public function process_course_format_options($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
unset($data->id);
$data->sectionid = $this->task->get_sectionid();
$data->courseid = $this->get_courseid();
$newid = $DB->insert_record('course_format_options', $data);
$this->set_mapping('course_format_options', $oldid, $newid);
static $courseformats = array();
$courseid = $this->get_courseid();
if (!array_key_exists($courseid, $courseformats)) {
// It is safe to have a static cache of course formats because format can not be changed after this point.
$courseformats[$courseid] = $DB->get_field('course', 'format', array('id' => $courseid));
}
$data = (array)$data;
if ($courseformats[$courseid] === $data['format']) {
// Import section format options only if both courses (the one that was backed up
// and the one we are restoring into) have same formats.
$params = array(
'courseid' => $this->get_courseid(),
'sectionid' => $this->task->get_sectionid(),
'format' => $data['format'],
'name' => $data['name']
);
if ($record = $DB->get_record('course_format_options', $params, 'id, value')) {
// Do not overwrite existing information.
$newid = $record->id;
} else {
$params['value'] = $data['value'];
$newid = $DB->insert_record('course_format_options', $params);
}
$this->set_mapping('course_format_options', $data['id'], $newid);
}
}
protected function after_execute() {