WordPress.org

Make WordPress Core

Changeset 25828


Ignore:
Timestamp:
10/17/2013 05:23:35 AM (5 years ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r25823 r25828  
    17371737     */
    17381738    function run() {
     1739        global $wpdb;
     1740
     1741        if ( ! is_main_network() || ! is_main_site() )
     1742            return;
     1743
    17391744        $lock_name = 'auto_upgrader.lock';
    1740         if ( get_site_option( $lock_name ) ) {
    1741             // Test to see if it was set more than an hour ago, if so, cleanup.
    1742             if ( get_site_option( $lock_name ) < ( time() - HOUR_IN_SECONDS ) )
    1743                 delete_site_option( $lock_name );
    1744             else // The process is already locked
     1745
     1746        // Try to lock
     1747        $lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time() ) );
     1748
     1749        if ( ! $lock_result ) {
     1750            $lock_result = get_option( $lock_name );
     1751
     1752            // If we couldn't create a lock, and there isn't a lock, bail
     1753            if ( ! $lock_result )
    17451754                return;
    1746         }
    1747         // Lock upgrades for us for half an hour
    1748         if ( ! add_site_option( $lock_name, microtime( true ), HOUR_IN_SECONDS / 2 ) )
    1749             return;
     1755
     1756            // Check to see if the lock is still valid
     1757            if ( $lock_result > ( time() - HOUR_IN_SECONDS ) )
     1758                return;
     1759        }
     1760
     1761        // Update the lock, as by this point we've definately got a lock, just need to fire the actions
     1762        update_option( $lock_name, time() );
    17501763
    17511764        // Don't automatically run these thins, as we'll handle it ourselves
     
    18301843
    18311844        // Clear the lock
    1832         delete_site_option( $lock_name );
    1833 
     1845        delete_option( $lock_name );
    18341846    }
    18351847
Note: See TracChangeset for help on using the changeset viewer.