MDL-36240 backup: Activity calendar events backed up.
authorAdrian Greeve <adrian@moodle.com>
Wed, 12 Nov 2014 05:58:08 +0000 (13:58 +0800)
committerAdrian Greeve <adrian@moodle.com>
Mon, 17 Nov 2014 01:18:00 +0000 (09:18 +0800)
Activity calendar events can now be backed up and restored
when no user data is selected.

backup/moodle2/backup_root_task.class.php
backup/moodle2/restore_root_task.class.php
backup/moodle2/restore_stepslib.php

index 01a9f62..0a2df8a 100644 (file)
@@ -129,11 +129,10 @@ class backup_root_task extends backup_task {
         $activities->add_dependency($badges);
         $users->add_dependency($badges);
 
-        // Define calendar events (dependent of users)
+        // Define calendar events.
         $events = new backup_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, true);
         $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
         $this->add_setting($events);
-        $users->add_dependency($events);
 
         // Define completion (dependent of users)
         $completion = new backup_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, true);
index 61e2c5c..73384df 100644 (file)
@@ -195,7 +195,7 @@ class restore_root_task extends restore_task {
         $activities->add_dependency($badges);
         $users->add_dependency($badges);
 
-        // Define Calendar events (dependent of users)
+        // Define Calendar events.
         $defaultvalue = false;                      // Safer default
         $changeable = false;
         if (isset($rootsettings['calendarevents']) && $rootsettings['calendarevents']) { // Only enabled when available
@@ -206,7 +206,6 @@ class restore_root_task extends restore_task {
         $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
         $events->get_ui()->set_changeable($changeable);
         $this->add_setting($events);
-        $users->add_dependency($events);
 
         // Define completion (dependent of users)
         $defaultvalue = false;                      // Safer default
index 3035c7e..fc4fe15 100644 (file)
@@ -2337,15 +2337,17 @@ class restore_calendarevents_structure_step extends restore_structure_step {
     }
 
     public function process_calendarevents($data) {
-        global $DB, $SITE;
+        global $DB, $SITE, $USER;
 
         $data = (object)$data;
         $oldid = $data->id;
         $restorefiles = true; // We'll restore the files
-        // Find the userid and the groupid associated with the event. Return if not found.
+        // Find the userid and the groupid associated with the event.
         $data->userid = $this->get_mappingid('user', $data->userid);
         if ($data->userid === false) {
-            return;
+            // Blank user ID means that we are dealing with module generated events such as quiz starting times.
+            // Use the current user ID for these events.
+            $data->userid = $USER->id;
         }
         if (!empty($data->groupid)) {
             $data->groupid = $this->get_mappingid('group', $data->groupid);