Skip to content
This repository
Browse code

Refs #4643. Cleanup for the upgrade lock.

  • Loading branch information...
commit 22e8d9be4582b78a500382e14046a653a14e3f43 1 parent ba0761b
Brett Profitt brettp authored
20 engine/lib/upgrade.php
@@ -313,7 +313,9 @@ function elgg_upgrade_bootstrap_17_to_18() {
313 313 }
314 314
315 315 /**
316   - * Locks a mutual execution of upgrade
  316 + * Creates a table {prefix}upgrade_lock that is used as a mutex for upgrades.
  317 + *
  318 + * @see _elgg_upgrade_lock()
317 319 *
318 320 * @return bool
319 321 * @access private
@@ -323,24 +325,26 @@ function _elgg_upgrade_lock() {
323 325
324 326 if (!_elgg_upgrade_is_locked()) {
325 327 // lock it
326   - insert_data("create table {$CONFIG->dbprefix}locked (id INT)");
327   - error_log('Upgrade continue running');
  328 + insert_data("create table {$CONFIG->dbprefix}upgrade_lock (id INT)");
  329 + elgg_log('Locked for upgrade.', 'NOTICE');
328 330 return true;
329 331 }
330 332
331   - error_log('Upgrade is locked');
  333 + elgg_log('Cannot lock for upgrade: already locked.', 'WARNING');
332 334 return false;
333 335 }
334 336
335 337 /**
336   - * Unlocks upgrade for new upgrade executions
  338 + * Unlocks upgrade.
  339 + *
  340 + * @see _elgg_upgrade_lock()
337 341 *
338 342 * @access private
339 343 */
340 344 function _elgg_upgrade_unlock() {
341 345 global $CONFIG;
342   - delete_data("drop table {$CONFIG->dbprefix}locked");
343   - error_log('Upgrade unlocks itself');
  346 + delete_data("drop table {$CONFIG->dbprefix}upgrade_lock");
  347 + elgg_log('Upgrade unlocked.', 'NOTICE');
344 348 }
345 349
346 350 /**
@@ -352,7 +356,7 @@ function _elgg_upgrade_unlock() {
352 356 function _elgg_upgrade_is_locked() {
353 357 global $CONFIG, $DB_QUERY_CACHE;
354 358
355   - $is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}locked'"));
  359 + $is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}upgrade_lock'"));
356 360
357 361 // Invalidate query cache
358 362 if ($DB_QUERY_CACHE) {
3  languages/en.php
@@ -1048,7 +1048,8 @@
1048 1048 'upgrade:db' => 'Your database was upgraded.',
1049 1049 'upgrade:core' => 'Your Elgg installation was upgraded.',
1050 1050 'upgrade:unlock' => 'Unlock upgrade',
1051   - 'upgrade:unlock:confirm' => "Somebody is performing an upgrade. You should cancel and wait until upgrade is done. Are you sure you want to continue?",
  1051 + '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?",
  1052 + 'upgrade:locked' => "Cannot upgrade. Another upgrade is running. To clear the upgrade lock, visit the Admin section.",
1052 1053 'upgrade:unlock:success' => "Upgrade unlocked suscessfully.",
1053 1054 'upgrade:unable_to_upgrade' => 'Unable to upgrade.',
1054 1055 'upgrade:unable_to_upgrade_info' =>
5 upgrade.php
@@ -9,6 +9,8 @@
9 9 * new version of the script. Deleting the script is not a requirement and
10 10 * leaving it behind does not affect the security of the site.
11 11 *
  12 + * Upgrades use a table {db_prefix}upgrade_lock as a mutex to prevent concurrent upgrades.
  13 + *
12 14 * @package Elgg.Core
13 15 * @subpackage Upgrade
14 16 */
@@ -20,9 +22,9 @@
20 22 require_once(dirname(__FILE__) . "/engine/start.php");
21 23
22 24 if (get_input('upgrade') == 'upgrade') {
23   -
24 25 // prevent someone from running the upgrade script in parallel (see #4643)
25 26 if (!_elgg_upgrade_lock()) {
  27 + register_error(elgg_echo('upgrade:locked'));
26 28 forward();
27 29 }
28 30
@@ -40,7 +42,6 @@
40 42 elgg_invalidate_simplecache();
41 43 elgg_reset_system_cache();
42 44
43   - // critical region has past
44 45 _elgg_upgrade_unlock();
45 46
46 47 } else {
10 views/default/widgets/control_panel/content.php
@@ -12,13 +12,7 @@
12 12 ));
13 13
14 14 // @todo Move in this in ElggUpgradeManager::isLocked() when #4682 fixed
15   -global $CONFIG, $DB_QUERY_CACHE;
16   -$is_locked = count(get_data("show tables like '{$CONFIG->dbprefix}locked'"));
17   -// Invalidate query cache
18   -if ($DB_QUERY_CACHE) {
19   - $DB_QUERY_CACHE->clear();
20   - elgg_log("Query cache invalidated", 'NOTICE');
21   -}
  15 +$is_locked = _elgg_upgrade_is_locked();
22 16
23 17 if (!$is_locked) {
24 18 elgg_register_menu_item('admin_control_panel', array(
@@ -33,7 +27,7 @@
33 27 'text' => elgg_echo('upgrade:unlock'),
34 28 'href' => 'action/admin/site/unlock_upgrade',
35 29 'is_action' => true,
36   - 'link_class' => 'elgg-button elgg-button-delete',
  30 + 'link_class' => 'elgg-button elgg-button-action',
37 31 'confirm' => elgg_echo('upgrade:unlock:confirm'),
38 32 ));
39 33 }

0 comments on commit 22e8d9b

Please sign in to comment.
Something went wrong with that request. Please try again.