aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-09-05 01:16:45 +0200
committerSem <sembrestels@riseup.net>2012-09-05 01:16:45 +0200
commitba0761b5a0fb7d5dd3c20179de0f49b1aa8e0a89 (patch)
tree2e1923a1076bb4f08eb2aff6ceecf4c86c941ba5 /engine/lib
parentdce60b43126dcaa38e6845ae45e09db87aa7e229 (diff)
downloadelgg-ba0761b5a0fb7d5dd3c20179de0f49b1aa8e0a89.tar.gz
elgg-ba0761b5a0fb7d5dd3c20179de0f49b1aa8e0a89.tar.bz2
Moved upgrade lock/unlock functions to upgrade.php lib.
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/upgrade.php51
1 files changed, 51 insertions, 0 deletions
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;
+}