diff --git a/backup/moodle2/restore_attendance_stepslib.php b/backup/moodle2/restore_attendance_stepslib.php index 67efb3b..dfea1c1 100644 --- a/backup/moodle2/restore_attendance_stepslib.php +++ b/backup/moodle2/restore_attendance_stepslib.php @@ -128,7 +128,11 @@ class restore_attendance_activity_structure_step extends restore_activity_struct } $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 a050109..e9acda0 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -403,8 +403,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(