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.

Method of the class: OrderTaxLookupMigrator{}

No Hooks.

Returns

void. Nothing (null).

Usage

$OrderTaxLookupMigrator = new OrderTaxLookupMigrator();
$OrderTaxLookupMigrator->process_batch( $batch ): void;
$batch(array) (required)
Batch of order ids, as returned by 'get_next_batch_to_process'.

OrderTaxLookupMigrator::process_batch() code WC 11.3.0

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;
		}

		// The cursor steps past an order that could not be rebuilt, so record it as a failed
		// analytics import, which Analytics settings offers to retry.
		if ( true !== $synced ) {
			$reason = -1 === $synced
				? 'The order could not be read (which is what a deactivated order type plugin looks like) or has no creation date to report it by.'
				: 'The write did not land.';

			wc_get_logger()->error(
				"Could not rebuild the analytics tax lookup rows of order {$order_id}. {$reason} 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.
	$this->advance_cursors( array_map( 'absint', $batch ) );

	ReportsCache::invalidate();
}