From ba0761b5a0fb7d5dd3c20179de0f49b1aa8e0a89 Mon Sep 17 00:00:00 2001 From: Sem Date: Wed, 5 Sep 2012 01:16:45 +0200 Subject: Moved upgrade lock/unlock functions to upgrade.php lib. --- engine/lib/upgrade.php | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'engine/lib') diff --git a/engine/lib/upgrade.php b/engine/lib/upgrade.php index f0874a483..7f55c4cba 100644 --- a/engine/lib/upgrade.php +++ b/engine/lib/upgrade.php @@ -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; +} -- cgit v1.2.3