diff options
author | Brett Profitt <brett.profitt@gmail.com> | 2012-12-16 17:32:01 -0500 |
---|---|---|
committer | Brett Profitt <brett.profitt@gmail.com> | 2012-12-16 17:32:01 -0500 |
commit | cc0f1ddad2fac1d1761d59a818f1c41d7db6ed0d (patch) | |
tree | 322d7a5e3104a17b64d65a12ce1478a14ced4cb1 /engine/lib | |
parent | d719d03f1b0e636db021e728cf79a10176d991da (diff) | |
parent | 22e8d9be4582b78a500382e14046a653a14e3f43 (diff) | |
download | elgg-cc0f1ddad2fac1d1761d59a818f1c41d7db6ed0d.tar.gz elgg-cc0f1ddad2fac1d1761d59a818f1c41d7db6ed0d.tar.bz2 |
Merge branch 'pr-309' into 1.8
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/admin.php | 1 | ||||
-rw-r--r-- | engine/lib/upgrade.php | 55 |
2 files changed, 56 insertions, 0 deletions
diff --git a/engine/lib/admin.php b/engine/lib/admin.php index 3f23f079c..cb9524f11 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -233,6 +233,7 @@ function admin_init() { elgg_register_action('admin/site/update_basic', '', 'admin'); elgg_register_action('admin/site/update_advanced', '', 'admin'); elgg_register_action('admin/site/flush_cache', '', 'admin'); + elgg_register_action('admin/site/unlock_upgrade', '', 'admin'); elgg_register_action('admin/menu/save', '', 'admin'); diff --git a/engine/lib/upgrade.php b/engine/lib/upgrade.php index f0874a483..f4f4b16f5 100644 --- a/engine/lib/upgrade.php +++ b/engine/lib/upgrade.php @@ -311,3 +311,58 @@ function elgg_upgrade_bootstrap_17_to_18() { return elgg_set_processed_upgrades($processed_upgrades); } + +/** + * Creates a table {prefix}upgrade_lock that is used as a mutex for upgrades. + * + * @see _elgg_upgrade_lock() + * + * @return bool + * @access private + */ +function _elgg_upgrade_lock() { + global $CONFIG; + + if (!_elgg_upgrade_is_locked()) { + // lock it + insert_data("create table {$CONFIG->dbprefix}upgrade_lock (id INT)"); + elgg_log('Locked for upgrade.', 'NOTICE'); + return true; + } + + elgg_log('Cannot lock for upgrade: already locked.', 'WARNING'); + return false; +} + +/** + * Unlocks upgrade. + * + * @see _elgg_upgrade_lock() + * + * @access private + */ +function _elgg_upgrade_unlock() { + global $CONFIG; + delete_data("drop table {$CONFIG->dbprefix}upgrade_lock"); + elgg_log('Upgrade unlocked.', 'NOTICE'); +} + +/** + * 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}upgrade_lock'")); + + // Invalidate query cache + if ($DB_QUERY_CACHE) { + $DB_QUERY_CACHE->clear(); + elgg_log("Query cache invalidated", 'NOTICE'); + } + + return $is_locked; +} |