mdjnelson / moodle-mod_customcert

Enables the creation of dynamically generated certificates with complete customisation via the web browser.
https://moodle.org/plugins/mod_customcert
GNU General Public License v3.0
93 stars 159 forks source link

Cron task error with missing gradeitems #592

Closed Peterburnett closed 8 months ago

Peterburnett commented 9 months ago

Hit a cron error where a course has deleted a gradeitem, and not updated their cert. This is blocking the cron task from finishing fully.

0007fc840fa5:27510 2024-01-07 19:50:58 Scheduled task failed: Handles emailing certificates. (mod_customcert\task\email_certificate_task),Call to a member function get_name() on bool
0007fc840fa5:27510 2024-01-07 19:50:58 Backtrace:
0007fc840fa5:27510 2024-01-07 19:50:58 * line 76 of /mod/customcert/element/gradeitemname/classes/element.php: call to customcertelement_gradeitemname\element->get_grade_item_name()
0007fc840fa5:27510 2024-01-07 19:50:58 * line 363 of /mod/customcert/classes/template.php: call to customcertelement_gradeitemname\element->render()
0007fc840fa5:27510 2024-01-07 19:50:58 * line 195 of /mod/customcert/classes/task/email_certificate_task.php: call to mod_customcert\template->generate_pdf()
0007fc840fa5:27510 2024-01-07 19:50:58 * line 309 of /lib/cronlib.php: call to mod_customcert\task\email_certificate_task->execute()
0007fc840fa5:27510 2024-01-07 19:50:58 * line 120 of /lib/cronlib.php: call to cron_run_inner_scheduled_task()
0007fc840fa5:27510 2024-01-07 19:50:58 * line 73 of /lib/cronlib.php: call to cron_run_scheduled_tasks()
0007fc840fa5:27510 2024-01-07 19:50:58 * line 178 of /admin/cli/cron.php: call to cron_run()
0007fc840fa5:27510 2024-01-07 19:50:58 

I can see in other locations such as the date element fetching the gradeitem is done via element helper which returns a false, but in the gradeitemname element its direct fetched using the API, but not checked if its missing.

The frontend already renders nothing when the gradeitem is missing, so the lowest friction fix here is to just return an empty string as the name in cases where fetch() returns false.

mdjnelson commented 8 months ago

Thanks @Peterburnett, closing.