get_var($wpdb->prepare('SELECT GET_LOCK(%s, 0)', self::name())); if ( $acquired === '0' ) { return false; } // NULL: the server or a proxy in front of it refused the lock. An update must still run, so // this request runs it unlocked, as every version before this did. self::$held = $acquired === '1'; // The version was read before the lock: another request may have finished in between. self::forgetCachedVersion(); if ( !self::updatePending() ) { self::release(); } return true; } public static function release(): void { if ( !self::$held ) { return; } global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->query($wpdb->prepare('SELECT RELEASE_LOCK(%s)', self::name())); self::$held = false; } /** * A lock's name is server-wide, and MySQL allows 64 characters. The plugin's tables use the base * prefix, so one lock covers every site of a network. */ public static function name(): string { global $wpdb; return 'asl_activation_' . md5(DB_NAME . $wpdb->base_prefix); } private static function updatePending(): bool { return intval(get_option('asl_version', 0)) !== ASL_CURRENT_VERSION; } private static function forgetCachedVersion(): void { wp_cache_delete('alloptions', 'options'); wp_cache_delete('notoptions', 'options'); wp_cache_delete('asl_version', 'options'); } }