Skip to content

Commit

Permalink
Implement new hook callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed May 21, 2024
1 parent cdacf2a commit b319d1d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
37 changes: 37 additions & 0 deletions classes/hook_callbacks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_redirects;

/**
* Hook callbacks for tool_redirects.
*
* @package tool_redirects
* @author Benjamin Walker (benjaminwalker@catalyst-au.net)
* @copyright 2024 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class hook_callbacks {

/**
* Redirect users based on configuration.
*
* @param \core\hook\output\before_http_headers $hook
*/
public static function before_http_headers(\core\hook\output\before_http_headers $hook): void {
\tool_redirects\helper::redirect_from_rules();
}
}
34 changes: 34 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Hook callbacks for tool_redirects
*
* @package tool_redirects
* @author Benjamin Walker (benjaminwalker@catalyst-au.net)
* @copyright 2024 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$callbacks = [
[
'hook' => \core\hook\output\before_http_headers::class,
'callback' => [\tool_redirects\hook_callbacks::class, 'before_http_headers'],
'priority' => 0,
],
];
3 changes: 3 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
/**
* Redirect users based on configuration.
*
* This is a legacy callback that is used for compatibility with older Moodle versions.
* Moodle 4.4+ will use tool_redirects\hook_callbacks::before_http_headers instead.
*
* @throws \moodle_exception
*/
function tool_redirects_before_http_headers() {
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 = 2023051100;
$plugin->release = 2023051100; // Match release exactly to version.
$plugin->version = 2024052000;
$plugin->release = 2024052000; // Match release exactly to version.
$plugin->requires = 2017051500; // Moodle 3.3.
$plugin->component = 'tool_redirects';
$plugin->maturity = MATURITY_STABLE;
$plugin->supported = [33, 401]; // Supports Moodle 3.5 or later.
$plugin->supported = [33, 404]; // Supports Moodle 3.5 or later.

0 comments on commit b319d1d

Please sign in to comment.