MDL-25631 backup Decoupling legacy files from course config settigs. If they are present, they will be restored.

This commit is contained in:
Eric Merrill 2013-03-26 15:18:10 -04:00
parent 373a8e052c
commit c9deaa8e79
2 changed files with 25 additions and 1 deletions

View File

@ -71,6 +71,8 @@ class restore_course_task extends restore_task {
$this->add_step(new restore_course_structure_step('course_info', 'course.xml'));
}
$this->add_step(new restore_course_legacy_files_step('legacy_files'));
// Restore course enrolments (plugins and membership). Conditionally prevented for any IMPORT/HUB operation
if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) {
$this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));

View File

@ -1459,7 +1459,6 @@ class restore_course_structure_step extends restore_structure_step {
// Add course related files, without itemid to match
$this->add_related_files('course', 'summary', null);
$this->add_related_files('course', 'legacy', null);
// Deal with legacy allowed modules.
if ($this->legacyrestrictmodules) {
@ -1486,6 +1485,29 @@ class restore_course_structure_step extends restore_structure_step {
}
}
/**
* Execution step that will migrate legacy files if present.
*/
class restore_course_legacy_files_step extends restore_execution_step {
public function define_execution() {
global $DB;
// Do a check for legacy files and skip if there are none.
$sql = 'SELECT count(*)
FROM {backup_files_temp}
WHERE backupid = ?
AND contextid = ?
AND component = ?
AND filearea = ?';
$params = array($this->get_restoreid(), $this->task->get_old_contextid(), 'course', 'legacy');
if ($DB->count_records_sql($sql, $params)) {
$DB->set_field('course', 'legacyfiles', 2, array('id' => $this->get_courseid()));
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'course',
'legacy', $this->task->get_old_contextid(), $this->task->get_userid());
}
}
}
/*
* Structure step that will read the roles.xml file (at course/activity/block levels)