Skip to content

Commit

Permalink
Merge pull request #24 from catalyst/fix-deprecated-callback
Browse files Browse the repository at this point in the history
Add Moodle 4.5 support
  • Loading branch information
dmitriim authored Nov 29, 2024
2 parents f2e9aa7 + 02d9136 commit 49b6b75
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions classes/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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();
}
}
4 changes: 4 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
3 changes: 3 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 49b6b75

Please sign in to comment.