From 9632db7aea538bc065e1ef746ef32064bedf93b1 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Wed, 27 Oct 2010 19:18:45 +0000 Subject: [PATCH] MDL-23027 CLI installer allows to define site name and shortname Credit goes to James Brisland for the submitted patch. I just polished it a bit and changed the SQL condition that selects the site course record from id=1 to format='site' (see xmldb_main_install() for how the site course record is initialised, we should not rely on the id assigned to it by the DB engine). --- admin/cli/install.php | 48 ++++++++++++++++++++++++++++++++++++++++++- lib/installlib.php | 9 +++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/admin/cli/install.php b/admin/cli/install.php index 6d98a43d1af..3378948d7c3 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -61,6 +61,8 @@ Options: --dbpass=PASSWORD Database password. Default is blank --dbsocket Use database sockets. Available for some databases only. --prefix=STRING Table prefix for above database tables. Default is mdl_ +--fullname=STRING The fullname of the site +--shortname=STRING The shortname of the site --adminuser=USERNAME Username for the moodle admin account. Default is admin --adminpass=PASSWORD Password for the moodle admin account, required in non-interactive mode. @@ -185,6 +187,8 @@ list($options, $unrecognized) = cli_get_params( 'dbpass' => '', 'dbsocket' => false, 'prefix' => 'mdl_', + 'fullname' => '', + 'shortname' => '', 'adminuser' => 'admin', 'adminpass' => '', 'non-interactive' => false, @@ -227,7 +231,7 @@ if ($interactive) { foreach ($languages as $key=>$lang) { $c++; $length = iconv_strlen($lang, 'UTF-8'); - $padded = $lang.str_repeat(' ', 28-$length); + $padded = $lang.str_repeat(' ', 38-$length); $langlist .= $padded; if ($c % 3 == 0) { $langlist .= "\n"; @@ -507,6 +511,48 @@ if ($interactive) { } } +// ask for fullname +if ($interactive) { + cli_separator(); + cli_heading(get_string('fullsitename', 'moodle')); + + if ($options['fullname'] !== '') { + $prompt = get_string('clitypevaluedefault', 'admin', $options['fullname']); + } else { + $prompt = get_string('clitypevalue', 'admin'); + } + + do { + $options['fullname'] = cli_input($prompt, $options['fullname']); + } while (empty($options['fullname'])); +} else { + if (empty($options['fullname'])) { + $a = (object)array('option'=>'fullname', 'value'=>$options['fullname']); + cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); + } +} + +// ask for shortname +if ($interactive) { + cli_separator(); + cli_heading(get_string('shortsitename', 'moodle')); + + if ($options['shortname'] !== '') { + $prompt = get_string('clitypevaluedefault', 'admin', $options['shortname']); + } else { + $prompt = get_string('clitypevalue', 'admin'); + } + + do { + $options['shortname'] = cli_input($prompt, $options['shortname']); + } while (empty($options['shortname'])); +} else { + if (empty($options['shortname'])) { + $a = (object)array('option'=>'shortname', 'value'=>$options['shortname']); + cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); + } +} + // ask for admin user name if ($interactive) { cli_separator(); diff --git a/lib/installlib.php b/lib/installlib.php index 122f5730c42..3a7c822cada 100644 --- a/lib/installlib.php +++ b/lib/installlib.php @@ -581,4 +581,11 @@ function install_cli_database(array $options, $interactive) { admin_apply_default_settings(NULL, true); set_config('registerauth', ''); -} \ No newline at end of file + // set the site name + if (isset($options['shortname']) and $options['shortname'] !== '') { + $DB->set_field('course', 'shortname', $options['shortname'], array('format' => 'site')); + } + if (isset($options['fullname']) and $options['fullname'] !== '') { + $DB->set_field('course', 'fullname', $options['fullname'], array('format' => 'site')); + } +}