From ed8c786f5234cbb4d71c50179e682893bf106475 Mon Sep 17 00:00:00 2001 From: Kepa Urzelai <43538080+KepaUrzelai@users.noreply.github.com> Date: Tue, 10 Sep 2024 11:48:10 +0200 Subject: [PATCH] Issue #95: prevent empty referenced course id coding error Patch: Referenced course is checked before trying to update module grades, as the subcourse setting "Fetch grades from" can be set to None. --- lib.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index f489b2c..4d780a3 100644 --- a/lib.php +++ b/lib.php @@ -427,8 +427,13 @@ function subcourse_update_grades($subcourse, $userid=0, $nullifnone=true) { require_once($CFG->dirroot . '/mod/subcourse/locallib.php'); require_once($CFG->libdir.'/gradelib.php'); - $refgrades = subcourse_fetch_refgrades($subcourse->id, $subcourse->refcourse, false, $userid, false); - + if ($subcourse->refcourse) { + $refgrades = subcourse_fetch_refgrades($subcourse->id, $subcourse->refcourse, false, $userid, false); + } else { + // Prevent empty referenced course id coding error. + return GRADE_UPDATE_FAILED; + } + if ($refgrades && $refgrades->grades) { if (!empty($refgrades->localremotescale)) { // Unable to fetch remote grades - local scale is used in the remote course.