MDL-72984 cli: add support email option to cli install

This commit is contained in:
Simey Lameze 2021-12-08 08:50:16 +08:00
parent 4c5db7e80f
commit f88bcdb041
3 changed files with 22 additions and 0 deletions

View File

@ -75,6 +75,7 @@ Options:
required in non-interactive mode. required in non-interactive mode.
--adminemail=STRING Email address for the moodle admin account. --adminemail=STRING Email address for the moodle admin account.
--sitepreset=STRING Admin site preset to be applied during the installation process. --sitepreset=STRING Admin site preset to be applied during the installation process.
--supportemail=STRING Email address for support and help.
--upgradekey=STRING The upgrade key to be set in the config.php, leave empty to not set it. --upgradekey=STRING The upgrade key to be set in the config.php, leave empty to not set it.
--non-interactive No interactive questions, installation fails if any --non-interactive No interactive questions, installation fails if any
problem encountered. problem encountered.
@ -256,6 +257,7 @@ list($options, $unrecognized) = cli_get_params(
'adminpass' => '', 'adminpass' => '',
'adminemail' => '', 'adminemail' => '',
'sitepreset' => '', 'sitepreset' => '',
'supportemail' => '',
'upgradekey' => '', 'upgradekey' => '',
'non-interactive' => false, 'non-interactive' => false,
'agree-license' => false, 'agree-license' => false,
@ -739,6 +741,20 @@ if (!$skipdatabase) {
$a = (object)['option' => 'adminemail', 'value' => $options['adminemail']]; $a = (object)['option' => 'adminemail', 'value' => $options['adminemail']];
cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
} }
// Ask for the support email address.
if ($interactive) {
cli_separator();
cli_heading(get_string('clisupportemail', 'install'));
$prompt = get_string('clitypevaluedefault', 'admin', $options['supportemail']);
$options['supportemail'] = cli_input($prompt, $options['supportemail']);
}
// Validate that the support email address provided is valid.
if (!empty($options['supportemail']) && !validate_email($options['supportemail'])) {
$a = (object)['option' => 'supportemail', 'value' => $options['supportemail']];
cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
}
} }
// Ask for the upgrade key. // Ask for the upgrade key.

View File

@ -48,6 +48,7 @@ $string['cliinstallfinished'] = 'Installation completed successfully.';
$string['cliinstallheader'] = 'Moodle {$a} command line installation program'; $string['cliinstallheader'] = 'Moodle {$a} command line installation program';
$string['climustagreelicense'] = 'In non-interactive mode you must agree to the licence by specifying --agree-license option'; $string['climustagreelicense'] = 'In non-interactive mode you must agree to the licence by specifying --agree-license option';
$string['cliskipdatabase'] = 'Skipping database installation.'; $string['cliskipdatabase'] = 'Skipping database installation.';
$string['clisupportemail'] = 'Support email address';
$string['clitablesexist'] = 'Database tables already present; CLI installation cannot continue.'; $string['clitablesexist'] = 'Database tables already present; CLI installation cannot continue.';
$string['compatibilitysettings'] = 'Checking your PHP settings ...'; $string['compatibilitysettings'] = 'Checking your PHP settings ...';
$string['compatibilitysettingshead'] = 'Checking your PHP settings ...'; $string['compatibilitysettingshead'] = 'Checking your PHP settings ...';

View File

@ -506,6 +506,11 @@ function install_cli_database(array $options, $interactive) {
$DB->set_field('user', 'username', $options['adminuser'], array('username' => 'admin')); $DB->set_field('user', 'username', $options['adminuser'], array('username' => 'admin'));
} }
// Set the support email address if specified.
if (isset($options['supportemail'])) {
set_config('supportemail', $options['supportemail']);
}
// indicate that this site is fully configured // indicate that this site is fully configured
set_config('rolesactive', 1); set_config('rolesactive', 1);
upgrade_finished(); upgrade_finished();