MDL-27233 move the restorer enrol/ra creation to the very beginning of the restore...
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 25 Nov 2011 00:07:27 +0000 (01:07 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 25 Nov 2011 00:07:27 +0000 (01:07 +0100)
Some early steps in restore are using capability checks to decide how to
restore some information. But at that stage, if the course contents have
been removed and the user had perms at course level only (usually teacher)
the process can fail because some content is not restoreable due to the
lack of permissions.

Moving the restorer step to the beginning really helps is those situations
and it does not hurt at all.

Also, fixed one notice detected when testing this.

backup/moodle2/restore_course_task.class.php
backup/moodle2/restore_root_task.class.php
backup/util/dbops/restore_dbops.class.php

index ceb0995..1ab98bf 100644 (file)
@@ -74,9 +74,6 @@ class restore_course_task extends restore_task {
             $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
         }
 
-        // Now make sure the user that is running the restore can actually access the course
-        $this->add_step(new restore_fix_restorer_access_step('fix_restorer_access'));
-
         // Restore course filters (conditionally)
         if ($this->get_setting_value('filters')) {
             $this->add_step(new restore_filters_structure_step('course_filters', 'filters.xml'));
index 04b7f4b..a5163e9 100644 (file)
@@ -37,6 +37,10 @@ class restore_root_task extends restore_task {
         // Conditionally create the temp table (can exist from prechecks) and delete old stuff
         $this->add_step(new restore_create_and_clean_temp_stuff('create_and_clean_temp_stuff'));
 
+        // Now make sure the user that is running the restore can actually access the course
+        // before executing any other step (potentially performing permission checks)
+        $this->add_step(new restore_fix_restorer_access_step('fix_restorer_access'));
+
         // If we haven't preloaded information, load all the included inforef records to temp_ids table
         $this->add_step(new restore_load_included_inforef_records('load_inforef_records'));
 
index 5dfa499..58342b2 100644 (file)
@@ -1201,7 +1201,7 @@ abstract class restore_dbops {
         // With problems of type error, throw exception, shouldn't happen if prechecks were originally
         // executed, so be radical here.
         if (array_key_exists('errors', $problems)) {
-            throw new restore_dbops_exception('restore_problems_processing_questions', null, implode(', ', $problems));
+            throw new restore_dbops_exception('restore_problems_processing_questions', null, implode(', ', $problems['errors']));
         }
     }