REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 7.45 KB
Close
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/Internal/DataStores/Orders/LegacyDataCleanup.php
Text
Base64
<?php /** * LegacyDataCleanup class file. */ namespace Automattic\WooCommerce\Internal\DataStores\Orders; use Automattic\WooCommerce\Internal\BatchProcessing\BatchProcessingController; use Automattic\WooCommerce\Internal\BatchProcessing\BatchProcessorInterface; defined( 'ABSPATH' ) || exit; /** * This class handles the background process in charge of cleaning up legacy data for orders when HPOS is authoritative. */ class LegacyDataCleanup implements BatchProcessorInterface { /** * Option name for this feature. * * @deprecated 9.1.0 */ public const OPTION_NAME = 'woocommerce_hpos_legacy_data_cleanup_in_progress'; /** * The default number of orders to process per batch. */ private const BATCH_SIZE = 25; /** * The batch processing controller to use. * * @var BatchProcessingController */ private $batch_processing; /** * The legacy handler to use for the actual cleanup. * * @var LegacyHandler */ private $legacy_handler; /** * The data synchronizer object to use. * * @var DataSynchronizer */ private $data_synchronizer; /** * Logger object to be used to log events. * * @var \WC_Logger */ private $error_logger; /** * Class initialization, invoked by the DI container. * * @param BatchProcessingController $batch_processing The batch processing controller to use. * @param LegacyDataHandler $legacy_handler Legacy order data handler instance. * @param DataSynchronizer $data_synchronizer Data synchronizer instance. * @internal */ final public function init( BatchProcessingController $batch_processing, LegacyDataHandler $legacy_handler, DataSynchronizer $data_synchronizer ) { $this->legacy_handler = $legacy_handler; $this->data_synchronizer = $data_synchronizer; $this->batch_processing = $batch_processing; $this->error_logger = wc_get_logger(); } /** * A user friendly name for this process. * * @return string Name of the process. */ public function get_name(): string { return 'Order legacy data cleanup'; } /** * A user friendly description for this process. * * @return string Description. */ public function get_description(): string { return 'Cleans up order data from legacy tables.'; } /** * Get total number of pending records that require update. * * @return int Number of pending records. */ public function get_total_pending_count(): int { return $this->can_run() ? $this->legacy_handler->count_orders_for_cleanup() : 0; } /** * Returns the batch with records that needs to be processed for a given size. * * @param int $size Size of the batch. * @return array Batch of records. */ public function get_next_batch_to_process( int $size ): array { return $this->can_run() ? array_map( 'absint', $this->legacy_handler->get_orders_for_cleanup( array(), $size ) ) : array(); } /** * Process data for current batch. * * @param array $batch Batch details. */ public function process_batch( array $batch ): void { // This is a destructive operation, so check if we need to bail out just in case. if ( ! $this->can_run() ) { $this->toggle_flag( false ); return; } $batch_failed = true; foreach ( $batch as $order_id ) { try { $this->legacy_handler->cleanup_post_data( absint( $order_id ) ); $batch_failed = false; } catch ( \Exception $e ) { $this->error_logger->error( sprintf( // translators: %1$d is an order ID, %2$s is an error message. __( 'Order %1$d legacy data could not be cleaned up during batch process. Error: %2$s', 'woocommerce' ), $order_id, $e->getMessage() ) ); } } if ( $batch_failed ) { $this->error_logger->error( __( 'Order legacy cleanup failed for an entire batch of orders. Aborting cleanup.', 'woocommerce' ) ); } if ( ! $this->orders_pending() || $batch_failed ) { $this->toggle_flag( false ); } } /** * Default batch size to use. * * @return int Default batch size. */ public function get_default_batch_size(): int { return self::BATCH_SIZE; } /** * Determine whether the cleanup process can be initiated. Legacy data cleanup requires HPOS to be authoritative and * compatibility mode to be disabled. * * @return boolean TRUE if the cleanup process can be enabled, FALSE otherwise. */ public function can_run() { return $this->data_synchronizer->custom_orders_table_is_authoritative() && ! $this->data_synchronizer->data_sync_is_enabled() && ! $this->batch_processing->is_enqueued( get_class( $this->data_synchronizer ) ); } /** * Whether the user has initiated the cleanup process. * * @return boolean TRUE if the user has initiated the cleanup process, FALSE otherwise. */ public function is_flag_set() { return $this->batch_processing->is_enqueued( self::class ); } /** * Sets the flag that indicates that the cleanup process should be initiated. * * @param boolean $enabled TRUE if the process should be initiated, FALSE if it should be canceled. * @return boolean Whether the legacy data cleanup was initiated or not. */ public function toggle_flag( bool $enabled ): bool { if ( $enabled && $this->can_run() ) { $this->batch_processing->enqueue_processor( self::class ); return true; } else { $this->batch_processing->remove_processor( self::class ); return $enabled ? false : true; } } /** * Returns an array in format required by 'woocommerce_debug_tools' to register the cleanup tool in WC. * * @return array Tools entries to register with WC. */ public function get_tools_entries() { $orders_for_cleanup_exist = ! empty( $this->legacy_handler->get_orders_for_cleanup( array(), 1 ) ); $entry_id = $this->is_flag_set() ? 'hpos_legacy_cleanup_cancel' : 'hpos_legacy_cleanup'; $entry = array( 'name' => __( 'Clean up order data from legacy tables', 'woocommerce' ), 'desc' => __( 'This tool will clear the data from legacy order tables in WooCommerce.', 'woocommerce' ), 'requires_refresh' => true, 'button' => __( 'Clear data', 'woocommerce' ), 'disabled' => ! ( $this->can_run() && ( $orders_for_cleanup_exist || $this->is_flag_set() ) ), ); if ( ! $this->can_run() ) { $entry['desc'] .= '<br />'; $entry['desc'] .= sprintf( '<strong class="red">%1$s</strong> %2$s', __( 'Note:', 'woocommerce' ), __( 'Only available when HPOS is authoritative and compatibility mode is disabled.', 'woocommerce' ) ); } else { if ( $this->is_flag_set() ) { $entry['status_text'] = sprintf( '%1$s %2$s', '<span class="dashicons dashicons-update spin"></span>', __( 'Clearing data...', 'woocommerce' ) ); $entry['button'] = __( 'Cancel', 'woocommerce' ); $entry['callback'] = function() { $this->toggle_flag( false ); return __( 'Order legacy data cleanup has been canceled.', 'woocommerce' ); }; } elseif ( ! $orders_for_cleanup_exist ) { $entry['button'] = __( 'No orders in need of cleanup', 'woocommerce' ); } else { $entry['callback'] = function() { $this->toggle_flag( true ); return __( 'Order legacy data cleanup process has been started.', 'woocommerce' ); }; } } return array( $entry_id => $entry ); } /** * Checks whether there are any orders in need of cleanup and cleanup can run. * * @return bool TRUE if there are orders in need of cleanup, FALSE otherwise. */ private function orders_pending() { return ! empty( $this->get_next_batch_to_process( 1 ) ); } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 11
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
CustomOrdersTableController.php
29.09 KB
lrw-r--r--
2026-04-07 17:35:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
DataSynchronizer.php
36.03 KB
lrw-r--r--
2025-11-24 23:10:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
LegacyDataCleanup.php
7.45 KB
lrw-r--r--
2024-12-18 22:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
LegacyDataHandler.php
20.93 KB
lrw-r--r--
2026-01-19 14:46:18
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OrdersTableDataStore.php
116.29 KB
lrw-r--r--
2026-05-25 14:01:26
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OrdersTableDataStoreMeta.php
5.64 KB
lrw-r--r--
2024-12-18 22:19:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OrdersTableFieldQuery.php
8.51 KB
lrw-r--r--
2024-01-30 23:24:56
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OrdersTableMetaQuery.php
18.69 KB
lrw-r--r--
2024-11-14 01:17:00
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OrdersTableQuery.php
48.50 KB
lrw-r--r--
2026-05-25 14:01:26
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OrdersTableRefundDataStore.php
6.31 KB
lrw-r--r--
2026-05-11 17:17:08
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OrdersTableSearchQuery.php
14.48 KB
lrw-r--r--
2025-07-29 12:34:58
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).