MDL-26841 backup - prevent any enrolments info to be handled in IMPORT/HUB operations
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 19 Sep 2011 09:21:43 +0000 (11:21 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 19 Sep 2011 09:21:43 +0000 (11:21 +0200)
backup/moodle2/backup_course_task.class.php
backup/moodle2/restore_course_task.class.php
backup/moodle2/restore_stepslib.php

index 6be90a7..41dcaee 100644 (file)
@@ -72,8 +72,10 @@ class backup_course_task extends backup_task {
         // annotating some bits, tags and module restrictions
         $this->add_step(new backup_course_structure_step('course_info', 'course.xml'));
 
-        // Generate the enrolment file
-        $this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
+        // Generate the enrolment file (conditionally, prevent it in any IMPORT/HUB operation)
+        if (!$this->plan->get_mode() == backup::MODE_IMPORT && !$this->plan->get_mode() == backup::MODE_HUB) {
+            $this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
+        }
 
         // Annotate all the groups and groupings belonging to the course
         $this->add_step(new backup_annotate_course_groups_and_groupings('annotate_course_groups'));
index 0e6896a..989e5a7 100644 (file)
@@ -69,8 +69,10 @@ class restore_course_task extends restore_task {
         // 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'));
 
-        // Restore course enrolments (plugins and membership)
-        $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
+        // 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'));
+        }
 
         // Restore course filters (conditionally)
         if ($this->get_setting_value('filters')) {
index 0dfc5a0..7141640 100644 (file)
@@ -1291,6 +1291,28 @@ class restore_ras_and_caps_structure_step extends restore_structure_step {
  */
 class restore_enrolments_structure_step extends restore_structure_step {
 
+    /**
+     * Conditionally decide if this step should be executed.
+     *
+     * This function checks the following parameter:
+     *
+     *   1. the course/enrolments.xml file exists
+     *
+     * @return bool true is safe to execute, false otherwise
+     */
+    protected function execute_condition() {
+
+        // Check it is included in the backup
+        $fullpath = $this->task->get_taskbasepath();
+        $fullpath = rtrim($fullpath, '/') . '/' . $this->filename;
+        if (!file_exists($fullpath)) {
+            // Not found, can't restore enrolments info
+            return false;
+        }
+
+        return true;
+    }
+
     protected function define_structure() {
 
         $paths = array();
@@ -1749,7 +1771,7 @@ class restore_course_logs_structure_step extends restore_structure_step {
     /**
      * Conditionally decide if this step should be executed.
      *
-     * This function checks the following four parameters:
+     * This function checks the following parameter:
      *
      *   1. the course/logs.xml file exists
      *