Automattic\WooCommerce\Internal\Logging

OrderLogsDeletionProcessor::process_batchpublicWC 1.0

Process a batch of items. Items are expected to be in the format returned by get_next_batch_to_process.

Method of the class: OrderLogsDeletionProcessor{}

No Hooks.

Returns

null. Nothing (null).

Usage

$OrderLogsDeletionProcessor = new OrderLogsDeletionProcessor();
$OrderLogsDeletionProcessor->process_batch( $batch ): void;
$batch(array) (required)
Batch of items to process.

OrderLogsDeletionProcessor::process_batch() code WC 10.5.0

public function process_batch( array $batch ): void {
	if ( empty( $batch ) ) {
		return;
	}

	if ( ! $this->hpos_in_use && ! $this->cpt_in_use ) {
		$this->throw_doing_it_wrong( StringUtil::class_name_without_namespace( __CLASS__ ) . '::' . __FUNCTION__ );
		return;
	}

	$logger = $this->legacy_proxy->call_function( 'wc_get_logger' );
	foreach ( $batch as $item ) {
		if ( ! is_array( $item ) || ! isset( $item['meta_value'] ) || ! isset( $item['order_id'] ) ) {
			throw new \Exception( "\$batch must be an array of arrays, each having a 'meta_value' key and an 'order_id' key" );
		}
		$logger->clear( $item['meta_value'] );
	}

	$order_ids = array_map( 'absint', array_column( $batch, 'order_id' ) );

	// Delete from the authoritative meta table.
	$this->delete_debug_log_source_meta_entries( true, $order_ids );

	if ( $this->data_synchronizer->data_sync_is_enabled() ) {
		// When HPOS data sync is enabled we need to manually delete the entries in the backup meta table too,
		// otherwise the next sync process will restore the rows we just deleted from the authoritative meta table.
		$this->delete_debug_log_source_meta_entries( false, $order_ids );
	}
}