From 5b7e5885cbf5f8d19bd222227b8792497e712ac0 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 1/2] 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index f489b2c..b862213 100644 --- a/lib.php +++ b/lib.php @@ -427,8 +427,12 @@ 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. From ee672f2625f7399372a1e045b6f9fbedf34f402a Mon Sep 17 00:00:00 2001 From: Kepa Urzelai <43538080+KepaUrzelai@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:58:19 +0200 Subject: [PATCH 2/2] Codechecker warning fix: Invalid inline comment end char Codechecker warning fix: Invalid inline comment end char (line 433) --- lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib.php b/lib.php index b862213..4d780a3 100644 --- a/lib.php +++ b/lib.php @@ -430,9 +430,10 @@ function subcourse_update_grades($subcourse, $userid=0, $nullifnone=true) { if ($subcourse->refcourse) { $refgrades = subcourse_fetch_refgrades($subcourse->id, $subcourse->refcourse, false, $userid, false); } else { - // Prevent empty referenced course id coding error + // 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.