2009-05-27 09:52:25 +00:00
|
|
|
<?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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This script creates config.php file and prepares database.
|
|
|
|
*
|
|
|
|
* This script is not intended for beginners!
|
|
|
|
* Potential problems:
|
|
|
|
* - su to apache account or sudo before execution
|
|
|
|
* - not compatible with Windows platform
|
|
|
|
*
|
2010-07-30 11:14:36 +00:00
|
|
|
* @package core
|
2009-05-27 09:52:25 +00:00
|
|
|
* @subpackage cli
|
|
|
|
* @copyright 2009 Petr Skoda (http://skodak.org)
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2013-07-01 21:06:44 +02:00
|
|
|
// Force OPcache reset if used, we do not want any stale caches
|
|
|
|
// when detecting if upgrade necessary or when running upgrade.
|
|
|
|
if (function_exists('opcache_reset') and !isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
opcache_reset();
|
|
|
|
}
|
|
|
|
|
2010-08-17 12:33:30 +00:00
|
|
|
define('CLI_SCRIPT', true);
|
2013-04-27 21:54:06 +02:00
|
|
|
define('CACHE_DISABLE_ALL', true);
|
2009-05-27 09:52:25 +00:00
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require(__DIR__.'/../../config.php');
|
2009-06-03 16:24:00 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
|
|
|
|
require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
|
|
|
|
require_once($CFG->libdir.'/clilib.php'); // cli only functions
|
|
|
|
require_once($CFG->libdir.'/environmentlib.php');
|
2009-05-27 09:52:25 +00:00
|
|
|
|
|
|
|
// now get cli options
|
2016-03-21 11:53:27 +08:00
|
|
|
$lang = isset($SESSION->lang) ? $SESSION->lang : $CFG->lang;
|
2011-02-25 23:39:42 +01:00
|
|
|
list($options, $unrecognized) = cli_get_params(
|
|
|
|
array(
|
|
|
|
'non-interactive' => false,
|
|
|
|
'allow-unstable' => false,
|
2016-03-10 21:55:54 +02:00
|
|
|
'help' => false,
|
2016-03-21 11:53:27 +08:00
|
|
|
'lang' => $lang
|
2011-02-25 23:39:42 +01:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'h' => 'help'
|
|
|
|
)
|
|
|
|
);
|
2009-05-27 09:52:25 +00:00
|
|
|
|
2016-03-10 21:55:54 +02:00
|
|
|
if ($options['lang']) {
|
|
|
|
$SESSION->lang = $options['lang'];
|
|
|
|
}
|
|
|
|
|
2009-05-27 09:52:25 +00:00
|
|
|
$interactive = empty($options['non-interactive']);
|
|
|
|
|
|
|
|
if ($unrecognized) {
|
2009-05-31 11:57:33 +00:00
|
|
|
$unrecognized = implode("\n ", $unrecognized);
|
2009-05-31 12:04:51 +00:00
|
|
|
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
|
2009-05-27 09:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($options['help']) {
|
2010-08-17 12:33:30 +00:00
|
|
|
$help =
|
2009-05-27 09:52:25 +00:00
|
|
|
"Command line Moodle upgrade.
|
|
|
|
Please note you must execute this script with the same uid as apache!
|
|
|
|
|
|
|
|
Site defaults may be changed via local/defaults.php.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--non-interactive No interactive questions or confirmations
|
2011-02-25 23:39:42 +01:00
|
|
|
--allow-unstable Upgrade even if the version is not marked as stable yet,
|
|
|
|
required in non-interactive mode.
|
2016-03-21 11:53:27 +08:00
|
|
|
--lang=CODE Set preferred language for CLI output. Defaults to the
|
2016-03-23 14:13:36 +08:00
|
|
|
site language if not set. Defaults to 'en' if the lang
|
|
|
|
parameter is invalid or if the language pack is not
|
|
|
|
installed.
|
2009-05-27 09:52:25 +00:00
|
|
|
-h, --help Print out this help
|
|
|
|
|
2010-08-17 12:33:30 +00:00
|
|
|
Example:
|
|
|
|
\$sudo -u www-data /usr/bin/php admin/cli/upgrade.php
|
2009-05-31 12:38:39 +00:00
|
|
|
"; //TODO: localize - to be translated later when everything is finished
|
2009-05-27 09:52:25 +00:00
|
|
|
|
|
|
|
echo $help;
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($CFG->version)) {
|
2009-05-31 11:57:33 +00:00
|
|
|
cli_error(get_string('missingconfigversion', 'debug'));
|
2009-05-27 09:52:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 14:05:40 +08:00
|
|
|
require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity
|
2009-05-27 09:52:25 +00:00
|
|
|
$CFG->target_release = $release; // used during installation and upgrades
|
|
|
|
|
|
|
|
if ($version < $CFG->version) {
|
2010-09-05 19:16:42 +00:00
|
|
|
cli_error(get_string('downgradedcore', 'error'));
|
2009-05-27 09:52:25 +00:00
|
|
|
}
|
|
|
|
|
2011-03-03 17:16:11 +01:00
|
|
|
$oldversion = "$CFG->release ($CFG->version)";
|
2009-05-31 11:57:33 +00:00
|
|
|
$newversion = "$release ($version)";
|
|
|
|
|
2012-03-01 01:56:53 +01:00
|
|
|
if (!moodle_needs_upgrading()) {
|
2012-03-07 10:58:56 +01:00
|
|
|
cli_error(get_string('cliupgradenoneed', 'core_admin', $newversion), 0);
|
2012-03-01 01:56:53 +01:00
|
|
|
}
|
|
|
|
|
2011-10-19 13:47:02 +01:00
|
|
|
// Test environment first.
|
2011-10-19 13:24:11 +01:00
|
|
|
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
|
|
|
|
if (!$envstatus) {
|
2009-06-03 16:24:00 +00:00
|
|
|
$errors = environment_get_errors($environment_results);
|
|
|
|
cli_heading(get_string('environment', 'admin'));
|
|
|
|
foreach ($errors as $error) {
|
|
|
|
list($info, $report) = $error;
|
|
|
|
echo "!! $info !!\n$report\n\n";
|
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-10-19 15:43:49 +01:00
|
|
|
// Test plugin dependencies.
|
2012-05-24 14:31:13 +02:00
|
|
|
$failed = array();
|
2013-10-04 22:40:44 +02:00
|
|
|
if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
|
2012-05-24 14:31:13 +02:00
|
|
|
cli_problem(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
|
2011-10-19 13:47:02 +01:00
|
|
|
cli_error(get_string('pluginschecktodo', 'admin'));
|
|
|
|
}
|
|
|
|
|
2011-03-03 17:16:11 +01:00
|
|
|
if ($interactive) {
|
|
|
|
$a = new stdClass();
|
|
|
|
$a->oldversion = $oldversion;
|
|
|
|
$a->newversion = $newversion;
|
|
|
|
echo cli_heading(get_string('databasechecking', '', $a)) . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
2011-02-25 23:39:42 +01:00
|
|
|
// make sure we are upgrading to a stable release or display a warning
|
|
|
|
if (isset($maturity)) {
|
|
|
|
if (($maturity < MATURITY_STABLE) and !$options['allow-unstable']) {
|
|
|
|
$maturitylevel = get_string('maturity'.$maturity, 'admin');
|
|
|
|
|
|
|
|
if ($interactive) {
|
|
|
|
cli_separator();
|
|
|
|
cli_heading(get_string('notice'));
|
|
|
|
echo get_string('maturitycorewarning', 'admin', $maturitylevel) . PHP_EOL;
|
2011-03-03 16:54:04 +01:00
|
|
|
echo get_string('morehelp') . ': ' . get_docs_url('admin/versions') . PHP_EOL;
|
2011-02-25 23:39:42 +01:00
|
|
|
cli_separator();
|
|
|
|
} else {
|
2012-05-28 10:59:22 +02:00
|
|
|
cli_problem(get_string('maturitycorewarning', 'admin', $maturitylevel));
|
|
|
|
cli_error(get_string('maturityallowunstable', 'admin'));
|
2011-02-25 23:39:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-27 09:52:25 +00:00
|
|
|
if ($interactive) {
|
2009-05-31 11:57:33 +00:00
|
|
|
echo html_to_text(get_string('upgradesure', 'admin', $newversion))."\n";
|
|
|
|
$prompt = get_string('cliyesnoprompt', 'admin');
|
|
|
|
$input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin')));
|
|
|
|
if ($input == get_string('clianswerno', 'admin')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-05-27 09:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($version > $CFG->version) {
|
2013-05-08 17:42:55 +12:00
|
|
|
// We purge all of MUC's caches here.
|
|
|
|
// Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
|
|
|
|
// This ensures a real config object is loaded and the stores will be purged.
|
|
|
|
// This is the only way we can purge custom caches such as memcache or APC.
|
|
|
|
// Note: all other calls to caches will still used the disabled API.
|
|
|
|
cache_helper::purge_all(true);
|
2009-05-27 09:52:25 +00:00
|
|
|
upgrade_core($version, true);
|
|
|
|
}
|
|
|
|
set_config('release', $release);
|
2012-05-03 14:05:40 +08:00
|
|
|
set_config('branch', $branch);
|
2009-05-27 09:52:25 +00:00
|
|
|
|
2010-09-05 19:19:40 +00:00
|
|
|
// unconditionally upgrade
|
2009-05-27 09:52:25 +00:00
|
|
|
upgrade_noncore(true);
|
|
|
|
|
|
|
|
// log in as admin - we need doanything permission when applying defaults
|
2013-09-08 08:38:52 +02:00
|
|
|
\core\session\manager::set_user(get_admin());
|
2009-05-27 09:52:25 +00:00
|
|
|
|
|
|
|
// apply all default settings, just in case do it twice to fill all defaults
|
2010-01-21 10:04:03 +00:00
|
|
|
admin_apply_default_settings(NULL, false);
|
|
|
|
admin_apply_default_settings(NULL, false);
|
2009-05-27 09:52:25 +00:00
|
|
|
|
2009-05-31 11:57:33 +00:00
|
|
|
echo get_string('cliupgradefinished', 'admin')."\n";
|
|
|
|
exit(0); // 0 means success
|