From 6a1cd0c18428dd7fbde596b53f16e56a5d748689 Mon Sep 17 00:00:00 2001 From: Riedler Date: Sat, 18 Jan 2025 00:22:03 +0100 Subject: [PATCH 1/3] fix: rework install/uninstall/upgrade handlers --- lbplanner/classes/helpers/config_helper.php | 26 +++++++++------ lbplanner/db/uninstall.php | 36 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 lbplanner/db/uninstall.php diff --git a/lbplanner/classes/helpers/config_helper.php b/lbplanner/classes/helpers/config_helper.php index f29417bd..1d6d9238 100644 --- a/lbplanner/classes/helpers/config_helper.php +++ b/lbplanner/classes/helpers/config_helper.php @@ -58,17 +58,13 @@ public static function set_default_active_year() { } /** - * Adds a customfield to moodle for each activity where teachers can select GK EK or both. - * - * Default value is GK. - * @throws \coding_exception - * @throws \moodle_exception - * @throws \coding_exception + * Adds a customfield to moodle for each activity where teachers can select GK EK Test or M. + * Default value is empty. */ public static function add_customfield(): void { // Check if the category is already created and only create it if it doesn't exist. // Check if plugin "modcustomfields" is installed and create the category and the custom field. - if (!get_config('local_lbplanner', 'categoryid')) { + if (config_helper::get_category_id() === -1) { if (array_key_exists('modcustomfields', core_component::get_plugin_list('local'))) { @@ -100,16 +96,28 @@ public static function add_customfield(): void { } } } + /** + * Adds a customfield to moodle for each activity where teachers can select GK EK or both. + * + * @throws \coding_exception + * @throws \moodle_exception + */ + public static function remove_customfield(): void { + $handler = mod_handler::create(); + $catcontroller = category_controller::create(config_helper::get_category_id(), null, $handler); + $handler->delete_category($catcontroller); + } /** * Get the category id from the config * @return int the category id if it is set, -1 otherwise */ public static function get_category_id(): int { - if (!get_config('local_lbplanner', 'categoryid')) { + $catid = get_config('local_lbplanner', 'categoryid'); + if ($catid === false) { return -1; } else { - return intval(get_config('local_lbplanner', 'categoryid')); + return intval($catid); } } } diff --git a/lbplanner/db/uninstall.php b/lbplanner/db/uninstall.php new file mode 100644 index 00000000..52003a1e --- /dev/null +++ b/lbplanner/db/uninstall.php @@ -0,0 +1,36 @@ +. + +/** + * Contains some stuff for when the plugin gets uninstalled. + * Upgrading the plugin shouldn't trigger this code. + * + * @package local_lbplanner + * @subpackage db + * @copyright 2024 NecodeIT + * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later + */ + +use local_lbplanner\helpers\config_helper; + + +/** + * Runs when plugin is uninstalled + */ +function xmldb_local_lbplanner_uninstall() { + config_helper::remove_customfield(); +} + From e22a7c730ab2c3ca50a82e54598d6a5cde46cc3f Mon Sep 17 00:00:00 2001 From: Riedler Date: Sat, 18 Jan 2025 00:22:16 +0100 Subject: [PATCH 2/3] name kateproject --- .kateproject | 1 + 1 file changed, 1 insertion(+) diff --git a/.kateproject b/.kateproject index 18da774c..ca3bca28 100644 --- a/.kateproject +++ b/.kateproject @@ -1,4 +1,5 @@ { + "name": "lbplanner-plugin", "lspclient": { "servers": { "php" : { From c186464e2acab36f8147ab34d090fd313e2cd26a Mon Sep 17 00:00:00 2001 From: Riedler Date: Sat, 18 Jan 2025 00:30:30 +0100 Subject: [PATCH 3/3] fix: make moodle code checker happy --- lbplanner/classes/helpers/config_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lbplanner/classes/helpers/config_helper.php b/lbplanner/classes/helpers/config_helper.php index 1d6d9238..47e7a8e0 100644 --- a/lbplanner/classes/helpers/config_helper.php +++ b/lbplanner/classes/helpers/config_helper.php @@ -64,7 +64,7 @@ public static function set_default_active_year() { public static function add_customfield(): void { // Check if the category is already created and only create it if it doesn't exist. // Check if plugin "modcustomfields" is installed and create the category and the custom field. - if (config_helper::get_category_id() === -1) { + if (self::get_category_id() === -1) { if (array_key_exists('modcustomfields', core_component::get_plugin_list('local'))) { @@ -104,7 +104,7 @@ public static function add_customfield(): void { */ public static function remove_customfield(): void { $handler = mod_handler::create(); - $catcontroller = category_controller::create(config_helper::get_category_id(), null, $handler); + $catcontroller = category_controller::create(self::get_category_id(), null, $handler); $handler->delete_category($catcontroller); }