Merge branch 'MDL-28513-master' of git://github.com/andrewnicols/moodle

This commit is contained in:
David Monllao 2015-01-21 09:52:55 +08:00
commit 59da38ef8a
4 changed files with 30 additions and 0 deletions

View File

@ -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();

View File

@ -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';

View File

@ -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.';

View File

@ -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'));