Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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.
13
//
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/>.
16
 
17
/**
18
 * Enable or disable maintenance mode.
19
 *
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
24
 */
25
 
26
define('CLI_SCRIPT', true);
27
 
28
require(__DIR__.'/../../config.php');
29
require_once("$CFG->libdir/clilib.php");
30
require_once("$CFG->libdir/adminlib.php");
31
 
32
 
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'));
36
 
37
if ($unrecognized) {
38
    $unrecognized = implode("\n  ", $unrecognized);
39
    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
40
}
41
 
42
if ($options['help']) {
43
    $help =
44
"Maintenance mode settings.
45
Current status displayed if not option specified.
46
 
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
53
 
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
57
 
58
    echo $help;
59
    die;
60
}
61
 
62
cli_heading(get_string('sitemaintenancemode', 'admin')." ($CFG->wwwroot)");
63
 
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;
69
    }
70
 
71
    $time = time() + ($options['enablelater']*60);
1441 ariadna 72
    set_config('maintenance_later', $time, null, true);
1 efrain 73
 
74
    echo get_string('clistatusenabledlater', 'admin', userdate($time))."\n";
75
    return 0;
76
 
77
} else if ($options['enable']) {
78
    if (file_exists("$CFG->dataroot/climaintenance.html")) {
79
        // The maintenance is already enabled, nothing to do.
1441 ariadna 80
        exit(0);
1 efrain 81
    }
1441 ariadna 82
    enable_cli_maintenance_mode();
83
    set_config('maintenance_enabled', 'cli mode', null, true);
84
 
85
    if (isset($CFG->maintenance_later)) {
86
        unset_config('maintenance_later', null, true);
87
    }
1 efrain 88
    echo get_string('sitemaintenanceoncli', 'admin')."\n";
89
    exit(0);
90
 
91
} else if ($options['enableold']) {
1441 ariadna 92
    set_config('maintenance_enabled', 1, null, true);
93
    if (isset($CFG->maintenance_later)) {
94
        unset_config('maintenance_later', null, true);
95
    }
1 efrain 96
    echo get_string('sitemaintenanceon', 'admin')."\n";
97
    exit(0);
98
 
99
} else if ($options['disable']) {
1441 ariadna 100
    if ($CFG->maintenance_enabled !== '0') {
101
        set_config('maintenance_enabled', 0, null, true);
102
    }
103
    if (isset($CFG->maintenance_later)) {
104
        unset_config('maintenance_later', null, true);
105
    }
1 efrain 106
    if (file_exists("$CFG->dataroot/climaintenance.html")) {
107
        unlink("$CFG->dataroot/climaintenance.html");
108
    }
109
    echo get_string('sitemaintenanceoff', 'admin')."\n";
110
    exit(0);
111
}
112
 
113
if (!empty($CFG->maintenance_enabled) or file_exists("$CFG->dataroot/climaintenance.html")) {
114
    echo get_string('clistatusenabled', 'admin')."\n";
115
 
116
} else if (isset($CFG->maintenance_later)) {
117
    echo get_string('clistatusenabledlater', 'admin', userdate($CFG->maintenance_later))."\n";
118
 
119
} else {
120
    echo get_string('clistatusdisabled', 'admin')."\n";
121
}