Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions croncheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,51 @@
}

$dirroot = __DIR__ . '/../../../';

if (substr($_SERVER['SCRIPT_FILENAME'], -42) == '/public/admin/tool/heartbeat/croncheck.php') {
// We are in Moodle 5.2 under the public/ sub path.
$dirroot = __DIR__ . '/../../../../';
}

/**
* Checks if the command line maintenance mode has been enabled. Skip the config bootstrapping.
*
* @param string $configfile The relative path for config.php
* @return bool True if climaintenance.html is found.
*/
function check_climaintenance($configfile) {
$content = file_get_contents($configfile);

// Set comments to be on newlines, replace '//' with '\n//', where // does not start with a : colon.
$content = preg_replace("#[^!:]//#", "\n//", $content);
$content = preg_replace("/;/", ";\n", $content); // Split up statements, replace ';' with ';\n'.
$content = preg_replace("/^[\s]+/m", "", $content); // Removes all initial whitespace and newlines.

$re = '/^\$CFG->dataroot\s+=\s+["\'](.*?)["\'];/m'; // Lines starting with $CFG->dataroot.
preg_match($re, $content, $matches);
if (!empty($matches)) {
$climaintenance = $matches[count($matches) - 1] . '/climaintenance.html';

if (file_exists($climaintenance)) {
return true;
}
}

return false;
}

if (check_climaintenance($dirroot . 'config.php') === true) {
print "CRITICAL: Moodle is in hard cli maintenance mode\n";
exit;
}

require_once($dirroot . 'config.php');

if (!empty($CFG->maintenance_enabled)) {
print "CRITICAL: Moodle is in soft maintenance mode\n";
exit;
}

$filterids = [];
if ($isweb) {
// If run from the web.
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

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

$plugin->version = 2025121604;
$plugin->release = 2025121604; // Match release exactly to version.
$plugin->version = 2025121605;
$plugin->release = 2025121605; // Match release exactly to version.
$plugin->requires = 2020061500; // Support for 3.9 and above, due to the Check API.
$plugin->supported = [39, 405];
$plugin->component = 'tool_heartbeat';
Expand Down
Loading