Automattic\WooCommerce\Internal\Admin

OrderTaxLookupMigrator::process_batch │ public │ WC 1.0

Re-sync the orders in the batch, which writes one row per tax order item and, once they are all written, drops whatever the order no longer carries.

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

Хуков нет.

Возвращает

void. Ничего (null).

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

$OrderTaxLookupMigrator = new OrderTaxLookupMigrator();
$OrderTaxLookupMigrator->process_batch( $batch ): void;
$batch(массив) (обязательный)
Batch of order ids, as returned by 'get_next_batch_to_process'.

Код OrderTaxLookupMigrator::process_batch() WC 11.2.2

public function process_batch( array $batch ): void {
	global $wpdb;

	if ( empty( $batch ) ) {
		return;
	}

	foreach ( $batch as $order_id ) {
		$order_id = (int) $order_id;
		$synced   = TaxesDataStore::sync_order_taxes( $order_id );

		// The reports only see lookup rows they can join to a `wc_order_stats` row, so an order
		// without one is gone as far as Analytics is concerned and its rows can go. A failed
		// `wc_get_order()` is not the same thing: it also fails while the plugin that registers
		// the order's type is deactivated, and that order still has its stats row.
		if ( -1 === $synced && ! $this->order_has_stats_row( $order_id ) ) {
			$wpdb->delete( TaxesDataStore::get_db_table_name(), array( 'order_id' => $order_id ), array( '%d' ) );
			continue;
		}

		// A write that did not land leaves the order holding the rows it came in with, which
		// report the way they did before. The cursor steps past it either way, so record it as
		// a failed analytics import: that is the list Analytics settings offers a retry over,
		// and the retry re-imports the order, which is the same work this pass could not do.
		if ( false === $synced ) {
			wc_get_logger()->error(
				"Could not rebuild the analytics tax lookup rows of order {$order_id}. The order keeps the rows it had and reports the way it did before. It is recorded as a failed analytics import, so it can be retried from Analytics settings.",
				array( 'source' => 'wc-order-tax-lookup-migration' )
			);

			OrdersScheduler::record_failed_order_import( $order_id );
		}
	}

	// Step past every order in the batch, including any that could not be rebuilt, which are
	// left to the failed import retry. See CURSOR_OPTION.
	update_option( self::CURSOR_OPTION, max( array_map( 'absint', $batch ) ), false );

	ReportsCache::invalidate();
}