ActionScheduler_HybridStore::get_store_from_action_id │ protected │ WC 1.0

Return which store an action is stored in.

Method of the class: ActionScheduler_HybridStore{}

No Hooks.

Returns

ActionScheduler_Store.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_store_from_action_id( $action_id, $primary_first );
$action_id(int) (required)
ID of the action.
$primary_first(true|false)
Optional flag indicating search the primary store first.
Default: false

ActionScheduler_HybridStore::get_store_from_action_id() code WC 11.1.2

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;
}