From 3458c729bb48151d881b8de708e7cf12329d79c0 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 18 Jan 2018 12:42:41 +1300 Subject: [PATCH] Fix #287 prevent restore from setting takenby when no userdata restored. --- backup/moodle2/restore_attendance_stepslib.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backup/moodle2/restore_attendance_stepslib.php b/backup/moodle2/restore_attendance_stepslib.php index 8a11e11..ae7cad8 100644 --- a/backup/moodle2/restore_attendance_stepslib.php +++ b/backup/moodle2/restore_attendance_stepslib.php @@ -126,17 +126,25 @@ class restore_attendance_activity_structure_step extends restore_activity_struct protected function process_attendance_session($data) { global $DB; + $userinfo = $this->get_setting_value('userinfo'); // Are we including userinfo? + $data = (object)$data; $oldid = $data->id; $data->attendanceid = $this->get_new_parentid('attendance'); $data->groupid = $this->get_mappingid('group', $data->groupid); $data->sessdate = $this->apply_date_offset($data->sessdate); - $data->lasttaken = $this->apply_date_offset($data->lasttaken); - $data->lasttakenby = $this->get_mappingid('user', $data->lasttakenby); $data->timemodified = $this->apply_date_offset($data->timemodified); $data->caleventid = $this->get_mappingid('event', $data->caleventid); + if ($userinfo) { + $data->lasttaken = $this->apply_date_offset($data->lasttaken); + $data->lasttakenby = $this->get_mappingid('user', $data->lasttakenby); + } else { + $data->lasttaken = 0; + $data->lasttakenby = 0; + } + $newitemid = $DB->insert_record('attendance_sessions', $data); $data->id = $newitemid; $this->set_mapping('attendance_session', $oldid, $newitemid, true);