diff --git a/classes/hook_callbacks.php b/classes/hook_callbacks.php new file mode 100644 index 0000000..5d71fd4 --- /dev/null +++ b/classes/hook_callbacks.php @@ -0,0 +1,39 @@ +. + +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'); + } + } +} diff --git a/db/hooks.php b/db/hooks.php new file mode 100644 index 0000000..fac84b9 --- /dev/null +++ b/db/hooks.php @@ -0,0 +1,34 @@ +. + +/** + * 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, + ], +]; diff --git a/lib.php b/lib.php index 9061ead..7114c3c 100644 --- a/lib.php +++ b/lib.php @@ -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')) { diff --git a/version.php b/version.php index 4edaf89..186f22f 100644 --- a/version.php +++ b/version.php @@ -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;