Commit | Line | Data |
---|---|---|
3b596dbf | 1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * This script creates config.php file and prepares database. | |
20 | * | |
21 | * This script is not intended for beginners! | |
22 | * Potential problems: | |
23 | * - environment check is not present yet | |
24 | * - su to apache account or sudo before execution | |
25 | * - not compatible with Windows platform | |
26 | * | |
30f58159 | 27 | * @package core |
3b596dbf | 28 | * @subpackage cli |
29 | * @copyright 2009 Petr Skoda (http://skodak.org) | |
30 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
31 | */ | |
32 | ||
28bd3d9a | 33 | define('CLI_SCRIPT', true); |
3b596dbf | 34 | |
28bd3d9a | 35 | require(dirname(dirname(dirname(__FILE__))).'/config.php'); |
16ae0853 | 36 | require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions |
37 | require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions | |
38 | require_once($CFG->libdir.'/clilib.php'); // cli only functions | |
39 | require_once($CFG->libdir.'/environmentlib.php'); | |
3b596dbf | 40 | |
41 | ||
42 | // now get cli options | |
43 | list($options, $unrecognized) = cli_get_params(array('non-interactive'=>false, 'help'=>false), | |
44 | array('h'=>'help')); | |
45 | ||
46 | $interactive = empty($options['non-interactive']); | |
47 | ||
48 | if ($unrecognized) { | |
6b997b07 | 49 | $unrecognized = implode("\n ", $unrecognized); |
1494616f | 50 | cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); |
3b596dbf | 51 | } |
52 | ||
53 | if ($options['help']) { | |
28bd3d9a | 54 | $help = |
3b596dbf | 55 | "Command line Moodle upgrade. |
56 | Please note you must execute this script with the same uid as apache! | |
57 | ||
58 | Site defaults may be changed via local/defaults.php. | |
59 | ||
60 | Options: | |
61 | --non-interactive No interactive questions or confirmations | |
62 | -h, --help Print out this help | |
63 | ||
28bd3d9a PS |
64 | Example: |
65 | \$sudo -u www-data /usr/bin/php admin/cli/upgrade.php | |
71d54993 | 66 | "; //TODO: localize - to be translated later when everything is finished |
3b596dbf | 67 | |
68 | echo $help; | |
69 | die; | |
70 | } | |
71 | ||
72 | if (empty($CFG->version)) { | |
6b997b07 | 73 | cli_error(get_string('missingconfigversion', 'debug')); |
3b596dbf | 74 | } |
75 | ||
76 | require("$CFG->dirroot/version.php"); // defines $version and $release | |
77 | $CFG->target_release = $release; // used during installation and upgrades | |
78 | ||
79 | if ($version < $CFG->version) { | |
80380bd7 | 80 | cli_error(get_string('downgradedcore', 'error')); |
3b596dbf | 81 | } |
82 | ||
6b997b07 | 83 | $newversion = "$release ($version)"; |
84 | ||
16ae0853 | 85 | // test environment first |
86 | if (!check_moodle_environment($version, $environment_results, false, ENV_SELECT_RELEASE)) { | |
87 | $errors = environment_get_errors($environment_results); | |
88 | cli_heading(get_string('environment', 'admin')); | |
89 | foreach ($errors as $error) { | |
90 | list($info, $report) = $error; | |
91 | echo "!! $info !!\n$report\n\n"; | |
92 | } | |
93 | exit(1); | |
94 | } | |
95 | ||
3b596dbf | 96 | if ($interactive) { |
6b997b07 | 97 | echo html_to_text(get_string('upgradesure', 'admin', $newversion))."\n"; |
98 | $prompt = get_string('cliyesnoprompt', 'admin'); | |
99 | $input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin'))); | |
100 | if ($input == get_string('clianswerno', 'admin')) { | |
101 | exit(1); | |
102 | } | |
3b596dbf | 103 | } |
104 | ||
105 | if ($version > $CFG->version) { | |
106 | upgrade_core($version, true); | |
107 | } | |
108 | set_config('release', $release); | |
109 | ||
deba811a | 110 | // unconditionally upgrade |
3b596dbf | 111 | upgrade_noncore(true); |
112 | ||
113 | // log in as admin - we need doanything permission when applying defaults | |
114 | $admins = get_admins(); | |
115 | $admin = reset($admins); | |
116 | session_set_user($admin); | |
117 | ||
118 | // apply all default settings, just in case do it twice to fill all defaults | |
054d3924 EL |
119 | admin_apply_default_settings(NULL, false); |
120 | admin_apply_default_settings(NULL, false); | |
3b596dbf | 121 | |
6b997b07 | 122 | echo get_string('cliupgradefinished', 'admin')."\n"; |
123 | exit(0); // 0 means success |