ActionScheduler_DBStore::build_where_clause_for_insert()privateWC 1.0

Helper method to build where clause for action insert statement.

Method of the class: ActionScheduler_DBStore{}

No Hooks.

Return

String. Where clause to be used with insert.

Usage

// private - for code of main (parent) class only
$result = $this->build_where_clause_for_insert( $data, $table_name, $unique );
$data(array) (required)
Row data for action.
$table_name(string) (required)
Action table name.
$unique(true|false) (required)
Where action should be unique.

ActionScheduler_DBStore::build_where_clause_for_insert() code WC 8.7.0

private function build_where_clause_for_insert( $data, $table_name, $unique ) {
	global $wpdb;

	if ( ! $unique ) {
		return 'SELECT NULL FROM DUAL';
	}

	$pending_statuses            = array(
		ActionScheduler_Store::STATUS_PENDING,
		ActionScheduler_Store::STATUS_RUNNING,
	);
	$pending_status_placeholders = implode( ', ', array_fill( 0, count( $pending_statuses ), '%s' ) );

	// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $pending_status_placeholders is hardcoded.
	$where_clause = $wpdb->prepare(
		"
SELECT action_id FROM $table_name
WHERE status IN ( $pending_status_placeholders )
AND hook = %s
AND `group_id` = %d
",
		array_merge(
			$pending_statuses,
			array(
				$data['hook'],
				$data['group_id'],
			)
		)
	);
	// phpcs:enable

	return "$where_clause" . ' LIMIT 1';
}