Automattic\WooCommerce\DataBase\Migrations\CustomOrderTable

CLIRunner::verify_cot_data()publicWC 1.0

Verify migrated order data with original posts data.

OPTIONS

[--batch-size=<batch-size>]
The number of orders to verify in each batch.
--- default: 500
---
[--start-from=<order_id>]
Order ID to start from.
--- default: 0
---

EXAMPLES

# Verify migrated order data, 500 orders at a time.
wp wc cot verify_cot_data --batch-size=500 --start-from=0

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

Хуков нет.

Возвращает

null. Ничего.

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

$CLIRunner = new CLIRunner();
$CLIRunner->verify_cot_data( $args, $assoc_args );
$args(массив)
Positional arguments passed to the command.
По умолчанию: array()
$assoc_args(массив)
Associative arguments (options) passed to the command.
По умолчанию: array()

Код CLIRunner::verify_cot_data() WC 6.7.0

public function verify_cot_data( $args = array(), $assoc_args = array() ) {
	global $wpdb;
	$this->log_production_warning();
	if ( ! $this->is_enabled() ) {
		return;
	}

	$assoc_args = wp_parse_args(
		$assoc_args,
		array(
			'batch-size' => 500,
			'start-from' => 0,
		)
	);

	$batch_count    = 1;
	$total_time     = 0;
	$failed_ids     = array();
	$processed      = 0;
	$order_id_start = (int) $assoc_args['start-from'];
	$order_count    = $this->get_verify_order_count( $order_id_start );
	$batch_size     = ( (int) $assoc_args['batch-size'] ) === 0 ? 500 : (int) $assoc_args['batch-size'];

	$progress = WP_CLI\Utils\make_progress_bar( 'Order Data Verification', $order_count / $batch_size );

	if ( ! $order_count ) {
		return WP_CLI::warning( __( 'There are no orders to verify, aborting.', 'woocommerce' ) );
	}

	while ( $order_count > 0 ) {
		WP_CLI::debug(
			sprintf(
				/* Translators: %1$d is the batch number, %2$d is the batch size. */
				__( 'Beginning verification for batch #%1$d (%2$d orders/batch).', 'woocommerce' ),
				$batch_count,
				$batch_size
			)
		);

		$order_ids        = $wpdb->get_col(
			$wpdb->prepare(
				"SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order' AND ID > %d ORDER BY ID ASC LIMIT %d",
				$order_id_start,
				$batch_size
			)
		);
		$batch_start_time = microtime( true );
		$failed_ids       = $failed_ids + $this->post_to_cot_migrator->verify_migrated_orders( $order_ids );
		$failed_ids       = $this->verify_meta_data( $order_ids, $failed_ids );
		$processed       += count( $order_ids );
		$batch_total_time = microtime( true ) - $batch_start_time;
		$batch_count ++;
		$total_time += $batch_total_time;

		$progress->tick();

		WP_CLI::debug(
			sprintf(
				/* Translators: %1$d is the batch number, %2$d is time taken to process batch. */
				__( 'Batch %1$d (%2$d orders) completed in %3$d seconds.', 'woocommerce' ),
				$batch_count,
				count( $order_ids ),
				$batch_total_time
			)
		);

		$order_id_start  = max( $order_ids );
		$remaining_count = $this->get_verify_order_count( $order_id_start, false );
		if ( $remaining_count === $order_count ) {
			return WP_CLI::error( __( 'Infinite loop detected, aborting. No errors found.', 'woocommerce' ) );
		}
		$order_count = $remaining_count;
	}

	$progress->finish();
	WP_CLI::log( __( 'Verification completed.', 'woocommerce' ) );

	if ( 0 === count( $failed_ids ) ) {
		return WP_CLI::success(
			sprintf(
				/* Translators: %1$d is the number of migrated orders and %2$d is time taken. */
				_n(
					'%1$d order was verified in %2$d seconds.',
					'%1$d orders were verified in %2$d seconds.',
					$processed,
					'woocommerce'
				),
				$processed,
				$total_time
			)
		);
	} else {
		$errors = print_r( $failed_ids, true );

		return WP_CLI::error(
			sprintf(
				'%1$s %2$s',
				sprintf(
					/* Translators: %1$d is the number of migrated orders and %2$d is the execution time in seconds. */
					_n(
						'%1$d order was verified in %2$d seconds.',
						'%1$d orders were verified in %2$d seconds.',
						$processed,
						'woocommerce'
					),
					$processed,
					$total_time
				),
				sprintf(
					/* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
					_n(
						'%1$d error found: %2$s. Please review the error above.',
						'%1$d errors found: %2$s. Please review the errors above.',
						count( $failed_ids ),
						'woocommerce'
					),
					count( $failed_ids ),
					$errors
				)
			)
		);
	}
}