mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-22895 backup: Adding the feature to support backing up and restoring calendar events
This commit is contained in:
parent
a280078197
commit
8331a159c5
11 changed files with 167 additions and 0 deletions
|
@ -1596,6 +1596,78 @@ class restore_comments_structure_step extends restore_structure_step {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This structure steps restores the calendar events
|
||||
*/
|
||||
class restore_calendarevents_structure_step extends restore_structure_step {
|
||||
|
||||
protected function define_structure() {
|
||||
|
||||
$paths = array();
|
||||
|
||||
$paths[] = new restore_path_element('calendarevents', '/events/event');
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
public function process_calendarevents($data) {
|
||||
global $DB;
|
||||
|
||||
$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.
|
||||
$data->userid = $this->get_mappingid('user', $data->userid);
|
||||
if ($data->userid === false) {
|
||||
return;
|
||||
}
|
||||
if (!empty($data->groupid)) {
|
||||
$data->groupid = $this->get_mappingid('group', $data->groupid);
|
||||
if ($data->groupid === false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'name' => $data->name,
|
||||
'description' => $data->description,
|
||||
'format' => $data->format,
|
||||
'courseid' => $this->get_courseid(),
|
||||
'groupid' => $data->groupid,
|
||||
'userid' => $data->userid,
|
||||
'repeatid' => $data->repeatid,
|
||||
'modulename' => $data->modulename,
|
||||
'eventtype' => $data->eventtype,
|
||||
'timestart' => $this->apply_date_offset($data->timestart),
|
||||
'timeduration' => $data->timeduration,
|
||||
'visible' => $data->visible,
|
||||
'uuid' => $data->uuid,
|
||||
'sequence' => $data->sequence,
|
||||
'timemodified' => $this->apply_date_offset($data->timemodified));
|
||||
if ($this->name == 'activity_calendar') {
|
||||
$params['instance'] = $this->task->get_activityid();
|
||||
} else {
|
||||
$params['instance'] = 0;
|
||||
}
|
||||
$sql = 'SELECT id FROM {event} WHERE name = ? AND courseid = ? AND
|
||||
repeatid = ? AND modulename = ? AND timestart = ? AND timeduration =?
|
||||
AND ' . $DB->sql_compare_text('description', 255) . ' = ' . $DB->sql_compare_text('?', 255);
|
||||
$arg = array ($params['name'], $params['courseid'], $params['repeatid'], $params['modulename'], $params['timestart'], $params['timeduration'], $params['description']);
|
||||
$result = $DB->record_exists_sql($sql, $arg);
|
||||
if (empty($result)) {
|
||||
$newitemid = $DB->insert_record('event', $params);
|
||||
$this->set_mapping('event_description', $oldid, $newitemid, $restorefiles);
|
||||
}
|
||||
|
||||
}
|
||||
protected function after_execute() {
|
||||
global $DB;
|
||||
// Add related files
|
||||
$this->add_related_files('calendar', 'event_description', 'event_description');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class restore_course_completion_structure_step extends restore_structure_step {
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue