ActionScheduler_HybridStore::get_store_from_action_idprotectedWC 1.0

Return which store an action is stored in.

Метод класса: ActionScheduler_HybridStore{}

Хуков нет.

Возвращает

ActionScheduler_Store.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_store_from_action_id( $action_id, $primary_first );
$action_id(int) (обязательный)
ID of the action.
$primary_first(true|false)
Optional flag indicating search the primary store first.
По умолчанию: false

Код ActionScheduler_HybridStore::get_store_from_action_id() WC 11.0.1

protected function get_store_from_action_id( $action_id, $primary_first = false ) {
	if ( $primary_first ) {
		$stores = array(
			$this->primary_store,
			$this->secondary_store,
		);
	} elseif ( $action_id < $this->demarkation_id ) {
		$stores = array(
			$this->secondary_store,
			$this->primary_store,
		);
	} else {
		$stores = array(
			$this->primary_store,
		);
	}

	foreach ( $stores as $store ) {
		try {
			// Probe by fetching the action status: if entry is corrupted, the object construction is not feasible.
			if ( null !== $store->get_status( $action_id ) ) {
				return $store;
			}
		} catch ( \InvalidArgumentException | \RuntimeException $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
			// A missing or corrupted/empty status just means this store can't resolve the action; keep probing.
		}
	}
	return null;
}