Skip to content

Commit

Permalink
Migrate after_config hook callback
Browse files Browse the repository at this point in the history
Change readme and version
  • Loading branch information
sumaiyamannan committed Nov 13, 2024
1 parent e0058c0 commit 0ae6043
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 28 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ what matters.

## Branches

| Moodle version | Branch | PHP | Excimer |
|-------------------|------------------|------|------------|
| Moodle 3.5+ | MOODLE_35_STABLE | 7.1+ | 1.0.2+ |
| Totara 10+ | MOODLE_35_STABLE | 7.1+ | 1.0.2+ |
| Moodle version | Branch | PHP | Excimer |
|-------------------|------------------|-------|------------|
| Moodle 4.3+ | MOODLE_403_STABLE | 8.1 | 2024110100 |
| Moodle 3.5+ | MOODLE_35_STABLE | 7.1+ | 1.0.2+ |
| Totara 10+ | MOODLE_35_STABLE | 7.1+ | 1.0.2+ |

## Installation

Expand Down
65 changes: 65 additions & 0 deletions classes/local/hooks/after_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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_excimer\local\hooks;

use tool_excimer\manager;

/**
* Class after_config
*
* @package tool_excimer
* @author Sumaiya Javed <[email protected]>
* @copyright 2024, Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class after_config {

/**
* Hook to be run after initial site config.
*
* This allows the plugin to selectively activate the ExcimerProfiler while
* having access to the database. If the site does not have the MDL-75014
* available then the timer will be started at this point. It means that
* the initialisation of the request up to this point will not be captured
* by the profiler. This eliminates the need for an
* auto_prepend_file/auto_append_file.
*
* See also https://docs.moodle.org/dev/Login_callbacks#after_config.
*
* @param \core\hook\after_config $hook
* return void
*/
public static function callback(\core\hook\after_config $hook): void {

global $CFG;

if (during_initial_install() || isset($CFG->upgraderunning)) {
// Do nothing during installation or upgrade.
return;
}

try {
// Start processor.
$manager = manager::get_instance();
$manager->start_processor();
} catch (\Exception $exception) {
debugging('tool_excimer_after_config error',
DEBUG_DEVELOPER, $exception->getTrace());
}

}
}
35 changes: 35 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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_excimer
*
* @package tool_excimer
* @author Sumaiya Javed <[email protected]>
* @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\after_config::class,
'callback' => 'tool_excimer\local\hooks\after_config::callback',
'priority' => 0,
],
];

17 changes: 0 additions & 17 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ function tool_excimer_before_session_start() {
$manager = manager::get_instance();
}

/**
* Hook to be run after initial site config.
*
* This allows the plugin to selectively activate the ExcimerProfiler while
* having access to the database. If the site does not have the MDL-75014 available, then the timer will be
* started at this point. It means that the initialisation of the
* request up to this point will not be captured by the profiler. This
* eliminates the need for an auto_prepend_file/auto_append_file.
*
* See also https://docs.moodle.org/dev/Login_callbacks#after_config.
*/
function tool_excimer_after_config(): void {
// Start processor.
$manager = manager::get_instance();
$manager->start_processor();
}

/**
* Hook to obtain a list of perfomence checks supplied by the plugin.
*
Expand Down
12 changes: 5 additions & 7 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@

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

$plugin->version = 2024091600;
$plugin->release = 2024091600;
$plugin->requires = 2017051500; // Moodle 3.3 for Totara support.
$plugin->supported = [35, 401]; // Supports Moodle 3.5 or later.
// TODO $plugin->incompatible = ; // Available as of Moodle 3.9.0 or later.

$plugin->version = 2024110100;
$plugin->release = 2024110100;
$plugin->requires = 2023100900; // Moodle 4.3.
$plugin->supported = [403, 405];
$plugin->component = 'tool_excimer';
$plugin->maturity = MATURITY_STABLE;

$plugin->dependencies = [];

0 comments on commit 0ae6043

Please sign in to comment.