From 38be39c9420c53e82f136e976b1274da4260a3e5 Mon Sep 17 00:00:00 2001 From: Riedler Date: Thu, 20 Nov 2025 22:48:05 +0100 Subject: [PATCH 1/3] feat: added panic switch --- lbplanner/classes/enums/SETTINGS.php | 4 ++++ lbplanner/lib.php | 4 ++++ lbplanner/settings.php | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/lbplanner/classes/enums/SETTINGS.php b/lbplanner/classes/enums/SETTINGS.php index 26414a50..2c43a255 100644 --- a/lbplanner/classes/enums/SETTINGS.php +++ b/lbplanner/classes/enums/SETTINGS.php @@ -43,6 +43,10 @@ class SETTINGS extends Enum { * NOTE: This is a constant! Do not set outside version.php under ANY circumstances! */ const V_FULLNUM = 'release_fullnum'; + /** + * Key for the panic / fulloff button. + */ + const PANIC = 'panic'; /** * Key for the setting for how many days into the future a student should be able to reserve a slot. */ diff --git a/lbplanner/lib.php b/lbplanner/lib.php index 07eaea0e..b1fa3775 100644 --- a/lbplanner/lib.php +++ b/lbplanner/lib.php @@ -23,6 +23,7 @@ */ use local_lbplanner\helpers\sentry_helper; +use local_lbplanner\enums\SETTINGS; /** * Callback for any webservices that get called by external actors. @@ -34,6 +35,9 @@ function local_lbplanner_override_webservice_execution(stdClass $externalfunctioninfo, array $params): mixed { // Only override calling our own functions. if ($externalfunctioninfo->component === 'local_lbplanner') { + if (get_config('local_lbplanner', SETTINGS::SENTRY_DSN) === '1') { + return null; // WILL crash things, but that's ok. It's a panic switch, not a careful deliberations switch. + } sentry_helper::init(); // Actually calling the function (since we're overriding this part, duh). try { diff --git a/lbplanner/settings.php b/lbplanner/settings.php index 827607f2..e36e054a 100644 --- a/lbplanner/settings.php +++ b/lbplanner/settings.php @@ -66,4 +66,12 @@ PARAM_TEXT ); $settings->add($sentrydsnsett); + + $panicsett = new admin_setting_configcheckbox( + 'local_lbplanner/' . SETTINGS::PANIC, + 'PANIC SWITCH', + 'Turns API off - only use in emergencies. No data loss, but total loss of EduPlanner services until box is unchecked.', + '0', + ); + $settings->add($panicsett); } From f7cc9e2b7b6ece1e48cbd161ef7bcb3ebe82159f Mon Sep 17 00:00:00 2001 From: Riedler Date: Thu, 20 Nov 2025 22:56:56 +0100 Subject: [PATCH 2/3] fix: critical typo, oops --- lbplanner/lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbplanner/lib.php b/lbplanner/lib.php index b1fa3775..448d6e32 100644 --- a/lbplanner/lib.php +++ b/lbplanner/lib.php @@ -35,7 +35,7 @@ function local_lbplanner_override_webservice_execution(stdClass $externalfunctioninfo, array $params): mixed { // Only override calling our own functions. if ($externalfunctioninfo->component === 'local_lbplanner') { - if (get_config('local_lbplanner', SETTINGS::SENTRY_DSN) === '1') { + if (get_config('local_lbplanner', SETTINGS::PANIC) === '1') { return null; // WILL crash things, but that's ok. It's a panic switch, not a careful deliberations switch. } sentry_helper::init(); From a67eae1d7e76b50063bfc6a8a2037f4af67e6b42 Mon Sep 17 00:00:00 2001 From: Riedler Date: Thu, 20 Nov 2025 23:00:52 +0100 Subject: [PATCH 3/3] fix: throw predictable error instead of nulling out --- lbplanner/lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbplanner/lib.php b/lbplanner/lib.php index 448d6e32..59b097bd 100644 --- a/lbplanner/lib.php +++ b/lbplanner/lib.php @@ -36,7 +36,7 @@ function local_lbplanner_override_webservice_execution(stdClass $externalfunctio // Only override calling our own functions. if ($externalfunctioninfo->component === 'local_lbplanner') { if (get_config('local_lbplanner', SETTINGS::PANIC) === '1') { - return null; // WILL crash things, but that's ok. It's a panic switch, not a careful deliberations switch. + throw new \moodle_exception('PANIC'); // TODO: add to translations. } sentry_helper::init(); // Actually calling the function (since we're overriding this part, duh).