ActionScheduler_DBStore::build_where_clause_for_insert()privateWC 1.0

Helper method to build where clause for action insert statement.

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

Хуков нет.

Возвращает

Строку. Where clause to be used with insert.

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

// private - только в коде основоного (родительского) класса
$result = $this->build_where_clause_for_insert( $data, $table_name, $unique );
$data(массив) (обязательный)
Row data for action.
$table_name(строка) (обязательный)
Action table name.
$unique(true|false) (обязательный)
Where action should be unique.

Код ActionScheduler_DBStore::build_where_clause_for_insert() 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';
}