]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #4643. Cleanup for the upgrade lock.
authorBrett Profitt <brett.profitt@gmail.com>
Sun, 16 Dec 2012 22:26:03 +0000 (17:26 -0500)
committerBrett Profitt <brett.profitt@gmail.com>
Sun, 16 Dec 2012 22:26:03 +0000 (17:26 -0500)
engine/lib/upgrade.php
languages/en.php
upgrade.php
views/default/widgets/control_panel/content.php

index 7f55c4cba65bf92d27d268cd15ab40de851a1ec7..f4f4b16f525c4d5ab7be4eb330f484dda9d81717 100644 (file)
@@ -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) {
index 159867e2fe4702c27117e7489314abf3eb278f88..f1a1d650b9c91d4bc254f113f2ede49e455df188 100644 (file)
@@ -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' =>
index a58fcdc9655f53ea75c4654848e3aaff031ecbef..c5f158c614f033643c65513a6b7153af07cdefd5 100644 (file)
@@ -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 {
index e6763d851d5ce93c1a7c0e935a5dead5fbc05e4b..a348d612f2b6f90ec9c55fb84554d6a11035550d 100644 (file)
@@ -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'),
        ));
 }