|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00032 define('CLI_SCRIPT', true); 00033 00034 require(dirname(dirname(dirname(__FILE__))).'/config.php'); 00035 require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions 00036 require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions 00037 require_once($CFG->libdir.'/clilib.php'); // cli only functions 00038 require_once($CFG->libdir.'/environmentlib.php'); 00039 require_once($CFG->libdir.'/pluginlib.php'); 00040 00041 // now get cli options 00042 list($options, $unrecognized) = cli_get_params( 00043 array( 00044 'non-interactive' => false, 00045 'allow-unstable' => false, 00046 'help' => false 00047 ), 00048 array( 00049 'h' => 'help' 00050 ) 00051 ); 00052 00053 $interactive = empty($options['non-interactive']); 00054 00055 if ($unrecognized) { 00056 $unrecognized = implode("\n ", $unrecognized); 00057 cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); 00058 } 00059 00060 if ($options['help']) { 00061 $help = 00062 "Command line Moodle upgrade. 00063 Please note you must execute this script with the same uid as apache! 00064 00065 Site defaults may be changed via local/defaults.php. 00066 00067 Options: 00068 --non-interactive No interactive questions or confirmations 00069 --allow-unstable Upgrade even if the version is not marked as stable yet, 00070 required in non-interactive mode. 00071 -h, --help Print out this help 00072 00073 Example: 00074 \$sudo -u www-data /usr/bin/php admin/cli/upgrade.php 00075 "; //TODO: localize - to be translated later when everything is finished 00076 00077 echo $help; 00078 die; 00079 } 00080 00081 if (empty($CFG->version)) { 00082 cli_error(get_string('missingconfigversion', 'debug')); 00083 } 00084 00085 require("$CFG->dirroot/version.php"); // defines $version, $release and $maturity 00086 $CFG->target_release = $release; // used during installation and upgrades 00087 00088 if ($version < $CFG->version) { 00089 cli_error(get_string('downgradedcore', 'error')); 00090 } 00091 00092 $oldversion = "$CFG->release ($CFG->version)"; 00093 $newversion = "$release ($version)"; 00094 00095 // Test environment first. 00096 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); 00097 if (!$envstatus) { 00098 $errors = environment_get_errors($environment_results); 00099 cli_heading(get_string('environment', 'admin')); 00100 foreach ($errors as $error) { 00101 list($info, $report) = $error; 00102 echo "!! $info !!\n$report\n\n"; 00103 } 00104 exit(1); 00105 } 00106 00107 // Test plugin dependencies. 00108 if (!plugin_manager::instance()->all_plugins_ok($version)) { 00109 cli_error(get_string('pluginschecktodo', 'admin')); 00110 } 00111 00112 if ($interactive) { 00113 $a = new stdClass(); 00114 $a->oldversion = $oldversion; 00115 $a->newversion = $newversion; 00116 echo cli_heading(get_string('databasechecking', '', $a)) . PHP_EOL; 00117 } 00118 00119 // make sure we are upgrading to a stable release or display a warning 00120 if (isset($maturity)) { 00121 if (($maturity < MATURITY_STABLE) and !$options['allow-unstable']) { 00122 $maturitylevel = get_string('maturity'.$maturity, 'admin'); 00123 00124 if ($interactive) { 00125 cli_separator(); 00126 cli_heading(get_string('notice')); 00127 echo get_string('maturitycorewarning', 'admin', $maturitylevel) . PHP_EOL; 00128 echo get_string('morehelp') . ': ' . get_docs_url('admin/versions') . PHP_EOL; 00129 cli_separator(); 00130 } else { 00131 cli_error(get_string('maturitycorewarning', 'admin', $maturitylevel)); 00132 } 00133 } 00134 } 00135 00136 if ($interactive) { 00137 echo html_to_text(get_string('upgradesure', 'admin', $newversion))."\n"; 00138 $prompt = get_string('cliyesnoprompt', 'admin'); 00139 $input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin'))); 00140 if ($input == get_string('clianswerno', 'admin')) { 00141 exit(1); 00142 } 00143 } 00144 00145 if ($version > $CFG->version) { 00146 upgrade_core($version, true); 00147 } 00148 set_config('release', $release); 00149 00150 // unconditionally upgrade 00151 upgrade_noncore(true); 00152 00153 // log in as admin - we need doanything permission when applying defaults 00154 $admins = get_admins(); 00155 $admin = reset($admins); 00156 session_set_user($admin); 00157 00158 // apply all default settings, just in case do it twice to fill all defaults 00159 admin_apply_default_settings(NULL, false); 00160 admin_apply_default_settings(NULL, false); 00161 00162 echo get_string('cliupgradefinished', 'admin')."\n"; 00163 exit(0); // 0 means success