MDL-58659 enroll: Add start and end date fields required by overview
[moodle.git] / admin / cli / maintenance.php
blobb267a039c310d76474f278e675f6d95014385277
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Enable or disable maintenance mode.
20 * @package core
21 * @subpackage cli
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 define('CLI_SCRIPT', true);
28 require(__DIR__.'/../../config.php');
29 require_once("$CFG->libdir/clilib.php");
30 require_once("$CFG->libdir/adminlib.php");
33 // Now get cli options.
34 list($options, $unrecognized) = cli_get_params(array('enable'=>false, 'enablelater'=>0, 'enableold'=>false, 'disable'=>false, 'help'=>false),
35 array('h'=>'help'));
37 if ($unrecognized) {
38 $unrecognized = implode("\n ", $unrecognized);
39 cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
42 if ($options['help']) {
43 $help =
44 "Maintenance mode settings.
45 Current status displayed if not option specified.
47 Options:
48 --enable Enable CLI maintenance mode
49 --enablelater=MINUTES Number of minutes before entering CLI maintenance mode
50 --enableold Enable legacy half-maintenance mode
51 --disable Disable maintenance mode
52 -h, --help Print out this help
54 Example:
55 \$ sudo -u www-data /usr/bin/php admin/cli/maintenance.php
56 "; //TODO: localize - to be translated later when everything is finished
58 echo $help;
59 die;
62 cli_heading(get_string('sitemaintenancemode', 'admin')." ($CFG->wwwroot)");
64 if ($options['enablelater']) {
65 if (file_exists("$CFG->dataroot/climaintenance.html")) {
66 // Already enabled, sorry.
67 echo get_string('clistatusenabled', 'admin')."\n";
68 return 1;
71 $time = time() + ($options['enablelater']*60);
72 set_config('maintenance_later', $time);
74 echo get_string('clistatusenabledlater', 'admin', userdate($time))."\n";
75 return 0;
77 } else if ($options['enable']) {
78 if (file_exists("$CFG->dataroot/climaintenance.html")) {
79 // The maintenance is already enabled, nothing to do.
80 } else {
81 enable_cli_maintenance_mode();
83 set_config('maintenance_enabled', 0);
84 unset_config('maintenance_later');
85 echo get_string('sitemaintenanceoncli', 'admin')."\n";
86 exit(0);
88 } else if ($options['enableold']) {
89 set_config('maintenance_enabled', 1);
90 unset_config('maintenance_later');
91 echo get_string('sitemaintenanceon', 'admin')."\n";
92 exit(0);
94 } else if ($options['disable']) {
95 set_config('maintenance_enabled', 0);
96 unset_config('maintenance_later');
97 if (file_exists("$CFG->dataroot/climaintenance.html")) {
98 unlink("$CFG->dataroot/climaintenance.html");
100 echo get_string('sitemaintenanceoff', 'admin')."\n";
101 exit(0);
104 if (!empty($CFG->maintenance_enabled) or file_exists("$CFG->dataroot/climaintenance.html")) {
105 echo get_string('clistatusenabled', 'admin')."\n";
107 } else if (isset($CFG->maintenance_later)) {
108 echo get_string('clistatusenabledlater', 'admin', userdate($CFG->maintenance_later))."\n";
110 } else {
111 echo get_string('clistatusdisabled', 'admin')."\n";