mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-19 21:15:23 +00:00
For Background updates, ensure that only one update process runs at the same time by using the options table as a lock.
This prevents multiple cron spawns and/or long-running updates from causing multiple update processes to spin up. This also fixes a case where the upgrader might kick in for ( ! is_main_network() || ! is_main_site() ) in mulisite installs. See #22704 Built from https://develop.svn.wordpress.org/trunk@25828 git-svn-id: http://core.svn.wordpress.org/trunk@25828 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
deadb7b296
commit
66f01957a0
@ -1736,17 +1736,30 @@ class WP_Automatic_Upgrader {
|
|||||||
* Kicks off a upgrade request for each item in the upgrade "queue"
|
* Kicks off a upgrade request for each item in the upgrade "queue"
|
||||||
*/
|
*/
|
||||||
function run() {
|
function run() {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
if ( ! is_main_network() || ! is_main_site() )
|
||||||
|
return;
|
||||||
|
|
||||||
$lock_name = 'auto_upgrader.lock';
|
$lock_name = 'auto_upgrader.lock';
|
||||||
if ( get_site_option( $lock_name ) ) {
|
|
||||||
// Test to see if it was set more than an hour ago, if so, cleanup.
|
// Try to lock
|
||||||
if ( get_site_option( $lock_name ) < ( time() - HOUR_IN_SECONDS ) )
|
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time() ) );
|
||||||
delete_site_option( $lock_name );
|
|
||||||
else // The process is already locked
|
if ( ! $lock_result ) {
|
||||||
|
$lock_result = get_option( $lock_name );
|
||||||
|
|
||||||
|
// If we couldn't create a lock, and there isn't a lock, bail
|
||||||
|
if ( ! $lock_result )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Check to see if the lock is still valid
|
||||||
|
if ( $lock_result > ( time() - HOUR_IN_SECONDS ) )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Lock upgrades for us for half an hour
|
|
||||||
if ( ! add_site_option( $lock_name, microtime( true ), HOUR_IN_SECONDS / 2 ) )
|
// Update the lock, as by this point we've definately got a lock, just need to fire the actions
|
||||||
return;
|
update_option( $lock_name, time() );
|
||||||
|
|
||||||
// Don't automatically run these thins, as we'll handle it ourselves
|
// Don't automatically run these thins, as we'll handle it ourselves
|
||||||
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
|
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
|
||||||
@ -1829,8 +1842,7 @@ class WP_Automatic_Upgrader {
|
|||||||
$this->send_debug_email();
|
$this->send_debug_email();
|
||||||
|
|
||||||
// Clear the lock
|
// Clear the lock
|
||||||
delete_site_option( $lock_name );
|
delete_option( $lock_name );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_debug_email() {
|
function send_debug_email() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user