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 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.