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); } } 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); } } /** 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;