diff --git a/admin/cli/install.php b/admin/cli/install.php index 9d23de73759..3146890ae61 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -77,6 +77,7 @@ Options: --adminemail=STRING Email address for the moodle admin account. --sitepreset=STRING Admin site preset to be applied during the installation process. --supportemail=STRING Email address for support and help. +--noreplyemail=STRING Email address used for noreply. --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 problem encountered. @@ -255,6 +256,7 @@ list($options, $unrecognized) = cli_get_params( 'adminemail' => '', 'sitepreset' => '', 'supportemail' => '', + 'noreplyemail' => '', 'upgradekey' => '', 'non-interactive' => false, 'agree-license' => false, @@ -751,6 +753,20 @@ if (!$skipdatabase) { $a = (object)['option' => 'supportemail', 'value' => $options['supportemail']]; cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); } + + // Ask for the noreply address. + if ($interactive) { + cli_separator(); + cli_heading(get_string('clinoreplyemail', 'install')); + $prompt = get_string('clitypevaluedefault', 'admin', $options['noreplyemail']); + $options['noreplyemail'] = cli_input($prompt, $options['noreplyemail']); + } + + // Validate that the noreply address provided is valid. + if (!empty($options['noreplyemail']) && !validate_email($options['noreplyemail'])) { + $a = (object)['option' => 'noreplyemail', 'value' => $options['noreplyemail']]; + cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); + } } // Ask for the upgrade key. diff --git a/admin/cli/install_database.php b/admin/cli/install_database.php index 08d59f4093a..8ef9aaaa3c3 100644 --- a/admin/cli/install_database.php +++ b/admin/cli/install_database.php @@ -58,6 +58,7 @@ Options: --shortname=STRING Name of the site --summary=STRING The summary to be displayed on the front page --supportemail=STRING Email address for support and help. +--noreplyemail=STRING Email address used for noreply. -h, --help Print out this help Example: @@ -100,6 +101,7 @@ list($options, $unrecognized) = cli_get_params( 'shortname' => '', 'summary' => '', 'supportemail' => '', + 'noreplyemail' => '', 'agree-license' => false, 'help' => false ), @@ -147,6 +149,12 @@ if (!empty($options['supportemail']) && !validate_email($options['supportemail'] cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); } +// Validate that the noreply address provided is valid. +if (!empty($options['noreplyemail']) && !validate_email($options['noreplyemail'])) { + $a = (object)['option' => 'noreplyemail', 'value' => $options['noreplyemail']]; + 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/public/lang/en/install.php b/public/lang/en/install.php index 78b072e9a9e..7ced92969ff 100644 --- a/public/lang/en/install.php +++ b/public/lang/en/install.php @@ -47,6 +47,7 @@ $string['clialreadyinstalled'] = 'The configuration file config.php already exis $string['cliinstallfinished'] = 'Installation completed successfully.'; $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['clinoreplyemail'] = 'Noreply address'; $string['cliskipdatabase'] = 'Skipping database installation.'; $string['clisupportemail'] = 'Support email address'; $string['clitablesexist'] = 'Database tables already present; CLI installation cannot continue.'; diff --git a/public/lib/installlib.php b/public/lib/installlib.php index 69e1ad26809..8cb905428b6 100644 --- a/public/lib/installlib.php +++ b/public/lib/installlib.php @@ -470,6 +470,11 @@ function install_cli_database(array $options, $interactive) { set_config('supportemail', $options['adminemail']); } + // Set the noreply address if specified. + if (!empty($options['noreplyemail'])) { + set_config('noreplyaddress', $options['noreplyemail']); + } + // indicate that this site is fully configured set_config('rolesactive', 1); upgrade_finished();