From 22e8d9be4582b78a500382e14046a653a14e3f43 Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Sun, 16 Dec 2012 17:26:03 -0500 Subject: Refs #4643. Cleanup for the upgrade lock. --- engine/lib/upgrade.php | 20 ++++++++++++-------- languages/en.php | 3 ++- upgrade.php | 5 +++-- views/default/widgets/control_panel/content.php | 10 ++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/engine/lib/upgrade.php b/engine/lib/upgrade.php index 7f55c4cba..f4f4b16f5 100644 --- a/engine/lib/upgrade.php +++ b/engine/lib/upgrade.php @@ -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) { diff --git a/languages/en.php b/languages/en.php index 159867e2f..f1a1d650b 100644 --- a/languages/en.php +++ b/languages/en.php @@ -1048,7 +1048,8 @@ Once you have logged in, we highly recommend that you change your password. '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' => diff --git a/upgrade.php b/upgrade.php index a58fcdc96..c5f158c61 100644 --- a/upgrade.php +++ b/upgrade.php @@ -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 @@ define('UPGRADING', 'upgrading'); 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 @@ if (get_input('upgrade') == 'upgrade') { elgg_invalidate_simplecache(); elgg_reset_system_cache(); - // critical region has past _elgg_upgrade_unlock(); } else { diff --git a/views/default/widgets/control_panel/content.php b/views/default/widgets/control_panel/content.php index e6763d851..a348d612f 100644 --- a/views/default/widgets/control_panel/content.php +++ b/views/default/widgets/control_panel/content.php @@ -12,13 +12,7 @@ elgg_register_menu_item('admin_control_panel', array( )); // @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 @@ if (!$is_locked) { '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'), )); } -- cgit v1.2.3