Permalink
Browse files

Refs #4643. Cleanup for the upgrade lock.

  • Loading branch information...
1 parent ba0761b commit 22e8d9be4582b78a500382e14046a653a14e3f43 @brettp brettp committed Dec 16, 2012
Showing with 19 additions and 19 deletions.
  1. +12 −8 engine/lib/upgrade.php
  2. +2 −1 languages/en.php
  3. +3 −2 upgrade.php
  4. +2 −8 views/default/widgets/control_panel/content.php
View
@@ -313,7 +313,9 @@ function elgg_upgrade_bootstrap_17_to_18() {
}
/**
- * Locks a mutual execution of upgrade
+ * Creates a table {prefix}upgrade_lock that is used as a mutex for upgrades.
+ *
+ * @see _elgg_upgrade_lock()
*
* @return bool
* @access private
@@ -323,24 +325,26 @@ function _elgg_upgrade_lock() {
if (!_elgg_upgrade_is_locked()) {
// lock it
- insert_data("create table {$CONFIG->dbprefix}locked (id INT)");
- error_log('Upgrade continue running');
+ insert_data("create table {$CONFIG->dbprefix}upgrade_lock (id INT)");
+ elgg_log('Locked for upgrade.', 'NOTICE');
return true;
}
- error_log('Upgrade is locked');
+ elgg_log('Cannot lock for upgrade: already locked.', 'WARNING');
return false;
}
/**
- * Unlocks upgrade for new upgrade executions
+ * Unlocks upgrade.
+ *
+ * @see _elgg_upgrade_lock()
*
* @access private
*/
function _elgg_upgrade_unlock() {
global $CONFIG;
- delete_data("drop table {$CONFIG->dbprefix}locked");
- error_log('Upgrade unlocks itself');
+ delete_data("drop table {$CONFIG->dbprefix}upgrade_lock");
+ elgg_log('Upgrade unlocked.', 'NOTICE');
}
/**
@@ -352,7 +356,7 @@ function _elgg_upgrade_unlock() {
function _elgg_upgrade_is_locked() {
global $CONFIG, $DB_QUERY_CACHE;
- $is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}locked'"));
+ $is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}upgrade_lock'"));
// Invalidate query cache
if ($DB_QUERY_CACHE) {
View
@@ -1048,7 +1048,8 @@
'upgrade:db' => 'Your database was upgraded.',
'upgrade:core' => 'Your Elgg installation was upgraded.',
'upgrade:unlock' => 'Unlock upgrade',
- 'upgrade:unlock:confirm' => "Somebody is performing an upgrade. You should cancel and wait until upgrade is done. Are you sure you want to continue?",
+ 'upgrade:unlock:confirm' => "The database is locked for another upgrade. Running concurrent upgrades is dangerous. You should only continue if you know there is not another upgrade running. Unlock?",
+ 'upgrade:locked' => "Cannot upgrade. Another upgrade is running. To clear the upgrade lock, visit the Admin section.",
'upgrade:unlock:success' => "Upgrade unlocked suscessfully.",
'upgrade:unable_to_upgrade' => 'Unable to upgrade.',
'upgrade:unable_to_upgrade_info' =>
View
@@ -9,6 +9,8 @@
* new version of the script. Deleting the script is not a requirement and
* leaving it behind does not affect the security of the site.
*
+ * Upgrades use a table {db_prefix}upgrade_lock as a mutex to prevent concurrent upgrades.
+ *
* @package Elgg.Core
* @subpackage Upgrade
*/
@@ -20,9 +22,9 @@
require_once(dirname(__FILE__) . "/engine/start.php");
if (get_input('upgrade') == 'upgrade') {
-
// prevent someone from running the upgrade script in parallel (see #4643)
if (!_elgg_upgrade_lock()) {
+ register_error(elgg_echo('upgrade:locked'));
forward();
}
@@ -40,7 +42,6 @@
elgg_invalidate_simplecache();
elgg_reset_system_cache();
- // critical region has past
_elgg_upgrade_unlock();
} else {
@@ -12,13 +12,7 @@
));
// @todo Move in this in ElggUpgradeManager::isLocked() when #4682 fixed
-global $CONFIG, $DB_QUERY_CACHE;
-$is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}locked'"));
-// Invalidate query cache
-if ($DB_QUERY_CACHE) {
- $DB_QUERY_CACHE->clear();
- elgg_log("Query cache invalidated", 'NOTICE');
-}
+$is_locked = _elgg_upgrade_is_locked();
if (!$is_locked) {
elgg_register_menu_item('admin_control_panel', array(
@@ -33,7 +27,7 @@
'text' => elgg_echo('upgrade:unlock'),
'href' => 'action/admin/site/unlock_upgrade',
'is_action' => true,
- 'link_class' => 'elgg-button elgg-button-delete',
+ 'link_class' => 'elgg-button elgg-button-action',
'confirm' => elgg_echo('upgrade:unlock:confirm'),
));
}

0 comments on commit 22e8d9b

Please sign in to comment.