From 9404332ebc47eee9d1b426d2ad0c3e4cd2d4daad Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Wed, 14 Jun 2017 11:13:20 +1200 Subject: [PATCH] Fixes #265 create calendar events when restoring an attendance. also add sanity check if restored session doesn't have a calendar event. --- backup/moodle2/restore_attendance_stepslib.php | 4 ++++ classes/structure.php | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/backup/moodle2/restore_attendance_stepslib.php b/backup/moodle2/restore_attendance_stepslib.php index 97bd5ed..ba6b6fd 100644 --- a/backup/moodle2/restore_attendance_stepslib.php +++ b/backup/moodle2/restore_attendance_stepslib.php @@ -120,7 +120,11 @@ class restore_attendance_activity_structure_step extends restore_activity_struct $data->caleventid = $this->get_mappingid('event', $data->caleventid); $newitemid = $DB->insert_record('attendance_sessions', $data); + $data->id = $newitemid; $this->set_mapping('attendance_session', $oldid, $newitemid, true); + + // Create Calendar event. + attendance_create_calendar_event($data); } /** diff --git a/classes/structure.php b/classes/structure.php index 14b484d..ceee72d 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -513,8 +513,12 @@ class mod_attendance_structure { $sess->timemodified = time(); $DB->update_record('attendance_sessions', $sess); - - attendance_update_calendar_event($sess->caleventid, $sess->duration, $sess->sessdate); + if (empty($sess->caleventid)) { + // This shouldn't really happen, but just in case to prevent fatal error. + attendance_create_calendar_event($sess); + } else { + attendance_update_calendar_event($sess->caleventid, $sess->duration, $sess->sessdate); + } $info = construct_session_full_date_time($sess->sessdate, $sess->duration); $event = \mod_attendance\event\session_updated::create(array(