; } /** * 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'] .= '
'; $entry['desc'] .= sprintf( '%1$s %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', '', __( '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 ) ); } }
Fatal error: Uncaught Automattic\WooCommerce\Internal\DependencyManagement\ContainerException: Attempt to get an instance of class 'Automattic\WooCommerce\Internal\DataStores\Orders\LegacyDataCleanup', which doesn't exist. in /htdocs/wp-content/plugins/woocommerce/src/Internal/DependencyManagement/RuntimeContainer.php:105 Stack trace: #0 /htdocs/wp-content/plugins/woocommerce/src/Internal/DependencyManagement/RuntimeContainer.php(185): Automattic\WooCommerce\Internal\DependencyManagement\RuntimeContainer->get_core('Automattic\\WooC...', Array) #1 [internal function]: Automattic\WooCommerce\Internal\DependencyManagement\RuntimeContainer->Automattic\WooCommerce\Internal\DependencyManagement\{closure}(Object(ReflectionParameter)) #2 /htdocs/wp-content/plugins/woocommerce/src/Internal/DependencyManagement/RuntimeContainer.php(173): array_map(Object(Closure), Array) #3 /htdocs/wp-content/plugins/woocommerce/src/Internal/DependencyManagement/RuntimeContainer.php(119): Automattic\WooCommerce\Internal\DependencyManagement\RuntimeContainer->instantiate_class_using_reflection('Automattic\\WooC...', Array) #4 /htdocs/wp-content/plugins/woocommerce/src/Internal/DependencyManagement/RuntimeContainer.php(78): Automattic\WooCommerce\Internal\DependencyManagement\RuntimeContainer->get_core('Automattic\\WooC...', Array) #5 /htdocs/wp-content/plugins/woocommerce/src/Container.php(68): Automattic\WooCommerce\Internal\DependencyManagement\RuntimeContainer->get('Automattic\\WooC...') #6 /htdocs/wp-content/plugins/woocommerce/includes/class-woocommerce.php(360): Automattic\WooCommerce\Container->get('Automattic\\WooC...') #7 /htdocs/wp-content/plugins/woocommerce/includes/class-woocommerce.php(265): WooCommerce->init_hooks() #8 /htdocs/wp-content/plugins/woocommerce/includes/class-woocommerce.php(166): WooCommerce->__construct() #9 /htdocs/wp-content/plugins/woocommerce/woocommerce.php(47): WooCommerce::instance() #10 /htdocs/wp-content/plugins/woocommerce/woocommerce.php(62): WC() #11 /htdocs/wp-settings.php(560): include_once('/htdocs/wp-cont...') #12 /htdocs/wp-config.php(98): require_once('/htdocs/wp-sett...') #13 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #14 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #15 /htdocs/index.php(17): require('/htdocs/wp-blog...') #16 {main} thrown in /htdocs/wp-content/plugins/woocommerce/src/Internal/DependencyManagement/RuntimeContainer.php on line 105
; } /** * 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'] .= '
'; $entry['desc'] .= sprintf( '%1$s %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', '', __( '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 ) ); } }