Docs: Improve documentation for WP_Upgrader::create_lock(), introduced in [36349].

See #34878. See #35986.


git-svn-id: https://develop.svn.wordpress.org/trunk@36821 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes 2016-03-03 07:07:31 +00:00
parent 2bd631f227
commit 5fc3cdb07e

View File

@ -752,15 +752,16 @@ class WP_Upgrader {
} }
/** /**
* Create a Lock using WordPress options. * Creates a lock using WordPress options.
* *
* @since 4.5.0 * @since 4.5.0
* @access public * @access public
* @static * @static
* *
* @param string $lock_name The name of this unique lock. * @param string $lock_name The name of this unique lock.
* @param int $release_timeout The duration in seconds to respect an existing lock. Default: 1 hour. * @param int $release_timeout Optional. The duration in seconds to respect an existing lock.
* @return bool * Default: 1 hour.
* @return bool False if a lock couldn't be created or if the lock is no longer valid. True otherwise.
*/ */
public static function create_lock( $lock_name, $release_timeout = null ) { public static function create_lock( $lock_name, $release_timeout = null ) {
global $wpdb; global $wpdb;
@ -769,18 +770,18 @@ class WP_Upgrader {
} }
$lock_option = $lock_name . '.lock'; $lock_option = $lock_name . '.lock';
// Try to lock // Try to lock.
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time() ) ); $lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time() ) );
if ( ! $lock_result ) { if ( ! $lock_result ) {
$lock_result = get_option( $lock_option ); $lock_result = get_option( $lock_option );
// If we couldn't create a lock, and there isn't a lock, bail // If a lock couldn't be created, and there isn't a lock, bail.
if ( ! $lock_result ) { if ( ! $lock_result ) {
return false; return false;
} }
// Check to see if the lock is still valid // Check to see if the lock is still valid. If not, bail.
if ( $lock_result > ( time() - $release_timeout ) ) { if ( $lock_result > ( time() - $release_timeout ) ) {
return false; return false;
} }
@ -791,7 +792,7 @@ class WP_Upgrader {
return WP_Upgrader::create_lock( $lock_name, $release_timeout ); return WP_Upgrader::create_lock( $lock_name, $release_timeout );
} }
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions // Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
update_option( $lock_option, time() ); update_option( $lock_option, time() );
return true; return true;