From c9deaa8e798ce0a0bc29cbce4ddabdc1d0c16504 Mon Sep 17 00:00:00 2001 From: Eric Merrill Date: Tue, 26 Mar 2013 15:18:10 -0400 Subject: [PATCH] MDL-25631 backup Decoupling legacy files from course config settigs. If they are present, they will be restored. --- backup/moodle2/restore_course_task.class.php | 2 ++ backup/moodle2/restore_stepslib.php | 24 +++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/backup/moodle2/restore_course_task.class.php b/backup/moodle2/restore_course_task.class.php index 8a8713a097c66..5f231e97d7f32 100644 --- a/backup/moodle2/restore_course_task.class.php +++ b/backup/moodle2/restore_course_task.class.php @@ -71,6 +71,8 @@ public function build() { $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')); diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index f25447552c6b4..5afd99e4a51e9 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1459,7 +1459,6 @@ protected function after_execute() { // 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 @@ protected function after_execute() { } } +/** + * 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)