Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-25631 backup Decoupling legacy files from course config settigs. …

…If they are present, they will be restored.
  • Loading branch information...
commit 4c31a1526169739f41965c30970524da4a5d3d88 1 parent 8bb0c27
@merrill-oakland merrill-oakland authored
View
2  backup/moodle2/restore_course_task.class.php
@@ -74,6 +74,8 @@ public function build() {
// Restore course role assignments and overrides (internally will observe the role_assignments setting)
$this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.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
24 backup/moodle2/restore_stepslib.php
@@ -1340,7 +1340,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) {
@@ -1367,6 +1366,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)
Please sign in to comment.
Something went wrong with that request. Please try again.