diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
commit | 10ef81bf85ad0a4bad0d204838e14c99ca2526f7 (patch) | |
tree | b4bb36a326d41de12d1a6181d2a2baf34696ac24 /plugins/jetpack/vendor/automattic/jetpack-sync/src/class-lock.php | |
parent | Updating script for Update (diff) | |
download | blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.gz blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.bz2 blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.zip |
Update jetpack 8.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/vendor/automattic/jetpack-sync/src/class-lock.php')
-rw-r--r-- | plugins/jetpack/vendor/automattic/jetpack-sync/src/class-lock.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-lock.php b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-lock.php new file mode 100644 index 00000000..84d87bc8 --- /dev/null +++ b/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-lock.php @@ -0,0 +1,65 @@ +<?php +/** + * Lock class. + * + * @package automattic/jetpack-sync + */ + +namespace Automattic\Jetpack\Sync; + +/** + * Lock class + */ +class Lock { + /** + * Prefix of the blog lock transient. + * + * @access public + * + * @var string + */ + const LOCK_PREFIX = 'jp_sync_lock_'; + + /** + * Default Lifetime of the lock. + * + * @access public + * + * @var int + */ + const LOCK_TRANSIENT_EXPIRY = 15; // Seconds. + + /** + * Attempt to lock. + * + * @access public + * + * @param string $name lock name. + * @param int $expiry lock duration in seconds. + * + * @return boolean True if succeeded, false otherwise. + */ + public function attempt( $name, $expiry = self::LOCK_TRANSIENT_EXPIRY ) { + $name = self::LOCK_PREFIX . $name; + $locked_time = get_option( $name ); + if ( $locked_time ) { + if ( microtime( true ) < $locked_time ) { + return false; + } + } + update_option( $name, microtime( true ) + $expiry ); + + return true; + } + + /** + * Remove the lock. + * + * @access public + * + * @param string $name lock name. + */ + public function remove( $name ) { + delete_option( self::LOCK_PREFIX . $name ); + } +} |