Skip to content

Commit

Permalink
MDL-53991 calendar: fix repeating events on course import
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourget committed Jan 12, 2017
1 parent d97582f commit f8dad73
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2670,7 +2670,7 @@ public function process_calendarevents($data) {
'courseid' => $this->get_courseid(),
'groupid' => $data->groupid,
'userid' => $data->userid,
'repeatid' => $data->repeatid,
'repeatid' => $this->get_mappingid('event', $data->repeatid),
'modulename' => $data->modulename,
'eventtype' => $data->eventtype,
'timestart' => $this->apply_date_offset($data->timestart),
Expand All @@ -2688,18 +2688,27 @@ public function process_calendarevents($data) {
FROM {event}
WHERE " . $DB->sql_compare_text('name', 255) . " = " . $DB->sql_compare_text('?', 255) . "
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']);
$arg = array ($params['name'], $params['courseid'], $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', $oldid, $newitemid);
$this->set_mapping('event_description', $oldid, $newitemid, $restorefiles);
}
// With repeating events, each event has the repeatid pointed at the first occurrence.
// Since the repeatid will be empty when the first occurrence is restored,
// Get the repeatid from the second occurrence of the repeating event and use that to update the first occurrence.
// Then keep a list of repeatids so we only perform this update once.
static $repeatids = array();
if (!empty($params['repeatid']) && !in_array($params['repeatid'], $repeatids)) {
// This entry is repeated so the repeatid field must be set.
$DB->set_field('event', 'repeatid', $params['repeatid'], array('id' => $params['repeatid']));
$repeatids[] = $params['repeatid'];
}

}
protected function after_execute() {
Expand Down

0 comments on commit f8dad73

Please sign in to comment.