mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'w04_MDL-37596_m25_schedmaint' of git://github.com/skodak/moodle
This commit is contained in:
commit
bf6a1b9078
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -16,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Enable or disable maintenance mode
|
||||
* Enable or disable maintenance mode.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage cli
|
||||
@ -26,12 +25,13 @@
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
|
||||
require(dirname(dirname(dirname(__FILE__))).'/config.php');
|
||||
require_once($CFG->libdir.'/clilib.php'); // cli only functions
|
||||
require(__DIR__.'/../../config.php');
|
||||
require_once("$CFG->libdir/clilib.php");
|
||||
require_once("$CFG->libdir/adminlib.php");
|
||||
|
||||
|
||||
// now get cli options
|
||||
list($options, $unrecognized) = cli_get_params(array('enable'=>false, 'disable'=>false, 'help'=>false),
|
||||
// Now get cli options.
|
||||
list($options, $unrecognized) = cli_get_params(array('enable'=>false, 'enablelater'=>0, 'enableold'=>false, 'disable'=>false, 'help'=>false),
|
||||
array('h'=>'help'));
|
||||
|
||||
if ($unrecognized) {
|
||||
@ -45,12 +45,14 @@ if ($options['help']) {
|
||||
Current status displayed if not option specified.
|
||||
|
||||
Options:
|
||||
--enable Enable maintenance mode
|
||||
--enable Enable CLI maintenance mode
|
||||
--enablelater=MINUTES Number of minutes before entering CLI maintenance mode
|
||||
--enableold Enable legacy half-maintenance mode
|
||||
--disable Disable maintenance mode
|
||||
-h, --help Print out this help
|
||||
|
||||
Example:
|
||||
\$sudo -u www-data /usr/bin/php admin/cli/maintenance.php
|
||||
\$ sudo -u www-data /usr/bin/php admin/cli/maintenance.php
|
||||
"; //TODO: localize - to be translated later when everything is finished
|
||||
|
||||
echo $help;
|
||||
@ -59,18 +61,52 @@ Example:
|
||||
|
||||
cli_heading(get_string('sitemaintenancemode', 'admin')." ($CFG->wwwroot)");
|
||||
|
||||
if ($options['enable']) {
|
||||
if ($options['enablelater']) {
|
||||
if (file_exists("$CFG->dataroot/climaintenance.html")) {
|
||||
// Already enabled, sorry.
|
||||
echo get_string('clistatusenabled', 'admin')."\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
$time = time() + ($options['enablelater']*60);
|
||||
set_config('maintenance_later', $time);
|
||||
|
||||
echo get_string('clistatusenabledlater', 'admin', userdate($time))."\n";
|
||||
return 0;
|
||||
|
||||
} else if ($options['enable']) {
|
||||
if (file_exists("$CFG->dataroot/climaintenance.html")) {
|
||||
// The maintenance is already enabled, nothing to do.
|
||||
} else {
|
||||
enable_cli_maintenance_mode();
|
||||
}
|
||||
set_config('maintenance_enabled', 0);
|
||||
unset_config('maintenance_later');
|
||||
echo get_string('sitemaintenanceoncli', 'admin')."\n";
|
||||
exit(0);
|
||||
|
||||
} else if ($options['enableold']) {
|
||||
set_config('maintenance_enabled', 1);
|
||||
unset_config('maintenance_later');
|
||||
echo get_string('sitemaintenanceon', 'admin')."\n";
|
||||
exit(0);
|
||||
|
||||
} else if ($options['disable']) {
|
||||
set_config('maintenance_enabled', 0);
|
||||
unset_config('maintenance_later');
|
||||
if (file_exists("$CFG->dataroot/climaintenance.html")) {
|
||||
unlink("$CFG->dataroot/climaintenance.html");
|
||||
}
|
||||
echo get_string('sitemaintenanceoff', 'admin')."\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!empty($CFG->maintenance_enabled)) {
|
||||
if (!empty($CFG->maintenance_enabled) or file_exists("$CFG->dataroot/climaintenance.html")) {
|
||||
echo get_string('clistatusenabled', 'admin')."\n";
|
||||
|
||||
} else if (isset($CFG->maintenance_later)) {
|
||||
echo get_string('clistatusenabledlater', 'admin', userdate($CFG->maintenance_later))."\n";
|
||||
|
||||
} else {
|
||||
echo get_string('clistatusdisabled', 'admin')."\n";
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ $string['cliincorrectvalueerror'] = 'Error, incorrect value "{$a->value}" for "{
|
||||
$string['cliincorrectvalueretry'] = 'Incorrect value, please retry';
|
||||
$string['clistatusdisabled'] = 'Status: disabled';
|
||||
$string['clistatusenabled'] = 'Status: enabled';
|
||||
$string['clistatusenabledlater'] = 'status: CLI maintenance mode will be enabled on {$a}';
|
||||
$string['clitypevalue'] = 'type value';
|
||||
$string['clitypevaluedefault'] = 'type value, press Enter to use default value ({$a})';
|
||||
$string['cliunknowoption'] = 'Unrecognised options:
|
||||
@ -664,6 +665,7 @@ $string['loginpasswordautocomplete_help'] = 'Having this off will let users save
|
||||
$string['loglifetime'] = 'Keep logs for';
|
||||
$string['longtimewarning'] = '<b>Please note that this process can take a long time.</b>';
|
||||
$string['maintenancemode'] = 'In maintenance mode';
|
||||
$string['maintenancemodeisscheduled'] = 'Site is switching to maintenance mode in {$a} minutes';
|
||||
$string['maintfileopenerror'] = 'Error opening maintenance files!';
|
||||
$string['maintinprogress'] = 'Maintenance is in progress...';
|
||||
$string['manageformats'] = 'Manage course formats';
|
||||
@ -955,6 +957,7 @@ $string['sitemaintenance'] = 'The site is undergoing maintenance and is currentl
|
||||
$string['sitemaintenancemode'] = 'Maintenance mode';
|
||||
$string['sitemaintenanceoff'] = 'Maintenance mode has been disabled and the site is running normally again';
|
||||
$string['sitemaintenanceon'] = 'Your site is currently in maintenance mode (only admins can log in or use the site).';
|
||||
$string['sitemaintenanceoncli'] = 'Your site is currently in CLI maintenance mode, no web access is allowed.';
|
||||
$string['sitemaintenancewarning'] = 'Your site is currently in maintenance mode (only admins can log in). To return this site to normal operation, <a href="maintenance.php">disable maintenance mode</a>.';
|
||||
$string['sitemaintenancewarning2'] = 'Your site is currently in maintenance mode (only admins can log in). To return this site to normal operation, <a href="{$a}">disable maintenance mode</a>.';
|
||||
$string['sitepolicies'] = 'Site policies';
|
||||
|
@ -679,6 +679,34 @@ function is_dataroot_insecure($fetchtest=false) {
|
||||
return INSECURE_DATAROOT_WARNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables CLI maintenance mode by creating new dataroot/climaintenance.html file.
|
||||
*/
|
||||
function enable_cli_maintenance_mode() {
|
||||
global $CFG;
|
||||
|
||||
if (file_exists("$CFG->dataroot/climaintenance.html")) {
|
||||
unlink("$CFG->dataroot/climaintenance.html");
|
||||
}
|
||||
|
||||
if (isset($CFG->maintenance_message) and !html_is_blank($CFG->maintenance_message)) {
|
||||
$data = $CFG->maintenance_message;
|
||||
$data = bootstrap_renderer::early_error_content($data, null, null, null);
|
||||
$data = bootstrap_renderer::plain_page(get_string('sitemaintenance', 'admin'), $data);
|
||||
|
||||
} else if (file_exists("$CFG->dataroot/climaintenance.template.html")) {
|
||||
$data = file_get_contents("$CFG->dataroot/climaintenance.template.html");
|
||||
|
||||
} else {
|
||||
$data = get_string('sitemaintenance', 'admin');
|
||||
$data = bootstrap_renderer::early_error_content($data, null, null, null);
|
||||
$data = bootstrap_renderer::plain_page(get_string('sitemaintenance', 'admin'), $data);
|
||||
}
|
||||
|
||||
file_put_contents("$CFG->dataroot/climaintenance.html", $data);
|
||||
chmod("$CFG->dataroot/climaintenance.html", $CFG->filepermissions);
|
||||
}
|
||||
|
||||
/// CLASS DEFINITIONS /////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
@ -428,6 +428,27 @@ class core_renderer extends renderer_base {
|
||||
if (!empty($CFG->additionalhtmltopofbody)) {
|
||||
$output .= "\n".$CFG->additionalhtmltopofbody;
|
||||
}
|
||||
$output .= $this->maintenance_warning();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scheduled maintenance warning message.
|
||||
*
|
||||
* Note: This is a nasty hack to display maintenance notice, this should be moved
|
||||
* to some general notification area once we have it.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function maintenance_warning() {
|
||||
global $CFG;
|
||||
|
||||
$output = '';
|
||||
if (isset($CFG->maintenance_later) and $CFG->maintenance_later > time()) {
|
||||
$output .= $this->box_start('errorbox maintenancewarning');
|
||||
$output .= get_string('maintenancemodeisscheduled', 'admin', (int)(($CFG->maintenance_later-time())/60));
|
||||
$output .= $this->box_end();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
@ -888,6 +888,19 @@ if (!empty($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],
|
||||
}
|
||||
}
|
||||
|
||||
// Switch to CLI maintenance mode if required, we need to do it here after all the settings are initialised.
|
||||
if (isset($CFG->maintenance_later) and $CFG->maintenance_later <= time()) {
|
||||
if (!file_exists("$CFG->dataroot/climaintenance.html")) {
|
||||
require_once("$CFG->libdir/adminlib.php");
|
||||
enable_cli_maintenance_mode();
|
||||
}
|
||||
unset_config('maintenance_later');
|
||||
if (AJAX_SCRIPT) {
|
||||
die;
|
||||
} else if (!CLI_SCRIPT) {
|
||||
redirect(new moodle_url('/'));
|
||||
}
|
||||
}
|
||||
|
||||
// note: we can not block non utf-8 installations here, because empty mysql database
|
||||
// might be converted to utf-8 in admin/index.php during installation
|
||||
|
@ -1596,15 +1596,15 @@ width: 80%; -moz-border-radius: 20px; padding: 15px">
|
||||
* @param string $meta meta tag
|
||||
* @return string html page
|
||||
*/
|
||||
protected static function plain_page($title, $content, $meta = '') {
|
||||
public static function plain_page($title, $content, $meta = '') {
|
||||
if (function_exists('get_string') && function_exists('get_html_lang')) {
|
||||
$htmllang = get_html_lang();
|
||||
} else {
|
||||
$htmllang = '';
|
||||
}
|
||||
|
||||
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" ' . $htmllang . '>
|
||||
return '<!DOCTYPE html>
|
||||
<html ' . $htmllang . '>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
'.$meta.'
|
||||
|
Loading…
x
Reference in New Issue
Block a user