danmarsden/moodle-mod_attendance

Error Deleting Attendance When "enablecalendar" is False

Closed this issue · 0 comments

Steps to Reproduce

  1. On a clean install, disable enablecalendar from the site plugin settings
  2. Turn on debugging to 'DEVELOPER'
  3. Create a course
  4. Add an Attendance activity
  5. Add multiple sessions - at least two
  6. Delete the Attendance activity
  7. View error in the output from the next run of admin/cli/cron.php

The error below occurs once for each session created:

Screenshot from 2023-08-25 09-16-56

This is cause by the DB call in classes/calendar_helpers.php:

$caleventsids = array_keys($DB->get_records_list('attendance_sessions', 'id', $sessionsids, '', 'caleventid'));

In attendance_sessions, caleventid is 0 for all entries because enablecalendar is set to false. The call to $DB->get_records_list() returns an array of objects where the key is the value of the given field, in this case, caleventid. Since all the caleventid values are 0, this produces the error above.

I think one fix is pretty easy - I'll submit a PR soon that addresses this issue.