From 6ef02f847978c4b29345ee6be51c556fc0810adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 16 Sep 2015 00:18:06 +0200 Subject: [PATCH] MDL-51261 admin: Add option to define upgradekey via cli installer --- admin/cli/install.php | 20 ++++++++++++++++++++ install/stringnames.txt | 1 + lang/en/admin.php | 1 + lib/installlib.php | 4 ++++ 4 files changed, 26 insertions(+) diff --git a/admin/cli/install.php b/admin/cli/install.php index 51364b9f149bd..523f9e8daaa81 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -74,6 +74,7 @@ --adminpass=PASSWORD Password for the moodle admin account, required in non-interactive mode. --adminemail=STRING Email address for the moodle admin account. +--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. --agree-license Indicates agreement with software license, @@ -258,6 +259,7 @@ 'adminuser' => 'admin', 'adminpass' => '', 'adminemail' => '', + 'upgradekey' => '', 'non-interactive' => false, 'agree-license' => false, 'allow-unstable' => false, @@ -722,6 +724,24 @@ cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); } +// Ask for the upgrade key. +if ($interactive) { + cli_separator(); + cli_heading(get_string('upgradekeyset', 'admin')); + if ($options['upgradekey'] !== '') { + $prompt = get_string('clitypevaluedefault', 'admin', $options['upgradekey']); + $options['upgradekey'] = cli_input($prompt, $options['upgradekey']); + } else { + $prompt = get_string('clitypevalue', 'admin'); + $options['upgradekey'] = cli_input($prompt); + } +} + +// Set the upgrade key if it was provided. +if ($options['upgradekey'] !== '') { + $CFG->upgradekey = $options['upgradekey']; +} + if ($interactive) { if (!$options['agree-license']) { cli_separator(); diff --git a/install/stringnames.txt b/install/stringnames.txt index 0e94de5b2cc2f..1e89ba4eb0c9a 100644 --- a/install/stringnames.txt +++ b/install/stringnames.txt @@ -64,6 +64,7 @@ reload,moodle remotedownloaderror,error thisdirection,langconfig thislanguage,langconfig +upgradekeyset,admin welcomep10,install welcomep20,install welcomep30,install diff --git a/lang/en/admin.php b/lang/en/admin.php index c6ec68dda58b5..4ac1e2be0c95a 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -1106,6 +1106,7 @@ $string['upgradeforumread'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts.
To use this functionality you need to update your tables.'; $string['upgradeforumreadinfo'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts. To use this functionality you need to update your tables with all the tracking information for existing posts. Depending on the size of your site this can take a long time (hours) and can be quite taxing on the database, so it\'s best to do it during a quiet period. However, your site will continue functioning during this upgrade and users won\'t be affected. Once you start this process you should let it finish (keep your browser window open). However, if you stop the process by closing the window: don\'t worry, you can start over.

Do you want to start the upgrading process now?'; $string['upgradekeyreq'] = 'Upgrade key required'; +$string['upgradekeyset'] = 'Upgrade key (leave empty to not set it)'; $string['upgradelogs'] = 'For full functionality, your old logs need to be upgraded. More information'; $string['upgradelogsinfo'] = 'Some changes have recently been made in the way logs are stored. To be able to view all of your old logs on a per-activity basis, your old logs need to be upgraded. Depending on your site this can take a long time (eg several hours) and can be quite taxing on the database for large sites. Once you start this process you should let it finish (by keeping the browser window open). Don\'t worry - your site will work fine for other people while the logs are being upgraded.

Do you want to upgrade your logs now?'; $string['upgradesettings'] = 'New settings'; diff --git a/lib/installlib.php b/lib/installlib.php index 233c34dbe3116..c85b826743b1f 100644 --- a/lib/installlib.php +++ b/lib/installlib.php @@ -256,6 +256,10 @@ function install_generate_configphp($database, $cfg) { } $configphp .= '$CFG->directorypermissions = ' . $chmod . ';' . PHP_EOL . PHP_EOL; + if (isset($cfg->upgradekey) and $cfg->upgradekey !== '') { + $configphp .= '$CFG->upgradekey = ' . var_export($cfg->upgradekey, true) . ';' . PHP_EOL . PHP_EOL; + } + $configphp .= 'require_once(dirname(__FILE__) . \'/lib/setup.php\');' . PHP_EOL . PHP_EOL; $configphp .= '// There is no php closing tag in this file,' . PHP_EOL; $configphp .= '// it is intentional because it prevents trailing whitespace problems!' . PHP_EOL;