Automattic\WooCommerce\DataBase\Migrations\CustomOrderTable

CLIRunner::get_verify_order_count()privateWC 1.0

Helper method to get count for orders needing verification.

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

Хуков нет.

Возвращает

int. Order count.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_verify_order_count( $order_id_start, $order_id_end, $order_types, $log ) : int;
$order_id_start(int) (обязательный)
Order ID to start from.
$order_id_end(int) (обязательный)
Order ID to end at.
$order_types(массив) (обязательный)
List of order types to verify.
$log(true|false)
Whether to also log an error message.
По умолчанию: true

Код CLIRunner::get_verify_order_count() WC 8.7.0

private function get_verify_order_count( int $order_id_start, int $order_id_end, array $order_types, bool $log = true ) : int {
	global $wpdb;

	$order_types_placeholder = implode( ',', array_fill( 0, count( $order_types ), '%s' ) );

	// phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Inputs are prepared.
	$order_count = (int) $wpdb->get_var(
		$wpdb->prepare(
			"SELECT COUNT(*) FROM $wpdb->posts WHERE post_type in ($order_types_placeholder) AND ID >= %d AND ID <= %d",
			array_merge(
				$order_types,
				array(
					$order_id_start,
					$order_id_end,
				)
			)
		)
	);
	// phpcs:enable

	if ( $log ) {
		WP_CLI::log(
			sprintf(
				/* Translators: %1$d is the number of orders to be verified. */
				_n(
					'There is %1$d order to be verified.',
					'There are %1$d orders to be verified.',
					$order_count,
					'woocommerce'
				),
				$order_count
			)
		);
	}

	return $order_count;
}