Automattic\WooCommerce\Internal\Logging

OrderLogsCleanupHelper::delete_debug_log_meta_entriesprivateWC 1.0

Delete _debug_log_source and _debug_log_source_pending_deletion meta entries for the given order IDs from the authoritative table and the backup table (when data sync is enabled).

Method of the class: OrderLogsCleanupHelper{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->delete_debug_log_meta_entries( $order_ids ): void;
$order_ids(array) (required)
Array of order IDs to delete meta for.

OrderLogsCleanupHelper::delete_debug_log_meta_entries() code WC 10.8.1

private function delete_debug_log_meta_entries( array $order_ids ): void {
	global $wpdb;

	$tables = array(
		array(
			'table'     => $this->hpos_in_use ? "{$wpdb->prefix}wc_orders_meta" : $wpdb->postmeta,
			'id_column' => $this->hpos_in_use ? 'order_id' : 'post_id',
		),
	);

	if ( $this->data_synchronizer->data_sync_is_enabled() ) {
		$tables[] = array(
			'table'     => $this->hpos_in_use ? $wpdb->postmeta : "{$wpdb->prefix}wc_orders_meta",
			'id_column' => $this->hpos_in_use ? 'post_id' : 'order_id',
		);
	}

	$id_placeholders = implode( ',', array_fill( 0, count( $order_ids ), '%d' ) );

	foreach ( $tables as $table_config ) {
		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
		$wpdb->query(
			$wpdb->prepare(
				"DELETE FROM {$table_config['table']}
				 WHERE {$table_config['id_column']} IN ({$id_placeholders})
				 AND meta_key IN (%s, %s)",
				array_merge( $order_ids, array( '_debug_log_source', '_debug_log_source_pending_deletion' ) )
			)
		);
		// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
	}
}