Automattic\WooCommerce\Internal\Logging

OrderLogsCleanupHelper::cleanup_dangling_ordersprivateWC 1.0

Clean up a batch of orders with dangling debug log meta.

Dangling orders have _debug_log_source meta but no _debug_log_source_pending_deletion.

Method of the class: OrderLogsCleanupHelper{}

No Hooks.

Returns

true|false. True if there may be more orders left to clean up.

Usage

// private - for code of main (parent) class only
$result = $this->cleanup_dangling_orders( $max_age, $files_swept_in_bulk ): bool;
$max_age(int) (required)
Maximum age in seconds before an order's debug log meta is eligible for cleanup.
$files_swept_in_bulk(true|false) (required)
True if the file sweep is already deleting these orders' log files.

OrderLogsCleanupHelper::cleanup_dangling_orders() code WC 11.0.1

private function cleanup_dangling_orders( int $max_age, bool $files_swept_in_bulk ): bool {
	$dangling_orders = $this->get_dangling_orders( $max_age );

	if ( empty( $dangling_orders ) ) {
		return false;
	}

	// Clearing each order's log source individually scans the log directory once per
	// order, so it's only worth doing when the bulk sweep isn't deleting the files.
	$deleted = $files_swept_in_bulk
		? $this->delete_debug_log_meta_entries( array_keys( $dangling_orders ) )
		: $this->clear_logs_and_delete_meta_entries( $dangling_orders );

	return $deleted && self::MAX_ORDERS_PER_RUN === count( $dangling_orders );
}