diff --git a/admin/cli/install.php b/admin/cli/install.php index 9bb207a1089..8ee0905dfdb 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -72,6 +72,7 @@ Options: --adminuser=USERNAME Username for the moodle admin account. Default is admin --adminpass=PASSWORD Password for the moodle admin account, required in non-interactive mode. +--adminemail=STRING Email address for the moodle admin account. --non-interactive No interactive questions, installation fails if any problem encountered. --agree-license Indicates agreement with software license, @@ -252,6 +253,7 @@ list($options, $unrecognized) = cli_get_params( 'shortname' => '', 'adminuser' => 'admin', 'adminpass' => '', + 'adminemail' => '', 'non-interactive' => false, 'agree-license' => false, 'allow-unstable' => false, @@ -687,6 +689,20 @@ if ($interactive) { } } +// Ask for the admin email address. +if ($interactive) { + cli_separator(); + cli_heading(get_string('cliadminemail', 'install')); + $prompt = get_string('clitypevaluedefault', 'admin', $options['adminemail']); + $options['adminemail'] = cli_input($prompt); +} + +// Validate that the address provided was an e-mail address. +if (!empty($options['adminemail']) && !validate_email($options['adminemail'])) { + $a = (object) array('option' => 'adminemail', 'value' => $options['adminemail']); + cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); +} + if ($interactive) { if (!$options['agree-license']) { cli_separator(); diff --git a/admin/cli/install_database.php b/admin/cli/install_database.php index 91ac8900c55..cb768c36d92 100644 --- a/admin/cli/install_database.php +++ b/admin/cli/install_database.php @@ -52,6 +52,7 @@ Options: --lang=CODE Installation and default site language. Default is en. --adminuser=USERNAME Username for the moodle admin account. Default is admin. --adminpass=PASSWORD Password for the moodle admin account. +--adminemail=STRING Email address for the moodle admin account. --agree-license Indicates agreement with software license. --fullname=STRING Name of the site --shortname=STRING Name of the site @@ -102,6 +103,7 @@ list($options, $unrecognized) = cli_get_params( 'lang' => 'en', 'adminuser' => 'admin', 'adminpass' => '', + 'adminemail' => '', 'fullname' => '', 'shortname' => '', 'agree-license' => false, @@ -126,6 +128,12 @@ if ($options['adminpass'] === true or $options['adminpass'] === '') { cli_error('You have to specify admin password. --help prints out the help'); // TODO: localize } +// Validate that the address provided was an e-mail address. +if (!empty($options['adminemail']) && !validate_email($options['adminemail'])) { + $a = (object) array('option' => 'adminemail', 'value' => $options['adminemail']); + cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); +} + $options['lang'] = clean_param($options['lang'], PARAM_SAFEDIR); if (!file_exists($CFG->dirroot.'/install/lang/'.$options['lang'])) { $options['lang'] = 'en'; diff --git a/lang/en/install.php b/lang/en/install.php index ee6fb04ded0..3d846950cb0 100644 --- a/lang/en/install.php +++ b/lang/en/install.php @@ -39,6 +39,7 @@ $string['admindirsettingsub'] = 'A very few webhosts use /admin as a special URL This will fix admin links in Moodle.'; $string['availablelangs'] = 'Available language packs'; $string['caution'] = 'Caution'; +$string['cliadminemail'] = 'New admin user email address'; $string['cliadminpassword'] = 'New admin user password'; $string['cliadminusername'] = 'Admin account username'; $string['clialreadyconfigured'] = 'The configuration file config.php already exists. Please use admin/cli/install_database.php to install Moodle for this site.'; diff --git a/lib/installlib.php b/lib/installlib.php index c1ae4d5a2f7..c055ba6c94f 100644 --- a/lib/installlib.php +++ b/lib/installlib.php @@ -488,6 +488,11 @@ function install_cli_database(array $options, $interactive) { // set up admin user password $DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin')); + // Set the admin email address if specified. + if (isset($options['adminemail'])) { + $DB->set_field('user', 'email', $options['adminemail'], array('username' => 'admin')); + } + // rename admin username if needed if (isset($options['adminuser']) and $options['adminuser'] !== 'admin' and $options['adminuser'] !== 'guest') { $DB->set_field('user', 'username', $options['adminuser'], array('username' => 'admin'));