Automattic\WooCommerce\Internal\Admin
OrderTaxLookupMigrator::get_next_batch_to_process
Returns the ids of the next orders to rebuild.
Method of the class: OrderTaxLookupMigrator{}
No Hooks.
Returns
array. Batch of order ids, containing $size or less items.
Usage
$OrderTaxLookupMigrator = new OrderTaxLookupMigrator(); $OrderTaxLookupMigrator->get_next_batch_to_process( $size ): array;
- $size(int) (required)
- Maximum size of the batch to be returned.
OrderTaxLookupMigrator::get_next_batch_to_process() OrderTaxLookupMigrator::get next batch to process code WC 11.2.1
public function get_next_batch_to_process( int $size ): array {
global $wpdb;
// On a table the re-key in `WC_Install::create_tables()` never reached, the sync would
// write every row back at zero and the pass would park the cursor at the end of the table
// with nothing rebuilt. Hand out nothing instead: an empty batch retires the processor
// with the cursor where it stands, so the rebuild is still on offer once the re-key has
// landed.
if ( ! TaxesDataStore::lookup_is_keyed_by_order_item() ) {
return array();
}
$table_name = TaxesDataStore::get_db_table_name();
$order_ids = $wpdb->get_col(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is not user input.
"SELECT DISTINCT order_id FROM {$table_name} WHERE order_id > %d AND order_item_id = 0 ORDER BY order_id ASC LIMIT %d",
$this->get_cursor(),
$size
)
);
if ( $wpdb->last_error ) {
// An empty batch reads as "nothing left to do" and retires the processor, which would
// leave the rest of the table behind. Report the failure instead, which fails the
// scheduled action and leaves the controller's watchdog to schedule another attempt.
// The controller only counts failures its process_batch() call throws, so a database
// that stays broken is retried rather than retired.
throw new Exception( $wpdb->last_error ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
return array_map( 'absint', $order_ids );
}