Skip to content

Commit

Permalink
MDL-51261 admin: Add option to define upgradekey via cli installer
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Sep 24, 2015
1 parent 98b32c9 commit 6ef02f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions admin/cli/install.php
Expand Up @@ -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,
Expand Down Expand Up @@ -258,6 +259,7 @@
'adminuser' => 'admin',
'adminpass' => '',
'adminemail' => '',
'upgradekey' => '',
'non-interactive' => false,
'agree-license' => false,
'allow-unstable' => false,
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions install/stringnames.txt
Expand Up @@ -64,6 +64,7 @@ reload,moodle
remotedownloaderror,error
thisdirection,langconfig
thislanguage,langconfig
upgradekeyset,admin
welcomep10,install
welcomep20,install
welcomep30,install
Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Expand Up @@ -1106,6 +1106,7 @@
$string['upgradeforumread'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts.<br />To use this functionality you need to <a href="{$a}">update your tables</a>.';
$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.<br /><br />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. <a href="{$a}">More information</a>';
$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.<br /><br />Do you want to upgrade your logs now?';
$string['upgradesettings'] = 'New settings';
Expand Down
4 changes: 4 additions & 0 deletions lib/installlib.php
Expand Up @@ -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;
Expand Down

0 comments on commit 6ef02f8

Please sign in to comment.