From 9e452e35d0a9c72c72a256659b7af557f9bbe6ce Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 8 May 2017 02:13:14 +0000 Subject: [PATCH 1/2] MDL-58822 backup: backup and restore user override events --- backup/moodle2/backup_stepslib.php | 8 ++++++++ backup/moodle2/restore_stepslib.php | 20 ++++++++++++++++--- .../moodle2/restore_assign_stepslib.php | 3 ++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 8855d58cedb..596259ee3c9 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -876,6 +876,14 @@ class backup_calendarevents_structure_step extends backup_structure_step { AND (eventtype = 'course' OR eventtype = 'group')"; $calendar_items_params = array('courseid'=>backup::VAR_COURSEID); $event->set_source_sql($calendar_items_sql, $calendar_items_params); + } else if ($this->name == 'activity_calendar') { + $params = array('instance' => backup::VAR_ACTIVITYID, 'modulename' => backup::VAR_MODNAME); + // If we don't want to include the userinfo in the backup then setting the courseid + // will filter out all of the user override events (which have a course id of zero). + if (!$this->get_setting_value('userinfo')) { + $params['courseid'] = backup::VAR_COURSEID; + } + $event->set_source_table('event', $params); } else { $event->set_source_table('event', array('courseid' => backup::VAR_COURSEID, 'instance' => backup::VAR_ACTIVITYID, 'modulename' => backup::VAR_MODNAME)); } diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index d4757be2766..89b15921228 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2653,6 +2653,17 @@ class restore_calendarevents_structure_step extends restore_structure_step { $data = (object)$data; $oldid = $data->id; $restorefiles = true; // We'll restore the files + // User overrides for activities are identified by having a courseid of zero with + // both a modulename and instance value set. + $isuseroverride = !$data->courseid && $data->modulename && $data->instance; + + + // If we don't want to include user data and this record is a user override event + // for an activity then we should not create it. + if (!$this->task->get_setting_value('userinfo') && $isuseroverride) { + return; + } + // Find the userid and the groupid associated with the event. $data->userid = $this->get_mappingid('user', $data->userid); if ($data->userid === false) { @@ -2688,7 +2699,9 @@ class restore_calendarevents_structure_step extends restore_structure_step { 'name' => $data->name, 'description' => $data->description, 'format' => $data->format, - 'courseid' => $this->get_courseid(), + // User overrides in activities use a course id of zero. All other event types + // must use the mapped course id. + 'courseid' => $data->courseid ? $this->get_courseid() : 0, 'groupid' => $data->groupid, 'userid' => $data->userid, 'repeatid' => $this->get_mappingid('event', $data->repeatid), @@ -2710,10 +2723,11 @@ class restore_calendarevents_structure_step extends restore_structure_step { WHERE " . $DB->sql_compare_text('name', 255) . " = " . $DB->sql_compare_text('?', 255) . " AND courseid = ? AND modulename = ? + AND instance = ? AND timestart = ? AND timeduration = ? AND " . $DB->sql_compare_text('description', 255) . " = " . $DB->sql_compare_text('?', 255); - $arg = array ($params['name'], $params['courseid'], $params['modulename'], $params['timestart'], $params['timeduration'], $params['description']); + $arg = array ($params['name'], $params['courseid'], $params['modulename'], $params['instance'], $params['timestart'], $params['timeduration'], $params['description']); $result = $DB->record_exists_sql($sql, $arg); if (empty($result)) { $newitemid = $DB->insert_record('event', $params); @@ -5512,4 +5526,4 @@ class restore_completion_defaults_structure_step extends restore_structure_step // Save id mapping for restoring associated events. $this->set_mapping('course_completion_defaults', $oldid, $newid); } -} \ No newline at end of file +} diff --git a/mod/assign/backup/moodle2/restore_assign_stepslib.php b/mod/assign/backup/moodle2/restore_assign_stepslib.php index e1e170d68f8..cfbb868fda9 100644 --- a/mod/assign/backup/moodle2/restore_assign_stepslib.php +++ b/mod/assign/backup/moodle2/restore_assign_stepslib.php @@ -65,8 +65,9 @@ class restore_assign_activity_structure_step extends restore_activity_structure_ $userflag = new restore_path_element('assign_userflag', '/activity/assign/userflags/userflag'); $paths[] = $userflag; - $paths[] = new restore_path_element('assign_override', '/activity/assign/overrides/override'); } + + $paths[] = new restore_path_element('assign_override', '/activity/assign/overrides/override'); $paths[] = new restore_path_element('assign_plugin_config', '/activity/assign/plugin_configs/plugin_config'); From a1ded17074d71855c66d8f17bb4037800e26a84d Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 8 May 2017 02:14:02 +0000 Subject: [PATCH 2/2] MDL-58822 backup: backup and restore new event columns --- backup/moodle2/backup_stepslib.php | 5 +++-- backup/moodle2/restore_stepslib.php | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 596259ee3c9..acdf34b45ed 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -863,8 +863,9 @@ class backup_calendarevents_structure_step extends backup_structure_step { $event = new backup_nested_element('event', array('id'), array( 'name', 'description', 'format', 'courseid', 'groupid', 'userid', - 'repeatid', 'modulename', 'instance', 'eventtype', 'timestart', - 'timeduration', 'visible', 'uuid', 'sequence', 'timemodified')); + 'repeatid', 'modulename', 'instance', 'type', 'eventtype', 'timestart', + 'timeduration', 'timesort', 'visible', 'uuid', 'sequence', 'timemodified', + 'priority')); // Build the tree $events->add_child($event); diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 89b15921228..b23fda48f61 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2657,7 +2657,6 @@ class restore_calendarevents_structure_step extends restore_structure_step { // both a modulename and instance value set. $isuseroverride = !$data->courseid && $data->modulename && $data->instance; - // If we don't want to include user data and this record is a user override event // for an activity then we should not create it. if (!$this->task->get_setting_value('userinfo') && $isuseroverride) { @@ -2706,13 +2705,16 @@ class restore_calendarevents_structure_step extends restore_structure_step { 'userid' => $data->userid, 'repeatid' => $this->get_mappingid('event', $data->repeatid), 'modulename' => $data->modulename, + 'type' => $data->type, 'eventtype' => $data->eventtype, 'timestart' => $this->apply_date_offset($data->timestart), 'timeduration' => $data->timeduration, + 'timesort' => $this->apply_date_offset($data->timesort), 'visible' => $data->visible, 'uuid' => $data->uuid, 'sequence' => $data->sequence, - 'timemodified' => $this->apply_date_offset($data->timemodified)); + 'timemodified' => $this->apply_date_offset($data->timemodified), + 'priority' => $data->priority); if ($this->name == 'activity_calendar') { $params['instance'] = $this->task->get_activityid(); } else {