From 8fe7e3aefb2e3ea77640b4abd8faf592bd52e174 Mon Sep 17 00:00:00 2001 From: Alexander Van der Bellen Date: Thu, 28 Nov 2024 12:00:23 +0800 Subject: [PATCH 1/2] Add Moodle 4.5 support --- classes/hook_callbacks.php | 20 ++++++++++++++++++++ db/hooks.php | 4 ++++ lib.php | 3 +++ version.php | 6 +++--- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/classes/hook_callbacks.php b/classes/hook_callbacks.php index ee1bdba..fd8483c 100644 --- a/classes/hook_callbacks.php +++ b/classes/hook_callbacks.php @@ -16,6 +16,10 @@ namespace tool_redirects; +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->dirroot . '/admin/tool/redirects/lib.php'); + /** * Hook callbacks for tool_redirects. * @@ -34,4 +38,20 @@ class hook_callbacks { public static function before_http_headers(\core\hook\output\before_http_headers $hook): void { \tool_redirects\helper::redirect_from_rules(); } + + /** + * Listener for the after_config hook. + * + * @param \core\hook\after_config $hook + */ + public static function after_config(\core\hook\after_config $hook): void { + global $CFG; + + if (during_initial_install() || isset($CFG->upgraderunning)) { + // Do nothing during installation or upgrade. + return; + } + + tool_redirects_after_config(); + } } diff --git a/db/hooks.php b/db/hooks.php index cf13ee4..5c79c2e 100644 --- a/db/hooks.php +++ b/db/hooks.php @@ -31,4 +31,8 @@ 'callback' => '\tool_redirects\hook_callbacks::before_http_headers', 'priority' => 0, ], + [ + 'hook' => \core\hook\after_config::class, + 'callback' => '\tool_redirects\hook_callbacks::after_config', + ], ]; diff --git a/lib.php b/lib.php index b179a9e..a978677 100644 --- a/lib.php +++ b/lib.php @@ -38,6 +38,9 @@ function tool_redirects_before_http_headers() { /** * Redirect users based on configuration. * + * This is a legacy callback that is used for compatibility with older Moodle versions. + * Moodle 4.5+ will use tool_redirects\hook_callbacks::after_config instead. + * * @throws \moodle_exception */ function tool_redirects_after_config() { diff --git a/version.php b/version.php index 8d36087..72b46b0 100644 --- a/version.php +++ b/version.php @@ -25,9 +25,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024052400; -$plugin->release = 2024052400; // Match release exactly to version. +$plugin->version = 2024112800; +$plugin->release = 2024112800; // Match release exactly to version. $plugin->requires = 2017051500; // Moodle 3.3. $plugin->component = 'tool_redirects'; $plugin->maturity = MATURITY_STABLE; -$plugin->supported = [33, 404]; // Supports Moodle 3.5 or later. +$plugin->supported = [33, 405]; // Supports Moodle 3.5 or later. From 02d91362574440dce045f8bab73054d2a1a2df61 Mon Sep 17 00:00:00 2001 From: Alexander Van der Bellen Date: Fri, 29 Nov 2024 10:18:36 +0800 Subject: [PATCH 2/2] Add branch table to readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 390e700..c682bfe 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,11 @@ A very simple plugin which allows admin to set redirects based on url. Redirects be from existing Moodle pages like from one course to another, or they can be 'vanity' urls from non existing urls into a page inside Moodle. +## Branches +| Moodle version | Branch | PHP | +|-------------------|-------------------------------------------------------------------------|------| +| Moodle 4.1+ | [master](https://github.com/catalyst/moodle-tool_redirects/tree/master) | 7.4+ | + ## Installation Step 1: Install the local module