From 7e249fdcbe6256acc7fcd8df15cc8c2084aa67cd Mon Sep 17 00:00:00 2001 From: Riedler Date: Tue, 17 Dec 2024 17:26:51 +0100 Subject: [PATCH 1/3] fix: no using ValueError! bad Riedler :bonk: --- lbplanner/classes/polyfill/Enum.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lbplanner/classes/polyfill/Enum.php b/lbplanner/classes/polyfill/Enum.php index dde1b238..0d9ec212 100644 --- a/lbplanner/classes/polyfill/Enum.php +++ b/lbplanner/classes/polyfill/Enum.php @@ -26,7 +26,6 @@ namespace local_lbplanner\polyfill; use ReflectionClass; -use ValueError; use local_lbplanner\polyfill\EnumCase; /** @@ -38,7 +37,7 @@ class Enum { * @param mixed $value the value to be matched * @param bool $try whether to return null (true) or throw an error (false) if not found * @return ?EnumCase the matching enum case or null if not found and $try==true - * @throws ValueError if not found and $try==false + * @throws \moodle_exception if not found and $try==false */ private static function find(mixed $value, bool $try): ?EnumCase { foreach (static::cases() as $case) { @@ -50,7 +49,7 @@ private static function find(mixed $value, bool $try): ?EnumCase { if ($try) { return null; } else { - throw new ValueError("value {$value} cannot be represented as a value in enum ".static::class); + throw new \moodle_exception("value {$value} cannot be represented as a value in enum ".static::class); } } /** From a4f7b4f10a25a261096a3152f98cd2d557c43b78 Mon Sep 17 00:00:00 2001 From: Riedler Date: Tue, 17 Dec 2024 17:44:23 +0100 Subject: [PATCH 2/3] fix: cast to int --- lbplanner/classes/helpers/plan_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbplanner/classes/helpers/plan_helper.php b/lbplanner/classes/helpers/plan_helper.php index 76afb05f..aec2f61b 100644 --- a/lbplanner/classes/helpers/plan_helper.php +++ b/lbplanner/classes/helpers/plan_helper.php @@ -118,7 +118,7 @@ public static function get_access_type(int $userid, int $planid): int { if ($field === false) { return PLAN_ACCESS_TYPE::NONE; } else { - return PLAN_ACCESS_TYPE::from($field); + return PLAN_ACCESS_TYPE::from((int)$field); } } From 86b7353b871483cf16d8442213564c12f3e27e92 Mon Sep 17 00:00:00 2001 From: Riedler Date: Tue, 17 Dec 2024 17:49:06 +0100 Subject: [PATCH 3/3] fix: set_deadline --- lbplanner/services/plan/set_deadline.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lbplanner/services/plan/set_deadline.php b/lbplanner/services/plan/set_deadline.php index a1d252af..71a612ce 100644 --- a/lbplanner/services/plan/set_deadline.php +++ b/lbplanner/services/plan/set_deadline.php @@ -87,10 +87,10 @@ public static function set_deadline(int $moduleid, int $deadlinestart, int $dead throw new \moodle_exception('Access denied'); } - // If a deadline already exists. - if (!$DB->record_exists(plan_helper::DEADLINES_TABLE, ['moduleid' => $moduleid, 'planid' => $planid])) { + $deadline = $DB->get_record(plan_helper::DEADLINES_TABLE, ['moduleid' => $moduleid, 'planid' => $planid]); + + if ($deadline !== false) { // Update the existing deadline. - $deadline = $DB->get_record(plan_helper::DEADLINES_TABLE, ['moduleid' => $moduleid, 'planid' => $planid]); $deadline->deadlinestart = $deadlinestart; $deadline->deadlineend = $deadlineend;