ActionScheduler_OptionLock::get_existing_lock │ private │ WC 1.0

Supplies the existing lock value, or null if not set.

Method of the class: ActionScheduler_OptionLock{}

No Hooks.

Returns

string|null.

Usage

// private - for code of main (parent) class only
$result = $this->get_existing_lock( $lock_type, $now );
$lock_type(string) (required)
A string to identify different lock types.
$now(int) (required)
The timestamp to use.

ActionScheduler_OptionLock::get_existing_lock() code WC 11.2.1

private function get_existing_lock( $lock_type, int $now ) {
	global $wpdb;

	$lock_key = $this->get_key( $lock_type );
	$cached   = wp_cache_get( $lock_key, 'action_scheduler_locks' );
	if ( false !== $cached ) {
		return (string) $cached;
	}

	$value = null;
	// Now grab the existing lock value, if there is one.
	// get_var() returns null for the empty string ('') so we must use get_row().
	$row = $wpdb->get_row(
		$wpdb->prepare(
			"SELECT option_value FROM $wpdb->options WHERE option_name = %s",
			$lock_key
		)
	);

	if ( $row ) {
		$value = $row->option_value;
		// Sync cache as necessary.
		$ttl = $this->get_expiration_from( $value ) - $now;
		if ( $ttl > 0 ) {
			wp_cache_set( $lock_key, $value, 'action_scheduler_locks', $ttl );
		}
	}

	return $value;
}