ActionScheduler_DBStore::find_actions_by_claim_id()publicWC 1.0

Retrieve the action IDs of action in a claim.

Method of the class: ActionScheduler_DBStore{}

No Hooks.

Return

Int[].

Usage

$ActionScheduler_DBStore = new ActionScheduler_DBStore();
$ActionScheduler_DBStore->find_actions_by_claim_id( $claim_id );
$claim_id(int) (required)
Claim ID.

ActionScheduler_DBStore::find_actions_by_claim_id() code WC 8.7.0

public function find_actions_by_claim_id( $claim_id ) {
	/** @var \wpdb $wpdb */
	global $wpdb;

	$action_ids  = array();
	$before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
	$cut_off     = $before_date->format( 'Y-m-d H:i:s' );

	$sql = $wpdb->prepare(
		"SELECT action_id, scheduled_date_gmt FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d ORDER BY priority ASC, attempts ASC, scheduled_date_gmt ASC, action_id ASC",
		$claim_id
	);

	// Verify that the scheduled date for each action is within the expected bounds (in some unusual
	// cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
	foreach ( $wpdb->get_results( $sql ) as $claimed_action ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		if ( $claimed_action->scheduled_date_gmt <= $cut_off ) {
			$action_ids[] = absint( $claimed_action->action_id );
		}
	}

	return $action_ids;
}