MDL-19352 maintenance mode reiplemented

This commit is contained in:
skodak 2009-05-31 14:42:29 +00:00
parent 926378ce4d
commit 4fe2250a1f
10 changed files with 154 additions and 107 deletions

78
admin/cli/maintenance.php Normal file
View File

@ -0,0 +1,78 @@
<?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/>.
/**
* Enable or disable maintenance mode
*
* @package moodlecore
* @subpackage cli
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (isset($_SERVER['REMOTE_ADDR'])) {
error_log("admin/cli/maintenance.php can not be called from web server!");
exit;
}
require_once dirname(dirname(dirname(__FILE__))).'/config.php';
require_once($CFG->libdir.'/clilib.php'); // cli only functions
// now get cli options
list($options, $unrecognized) = cli_get_params(array('enable'=>false, 'disable'=>false, 'help'=>false),
array('h'=>'help'));
if ($unrecognized) {
$unrecognized = implode("\n ", $unrecognized);
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
if ($options['help']) {
$help =
"Maintenance mode settings.
Current status displayed if not option specified.
Options:
--enable Enable maintenance mode
--disable Disable maintenance mode
-h, --help Print out this help
Example: \$sudo -u wwwrun /usr/bin/php admin/cli/maintenance.php
"; //TODO: localize - to be translated later when everything is finished
echo $help;
die;
}
cli_heading(get_string('sitemaintenancemode', 'admin')." ($CFG->wwwroot)");
if ($options['enable']) {
set_config('maintenance_enabled', 1);
echo get_string('sitemaintenanceon', 'admin')."\n";
exit(0);
} else if ($options['disable']) {
set_config('maintenance_enabled', 0);
echo get_string('sitemaintenanceoff', 'admin')."\n";
exit(0);
}
if (!empty($CFG->maintenance_enabled)) {
echo "Status: enabled\n"; // TODO: localize
} else {
echo "Status: disabled\n"; // TODO: localize
}

View File

@ -357,9 +357,8 @@ if (empty($CFG->filter_multilang_converted)) {
}
// Alert if we are currently in maintenance mode
// TODO: we are not using coursefiles directories anymore anymore - needs rewrite
if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
print_box(get_string('sitemaintenancewarning', 'admin'), 'generalbox adminwarning');
if (!empty($CFG->maintenance_enabled)) {
print_box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
}

View File

@ -1,76 +0,0 @@
<?php // $Id$
// Enables/disables maintenance mode
require('../config.php');
require_once($CFG->libdir.'/adminlib.php');
die('TODO: This needs to be reimplemented, probably via new cli script and $CFG->maintenance setting');
$action = optional_param('action', '', PARAM_ALPHA);
admin_externalpage_setup('maintenancemode');
//Check folder exists
if (! make_upload_directory(SITEID)) { // Site folder
print_error('cannotcreatesitedir', 'error');
}
$filename = $CFG->dataroot.'/'.SITEID.'/maintenance.html';
if ($form = data_submitted()) {
if (confirm_sesskey()) {
if ($form->action == "disable") {
unlink($filename);
redirect('maintenance.php', get_string('sitemaintenanceoff','admin'));
} else {
$file = fopen($filename, 'w');
fwrite($file, $form->text);
fclose($file);
redirect('maintenance.php', get_string('sitemaintenanceon', 'admin'));
}
}
}
/// Print the header stuff
admin_externalpage_print_header();
print_heading(get_string('sitemaintenancemode', 'admin'));
print_box_start();
/// Print the appropriate form
if (file_exists($filename)) { // We are in maintenance mode
echo '<div class="buttons">';
echo '<p>'.get_string('sitemaintenanceon', 'admin').'</p>';
echo '<form action="maintenance.php" method="post">';
echo '<div>';
echo '<input type="hidden" name="action" value="disable" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<p><input type="submit" value="'.get_string('disable').'" /></p>';
echo '</div>';
echo '</form>';
echo '</div>';
} else { // We are not in maintenance mode
$usehtmleditor = can_use_html_editor();
echo '<div class="buttons">';
echo '<form action="maintenance.php" method="post">';
echo '<div>';
echo '<input type="hidden" name="action" value="enable" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<p><input type="submit" value="'.get_string('enable').'" /></p>';
echo '<p>'.get_string('optionalmaintenancemessage', 'admin').':</p>';
echo '<div class="editor" style="width:600px;">'; // contains the editor
print_textarea($usehtmleditor, 20, 50, 600, 400, "text");
echo '</div>';
echo '</div>';
echo '</form>';
echo '</div>';
}
print_box_end();
admin_externalpage_print_footer();
?>

View File

@ -159,7 +159,13 @@ $temp->add(new admin_setting_configpasswordunmask('proxypassword', get_string('p
$temp->add(new admin_setting_configtext('proxybypass', get_string('proxybypass', 'admin'), get_string('configproxybypass', 'admin'), 'localhost, 127.0.0.1'));
$ADMIN->add('server', $temp);
$ADMIN->add('server', new admin_externalpage('maintenancemode', get_string('sitemaintenancemode', 'admin'), "$CFG->wwwroot/$CFG->admin/maintenance.php"));
$temp = new admin_settingpage('maintenancemode', get_string('sitemaintenancemode', 'admin'));
$options = array(0=>get_string('disable'), 1=>get_string('enable'));
$temp->add(new admin_setting_configselect('maintenance_enabled', get_string('sitemaintenancemode', 'admin'),
get_string('helpsitemaintenance', 'admin'), 0, $options));
$temp->add(new admin_setting_confightmleditor('maintenance_message', get_string('optionalmaintenancemessage', 'admin'),
'', ''));
$ADMIN->add('server', $temp);
$temp = new admin_settingpage('cleanup', get_string('cleanup', 'admin'));
$temp->add(new admin_setting_configselect('longtimenosee', get_string('longtimenosee', 'admin'), get_string('configlongtimenosee', 'admin'), 120, array(0 => get_string('never'),

View File

@ -4092,10 +4092,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//Iterate
$counter = 0;
foreach ($list as $dir) {
//Avoid copying maintenance.html. MDL-18594
if ($dir == 'maintenance.html') {
continue;
}
//no need to deal with 'maintenance.html' here anymore - MDL-18594
//Copy the dir to its new location
//Only if destination file/dir doesn exists
if (!file_exists($dest_dir."/".$dir)) {

View File

@ -58,12 +58,17 @@
user_accesstime_log();
}
/// If the site is currently under maintenance, then print a message
if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
print_maintenance_message();
}
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
if (moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}
} else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required
if (isloggedin() && $USER->username != 'guest') {
if (isloggedin() && !isguestuser()) {
redirect($CFG->wwwroot .'/my/index.php');
}
}

View File

@ -778,6 +778,7 @@ $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['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';
$string['sitepolicy'] = 'Site policy URL';
$string['sitesectionhelp'] = 'If selected, a topic section will be displayed on the site\'s front page.';

View File

@ -1560,11 +1560,8 @@ class admin_setting_configtext extends admin_setting {
* @package moodlecore
*/
class admin_setting_configtextarea extends admin_setting_configtext {
/**
* @var string Represents the number of rows/cols to make the editor
*/
public $rows;
public $cols;
private $rows;
private $cols;
/**
* @param string $name
@ -1596,7 +1593,50 @@ class admin_setting_configtextarea extends admin_setting_configtext {
}
return format_admin_setting($this, $this->visiblename,
'<div class="form-textarea form-textarea-advanced" ><textarea rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'">'. s($data) .'</textarea></div>',
'<div class="form-textarea" ><textarea rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'">'. s($data) .'</textarea></div>',
$this->description, true, '', $defaultinfo, $query);
}
}
/**
* General text area with html editor.
*/
class admin_setting_confightmleditor extends admin_setting_configtext {
private $rows;
private $cols;
/**
* @param string $name
* @param string $visiblename
* @param string $description
* @param mixed $defaultsetting string or array
* @param mixed $paramtype
*/
public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $cols='60', $rows='8') {
$this->rows = $rows;
$this->cols = $cols;
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
}
/**
* Returns an XHTML string for the editor
*
* @param string $data
* @param string $query
* @return string XHTML string for the editor
*/
public function output_html($data, $query='') {
$default = $this->get_defaultsetting();
$defaultinfo = $default;
if (!is_null($default) and $default !== '') {
$defaultinfo = "\n".$default;
}
$editor = get_preferred_texteditor(FORMAT_HTML);
$editorclass = $editor->get_legacy_textarea_class();
return format_admin_setting($this, $this->visiblename,
'<div class="form-textarea"><textarea class="'.$editorclass.'" rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'">'. s($data) .'</textarea></div>',
$this->description, true, '', $defaultinfo, $query);
}
}

View File

@ -2077,11 +2077,8 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu
$sysctx = get_context_instance(CONTEXT_SYSTEM);
/// If the site is currently under maintenance, then print a message
if (!has_capability('moodle/site:config', $sysctx)) {
if (file_exists($CFG->dataroot.'/'.SITEID.'/maintenance.html')) {
print_maintenance_message();
exit;
}
if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', $sysctx)) {
print_maintenance_message();
}
/// groupmembersonly access control

View File

@ -2435,8 +2435,8 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
$button = '&nbsp;';
}
if (file_exists($CFG->dataroot.'/'.SITEID.'/maintenance.html')) {
$button = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/maintenance.php">'.get_string('maintenancemode', 'admin').'</a> '.$button;
if (!empty($CFG->maintenance_enabled)) {
$button = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=maintenancemode">'.get_string('maintenancemode', 'admin').'</a> '.$button;
if(!empty($title)) {
$title .= ' - ';
}
@ -6923,22 +6923,22 @@ function page_id_and_class(&$getid, &$getclass) {
}
/**
* Prints a maintenance message from /maintenance.html
*
* @global object
* @global object
* Prints a maintenance message from $CFG->maintenance_message or default if empty
* @return void
*/
function print_maintenance_message () {
global $CFG, $SITE;
function print_maintenance_message() {
global $CFG, $SITE, $PAGE;
$PAGE->set_pagetype('maintenance-message');
print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home');
print_box_start();
print_heading(get_string('sitemaintenance', 'admin'));
@include($CFG->dataroot.'/1/maintenance.html');
print_box_end();
if (isset($CFG->maintenance_message) and !html_is_blank($CFG->maintenance_message)) {
print_box_start('maintenance_message generalbox boxwidthwide boxaligncenter');
echo $CFG->maintenance_message;
print_box_end();
}
print_footer();
die;
}
/**