Skip to content

Commit

Permalink
Implement new hook callbacks #180
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed Jun 6, 2024
1 parent b5a13e7 commit f112266
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
39 changes: 39 additions & 0 deletions classes/hook_callbacks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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_heartbeat;

/**
* Hook callbacks for tool_heartbeat.
*
* @package tool_heartbeat
* @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 {

/**
* Runs before HTTP headers. Used to ping the cachecheck.
*
* @param \core\hook\output\before_http_headers $hook
*/
public static function before_http_headers(\core\hook\output\before_http_headers $hook): void {
if (class_exists('\core\check\manager')) {
\tool_heartbeat\check\cachecheck::ping('web');
}
}
}
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_heartbeat
*
* @package tool_heartbeat
* @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_heartbeat\hook_callbacks::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 @@ -23,6 +23,9 @@

/**
* Runs before HTTP headers. Used to ping the cachecheck.
*
* This is a legacy callback that is used for compatibility with older Moodle versions.
* Moodle 4.4+ will use tool_heartbeat\hook_callbacks::before_http_headers instead.
*/
function tool_heartbeat_before_http_headers() {
if (class_exists('\core\check\manager')) {
Expand Down
6 changes: 3 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

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

$plugin->version = 2024031400;
$plugin->release = 2024031400; // Match release exactly to version.
$plugin->version = 2024052000;
$plugin->release = 2024052000; // Match release exactly to version.
$plugin->requires = 2020061500; // Support for 3.9 and above, due to the Check API.
$plugin->supported = [39, 401];
$plugin->supported = [39, 404];
$plugin->component = 'tool_heartbeat';
$plugin->maturity = MATURITY_STABLE;

0 comments on commit f112266

Please sign in to comment.