]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19352 maintenance mode reiplemented
authorskodak <skodak>
Sun, 31 May 2009 14:42:29 +0000 (14:42 +0000)
committerskodak <skodak>
Sun, 31 May 2009 14:42:29 +0000 (14:42 +0000)
admin/cli/maintenance.php [new file with mode: 0644]
admin/index.php
admin/maintenance.php [deleted file]
admin/settings/server.php
backup/restorelib.php
index.php
lang/en_utf8/admin.php
lib/adminlib.php
lib/moodlelib.php
lib/weblib.php

diff --git a/admin/cli/maintenance.php b/admin/cli/maintenance.php
new file mode 100644 (file)
index 0000000..0d499af
--- /dev/null
@@ -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
+}
index 00e5ec9ad387491c93b43d72cc7c50e65da7d2f4..c78c2efa71dd4f112584726460cc55213d07433c 100644 (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');
 }
 
 
diff --git a/admin/maintenance.php b/admin/maintenance.php
deleted file mode 100644 (file)
index a726f1a..0000000
+++ /dev/null
@@ -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();
-?>
index 6336c771b314def1d962f0f4d207aa30eccc2d68..34341dcf51d3001fd7096f7e18b7c8e76cf1ea89 100644 (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'),
index de34e0245f8066eca4c44b4fa9c9291e99e9eb02..7d731e8f4f30fe008bd0de81452704dfacf5237b 100644 (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)) {
index 6c9d7a45355867aac3b7c23af6eb94612cdceee1..d40f73e052802839f740a142c1e3e03191db976e 100644 (file)
--- a/index.php
+++ b/index.php
         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');
         }
     }
index 04f16d48685d4fd6fa690f275c9ecb9de30daac0..0fde5d380746b5325a076d7caec71925142fa2aa 100644 (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.';
index 69e75faeb0cbf83cd562ca41954d64f9b9c39bd3..90272e5528a2673b6c62aac11a9431a3e1e587e3 100644 (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);
     }
 }
index 8ea7e01f063a76e565ca01ce14148379d241a28f..b1e8c5f1b0a8f670c42fcb4aa7e3c760cfa9cd66 100644 (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
index c484734512482f668c25e4af4ccfac5e4551f8d2..c2289b69db46d0953f9c8ad4f1652e4cd21f90c9 100644 (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;
 }
 
 /**