MDL-23027 CLI installer allows to define site name and shortname
authorDavid Mudrak <david.mudrak@gmail.com>
Wed, 27 Oct 2010 19:18:45 +0000 (19:18 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Wed, 27 Oct 2010 19:18:45 +0000 (19:18 +0000)
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
lib/installlib.php

index 6d98a43..3378948 100644 (file)
@@ -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();
index 122f573..3a7c822 100644 (file)
@@ -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'));
+    }
+}