Skip to content

Commit

Permalink
MDL-29474 fix regressions in CLI install
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Oct 27, 2011
1 parent 7b27861 commit f433088
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
33 changes: 20 additions & 13 deletions admin/cli/install.php
Expand Up @@ -20,7 +20,6 @@
*
* This script is not intended for beginners!
* Potential problems:
* - environment check is not present yet
* - su to apache account or sudo before execution
* - not compatible with Windows platform
*
Expand Down Expand Up @@ -91,7 +90,11 @@
echo "\n\n";
}

cli_error(get_string('clialreadyinstalled', 'install'));
if ($DB->get_manager()->table_exists('config')) {
cli_error(get_string('clialreadyinstalled', 'install'));
} else {
cli_error(get_string('clialreadyconfigured', 'install'));
}
}

$olddir = getcwd();
Expand Down Expand Up @@ -636,7 +639,21 @@
cli_error('Can not create config file.');
}

// remember selected language
$installlang = $CFG->lang;
// return back to original dir before executing setup.php which changes the dir again
chdir($olddir);
// We have config.php, it is a real php script from now on :-)
require($configfile);

// use selected language
$CFG->lang = $installlang;
$SESSION->lang = $CFG->lang;

require("$CFG->dirroot/version.php");

// Test environment first.
require_once($CFG->libdir . '/environmentlib.php');
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
$errors = environment_get_errors($environment_results);
Expand All @@ -649,21 +666,11 @@
}

// Test plugin dependencies.
require_once($CFG->libdir . '/pluginlib.php');
if (!plugin_manager::instance()->all_plugins_ok($version)) {
cli_error(get_string('pluginschecktodo', 'admin'));
}

// remember selected language
$installlang = $CFG->lang;
// return back to original dir before executing setup.php which changes the dir again
chdir($olddir);
// We have config.php, it is a real php script from now on :-)
require($configfile);

// use selected language
$CFG->lang = $installlang;
$SESSION->lang = $CFG->lang;

install_cli_database($options, $interactive);

echo get_string('cliinstallfinished', 'install')."\n";
Expand Down
3 changes: 2 additions & 1 deletion lang/en/install.php
Expand Up @@ -42,7 +42,8 @@
$string['caution'] = 'Caution';
$string['cliadminpassword'] = 'New admin user password';
$string['cliadminusername'] = 'Admin account username';
$string['clialreadyinstalled'] = 'File config.php already exists, please use admin/cli/upgrade.php if you want to upgrade your site.';
$string['clialreadyconfigured'] = 'File config.php already exists, please use admin/cli/install_database.php if you want to install this site.';
$string['clialreadyinstalled'] = 'File config.php already exists, please use admin/cli/upgrade.php if you want to upgrade this site.';
$string['cliinstallfinished'] = 'Installation completed successfully.';
$string['cliinstallheader'] = 'Moodle {$a} command line installation program';
$string['climustagreelicense'] = 'In non interactive mode you must agree to license by specifying --agree-license option';
Expand Down
21 changes: 18 additions & 3 deletions lib/pluginlib.php
Expand Up @@ -851,7 +851,12 @@ protected function get_version_from_config_plugins($plugin, $disablecache=false)
static $pluginversions = null;

if (is_null($pluginversions) or $disablecache) {
$pluginversions = $DB->get_records_menu('config_plugins', array('name' => 'version'), 'plugin', 'plugin,value');
try {
$pluginversions = $DB->get_records_menu('config_plugins', array('name' => 'version'), 'plugin', 'plugin,value');
} catch (dml_exception $e) {
// before install
$pluginversions = array();
}
}

if (!array_key_exists($plugin, $pluginversions)) {
Expand Down Expand Up @@ -989,7 +994,12 @@ protected static function get_blocks_info($disablecache=false) {
static $blocksinfocache = null;

if (is_null($blocksinfocache) or $disablecache) {
$blocksinfocache = $DB->get_records('block', null, 'name', 'name,id,version,visible');
try {
$blocksinfocache = $DB->get_records('block', null, 'name', 'name,id,version,visible');
} catch (dml_exception $e) {
// before install
$blocksinfocache = array();
}
}

return $blocksinfocache;
Expand Down Expand Up @@ -1318,7 +1328,12 @@ protected static function get_modules_info($disablecache=false) {
static $modulesinfocache = null;

if (is_null($modulesinfocache) or $disablecache) {
$modulesinfocache = $DB->get_records('modules', null, 'name', 'name,id,version,visible');
try {
$modulesinfocache = $DB->get_records('modules', null, 'name', 'name,id,version,visible');
} catch (dml_exception $e) {
// before install
$modulesinfocache = array();
}
}

return $modulesinfocache;
Expand Down

0 comments on commit f433088

Please sign in to comment.