Automattic\WooCommerce\Internal\Admin

OrderTaxLookupMigrator::advance_cursors │ private │ WC 1.0

Step every pass past the orders the batch covered.

A pass never moves back, and stops short of any order it still has to rebuild that the batch left out. That happens when the pass came on offer while the batch was in flight.

Method of the class: OrderTaxLookupMigrator{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->advance_cursors( $batch ): void;
$batch(non-empty-array) (required)
Order ids of the batch.

OrderTaxLookupMigrator::advance_cursors() code WC 11.3.0

private function advance_cursors( array $batch ): void {
	global $wpdb;

	$table_name   = TaxesDataStore::get_db_table_name();
	$last         = max( $batch );
	$placeholders = implode( ', ', array_fill( 0, count( $batch ), '%d' ) );

	foreach ( $this->get_pending_passes() as $pass ) {
		$cursor = $this->get_cursor( $pass['cursor'] );

		if ( $cursor >= $last ) {
			continue;
		}

		$skipped = $wpdb->get_var(
			$wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- The values come as one array.
				// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is not user input.
				"SELECT MIN(order_id) FROM {$table_name} WHERE order_id > %d AND order_id < %d AND order_id NOT IN ( {$placeholders} ) AND ( {$pass['condition']} )",
				array_merge( array( $cursor, $last ), $batch )
			)
		);

		if ( $wpdb->last_error ) {
			continue;
		}

		update_option( $pass['cursor'], null === $skipped ? $last : (int) $skipped - 1, false );
	}
}