Commit 22e450eb authored by Andrew Robert Nicols's avatar Andrew Robert Nicols
Browse files

Add CLI Installer and Upgrade (Bug #844604)



This commit adds a Command Line Interface install and upgrade mechanism.
This should provide for unattended installations and upgrades.

Change-Id: I7eaff22f76e30345102405b302bb12fdbd897d4c
Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
parent 36f88033
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2011 Andrew Nicols <andrew.nicols@luns.net.uk>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('INSTALLER', 1);
define('CLI', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require(get_config('libroot') . 'cli.php');
require(get_config('libroot') . 'upgrade.php');
require(get_config('docroot') . 'local/install.php');
$cli = get_cli();
$options = array();
$options['adminpassword'] = new stdClass();
$options['adminpassword']->examplevalue = 'Password1!';
$options['adminpassword']->shortoptions = array('p');
$options['adminpassword']->description = get_string('cliadminpassword', 'admin');
$options['adminpassword']->required = true;
$options['adminemail'] = new stdClass();
$options['adminemail']->examplevalue = 'user@example.org';
$options['adminemail']->shortoptions = array('e');
$options['adminemail']->description = get_string('cliadminemail', 'admin');
$options['adminemail']->required = true;
$settings = new stdClass();
$settings->options = $options;
$settings->info = get_string('cliinstallerdescription', 'admin');
$cli->setup($settings);
// Check whether we need to do anything
if (table_exists(new XMLDBTable('config'))) {
cli::cli_exit(get_string('maharainstalled', 'admin'), false);
}
// Check initial password and e-mail address before we install
try {
$adminpassword = $cli->get_cli_param('adminpassword');
$adminemail = $cli->get_cli_param('adminemail');
}
catch (ParameterException $e) {
cli::cli_exit($e->getMessage(), true);
}
// Determine what we will install
$upgrades = check_upgrades();
$upgrades['firstcoredata'] = true;
$upgrades['localpreinst'] = true;
$upgrades['lastcoredata'] = true;
$upgrades['localpostinst'] = true;
// Actually perform the installation
log_info(get_string('cliinstallingmahara', 'admin'));
upgrade_mahara($upgrades);
// Set initial password and e-mail address
$userobj = new User();
$userobj = $userobj->find_by_username('admin');
$userobj->email = $adminemail;
$userobj->commit();
// Password changes should be performed by the authfactory
$authobj = AuthFactory::create($userobj->authinstance);
$authobj->change_password($userobj, $adminpassword, true);
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2011 Andrew Nicols <andrew.nicols@luns.net.uk>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('INSTALLER', 1);
define('CLI', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require(get_config('libroot') . 'cli.php');
require(get_config('libroot') . 'upgrade.php');
require(get_config('docroot') . 'local/install.php');
$cli = get_cli();
$options = array();
$settings = new stdClass();
$settings->options = $options;
$settings->info = get_string('cliupgraderdescription', 'admin');
$cli->setup($settings);
// Check whether Mahara is installed yet
if (!table_exists(new XMLDBTable('config'))) {
cli::cli_exit(get_string('maharanotinstalled', 'admin'), false);
}
// Check whether we need to do anything
$upgrades = check_upgrades();
if (!$upgrades) {
cli::cli_exit(get_string('noupgrades', 'admin'), false);
}
// Check for issues which would pose problems during upgrade
ensure_upgrade_sanity();
// Actually perform the upgrade
log_info(get_string('cliupgradingmahara', 'admin'));
upgrade_mahara($upgrades);
......@@ -308,7 +308,9 @@ if (!get_config('installed')) {
$scriptfilename = str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']);
if (false === strpos($scriptfilename, 'admin/index.php')
&& false === strpos($scriptfilename, 'admin/upgrade.php')
&& false === strpos($scriptfilename, 'admin/upgrade.json.php')) {
&& false === strpos($scriptfilename, 'admin/upgrade.json.php')
&& false === strpos($scriptfilename, 'admin/cli/install.php')
&& false === strpos($scriptfilename, 'admin/cli/upgrade.php')) {
redirect('/admin/');
}
}
......
......@@ -40,6 +40,7 @@ $string['coredata'] = 'core data';
$string['coredatasuccess'] = 'Successfully installed core data';
$string['fromversion'] = 'From version';
$string['information'] = 'Information';
$string['installingplugin'] = 'Installing %s';
$string['installsuccess'] = 'Successfully installed version ';
$string['toversion'] = 'To version';
$string['localdatasuccess'] = 'Successfully installed local customisations';
......@@ -53,6 +54,7 @@ $string['thefollowingupgradesareready'] = 'The following upgrades are ready:';
$string['registerthismaharasite'] = 'Register this Mahara site';
$string['upgradeloading'] = 'Loading...';
$string['upgrades'] = 'Upgrades';
$string['upgradingplugin'] = 'Upgrading %s';
$string['upgradesuccess'] = 'Successfully upgraded';
$string['upgradesuccesstoversion'] = 'Successfully upgraded to version ';
$string['upgradefailure'] = 'Failed to upgrade!';
......@@ -63,6 +65,14 @@ $string['Plugin'] = 'Plugin';
$string['jsrequiredforupgrade'] = 'You must enable javascript to perform an install or upgrade.';
$string['dbnotutf8warning'] = 'You are not using a UTF-8 database. Mahara stores all data as UTF-8 internally. You may still attempt this upgrade but it is recommended that you convert your database to UTF-8.';
$string['dbcollationmismatch'] = 'A column of your database is using a collation that is not the same as the database default. Please ensure all columns use the same collation as the database.';
$string['maharainstalled'] = 'Mahara is already installed';
$string['cliadminpassword'] = 'The password for the admin user';
$string['cliadminemail'] = 'The e-mail address for the admin user';
$string['cliinstallerdescription'] = 'Install the Mahara and create required data directories';
$string['cliinstallingmahara'] = 'Installing Mahara';
$string['cliupgraderdescription'] = 'Upgrade the mahara database and data to the version of mahara installed';
$string['cliupgradingmahara'] = 'Upgrading Mahara';
$string['maharanotinstalled'] = 'Mahara is not currently installed. Please install mahara before trying to upgrade';
// Admin navigation menu
$string['adminhome'] = 'Admin home';
......
......@@ -188,6 +188,59 @@ function ensure_upgrade_sanity() {
}
}
/**
* Upgrade/Install the specified mahara components
*
* @param array $upgrades The list of components to install or upgrade
* @return void
*/
function upgrade_mahara($upgrades) {
if (isset($upgrades['firstcoredata']) && $upgrades['firstcoredata']) {
$install = true;
}
uksort($upgrades, 'sort_upgrades');
foreach ($upgrades as $name => $data) {
if ($name == 'disablelogin') {
continue;
}
if ($install) {
log_info(get_string('installingplugin', 'admin', $name));
}
else {
log_info(get_string('upgradingplugin', 'admin', $name));
}
if ($name == 'firstcoredata' || $name == 'lastcoredata') {
$funname = 'core_install_' . $name . '_defaults';
$funname();
continue;
}
else if ($install && $name == 'localpreinst') {
$name(array('localdata' => true));
}
else if ($install && $name == 'localpostinst') {
// Update local version
$config = new StdClass;
require(get_config('docroot') . 'local/version.php');
set_config('localversion', $config->version);
set_config('localrelease', $config->release);
// Installation is finished
set_config('installed', true);
log_info('Installation complete.');
}
else {
if ($name == 'core') {
$funname = 'upgrade_core';
}
else {
$funname = 'upgrade_plugin';
}
$data->name = $name;
$funname($data);
}
}
}
/**
* Check to see if the internal plugins are installed. Die if they are not.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment