]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Moved upgrade lock/unlock functions to upgrade.php lib.
authorSem <sembrestels@riseup.net>
Tue, 4 Sep 2012 23:16:45 +0000 (01:16 +0200)
committerSem <sembrestels@riseup.net>
Tue, 4 Sep 2012 23:16:45 +0000 (01:16 +0200)
actions/admin/site/unlock_upgrade.php
engine/lib/upgrade.php
upgrade.php

index b73cf7033538684ef05137acd5917fa02a629209..b625b1d267c04c6649ae473055a48fee0499f9cb 100644 (file)
@@ -3,21 +3,8 @@
  * Unlocks the upgrade script 
  */
 
-// @todo Move 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');
-}
-
-if ($is_locked) {
-       // @todo Move to ElggUpgradeManager::unlock() when #4682 fixed.
-       delete_data("drop table {$CONFIG->dbprefix}locked");
-       error_log('Upgrade unlocks itself');
+if (_elgg_upgrade_is_locked()) {
+       _elgg_upgrade_unlock();
 }
 system_message(elgg_echo('upgrade:unlock:success'));
-forward(REFERER);
\ No newline at end of file
+forward(REFERER);
index f0874a483717bd4ede72e72036e9877ab47c6a1e..7f55c4cba65bf92d27d268cd15ab40de851a1ec7 100644 (file)
@@ -311,3 +311,54 @@ function elgg_upgrade_bootstrap_17_to_18() {
 
        return elgg_set_processed_upgrades($processed_upgrades);
 }
+
+/**
+ * Locks a mutual execution of upgrade
+ *
+ * @return bool
+ * @access private
+ */
+function _elgg_upgrade_lock() {
+       global $CONFIG;
+       
+       if (!_elgg_upgrade_is_locked()) {
+               // lock it
+               insert_data("create table {$CONFIG->dbprefix}locked (id INT)");
+               error_log('Upgrade continue running');
+               return true;
+       }
+       
+       error_log('Upgrade is locked');
+       return false;
+}
+
+/**
+ * Unlocks upgrade for new upgrade executions
+ *
+ * @access private
+ */
+function _elgg_upgrade_unlock() {
+       global $CONFIG;
+       delete_data("drop table {$CONFIG->dbprefix}locked");
+       error_log('Upgrade unlocks itself');
+}
+
+/**
+ * Checks if upgrade is locked
+ *
+ * @return bool
+ * @access private
+ */
+function _elgg_upgrade_is_locked() {
+       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');
+       }
+       
+       return $is_locked;
+}
index e1f3c6b9e5ee0720ba6eb2954842729d4a1b6e3a..a58fcdc9655f53ea75c4654848e3aaff031ecbef 100644 (file)
  * @subpackage Upgrade
  */
 
-// @todo Move to ElggUpgradeManager::lock() when #4628 fixed.
-function upgrade_lock() {
-       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');
-       }
-       
-       if (!$is_locked) {
-               // lock it
-               insert_data("create table {$CONFIG->dbprefix}locked (id INT)");
-               error_log('Upgrade continue running');
-               return true;
-       }
-       
-       error_log('Upgrade is locked');
-       return false;
-}
-
-// @todo Move to ElggUpgradeManager::unlock() when #4682 fixed.
-function upgrade_unlock() {
-       global $CONFIG;
-       delete_data("drop table {$CONFIG->dbprefix}locked");
-       error_log('Upgrade unlocks itself');
-}
-
-
 // we want to know if an error occurs
 ini_set('display_errors', 1);
 
@@ -53,7 +22,7 @@ require_once(dirname(__FILE__) . "/engine/start.php");
 if (get_input('upgrade') == 'upgrade') {
        
        // prevent someone from running the upgrade script in parallel (see #4643)
-       if (!upgrade_lock()) {
+       if (!_elgg_upgrade_lock()) {
                forward();
        }
        
@@ -72,7 +41,7 @@ if (get_input('upgrade') == 'upgrade') {
        elgg_reset_system_cache();
        
        // critical region has past
-       upgrade_unlock();
+       _elgg_upgrade_unlock();
        
 } else {
        // if upgrading from < 1.8.0, check for the core view 'welcome' and bail if it's found.