Commit 7289bb19 authored by Francois Marier's avatar Francois Marier Committed by Gerrit Code Review
Browse files

Merge "Prevent multiple simultaneous upgrades (bug #844480)"

parents 56760c9e b5713230
......@@ -101,6 +101,9 @@ if (!empty($upgrade)) {
}
$data['error'] = false;
$data['feedback'] = $SESSION->render_messages();
if (param_boolean('last', false)) {
delete_records('config', 'field', '_upgrade');
}
json_reply(false, $data);
exit;
}
......@@ -108,6 +111,9 @@ if (!empty($upgrade)) {
list($texttrace, $htmltrace) = log_build_backtrace($e->getTrace());
$data['errormessage'] = $e->getMessage() . '<br>' . $htmltrace;
$data['error'] = true;
if (table_exists(new XMLDBTable('config'))) {
delete_records('config', 'field', '_upgrade');
}
json_reply('local', $data);
exit;
}
......@@ -122,6 +128,9 @@ else {
// time the core upgrade was written.
$data['error'] = false;
$data['message'] = get_string('nothingtoupgrade','admin');
if (param_boolean('last', false)) {
delete_records('config', 'field', '_upgrade');
}
json_reply(false, $data);
exit;
}
......@@ -72,6 +72,34 @@ if (!$upgrades) {
die_info(get_string('noupgrades', 'admin'));
}
$start = time();
if (empty($upgrades['core']->install)) {
// Insert a record into config before the upgrade starts, to prevent subsequent hits
// on this page from starting a second simultaneous upgrade.
// But let the admin run a second one if they really want to.
if (param_integer('rerun', 0)) {
delete_records('config', 'field', '_upgrade');
}
if (!$lastupgrade = get_field('config', 'value', 'field', '_upgrade')) {
try {
insert_record('config', (object) array('field' => '_upgrade', 'value' => $start));
}
catch (SQLException $e) {
if (!$lastupgrade = get_field('config', 'value', 'field', '_upgrade')) {
$lastupgrade = '???';
}
}
}
if (!empty($lastupgrade)) {
$laststart = format_date($lastupgrade, 'strftimedatetimeshort');
log_debug('Not upgrading; unfinished upgrade from ' . $laststart . ' still in progress');
die_info(get_string('upgradeinprogress', 'admin', $laststart));
}
}
$loadingicon = $THEME->get_url('images/loading.gif');
$successicon = $THEME->get_url('images/success.gif');
$failureicon = $THEME->get_url('images/failure.gif');
......@@ -127,7 +155,7 @@ $js = <<< EOJS
$(element).innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />';
sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) {
sendjsonrequest('upgrade.json.php', { 'name': element, 'last': todo.length == 0 }, 'GET', function (data) {
if ( !data.error ) {
var message;
if (data.coredata) {
......
......@@ -58,6 +58,7 @@ $string['upgradesuccesstoversion'] = 'Successfully upgraded to version ';
$string['upgradefailure'] = 'Failed to upgrade!';
$string['noupgrades'] = 'Nothing to upgrade! You are fully up to date!';
$string['youcanupgrade'] = 'You can upgrade Mahara from %s (%s) to %s (%s)!';
$string['upgradeinprogress'] = 'An upgrade began at %s and did not complete. <a href="?rerun=1">Run this upgrade anyway.</a>';
$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.';
......
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