elseif ( self::DB_STATUS === $args['status'] ) { $args['status'] = ''; } elseif ( is_array( $args['status'] ) ) { $args['status'] = array_diff_key( $args['status'], array( self::STATUS => null ) ); } return $args; } /** * Append draft status to a list of statuses. * * @param array $statuses Array of statuses. * @internal * @return array */ public function append_draft_order_post_status( $statuses ) { $statuses[] = self::STATUS; return $statuses; } /** * Delete draft orders older than a day in batches of 20. * * Ran on a daily cron schedule. * * @internal */ public function delete_expired_draft_orders() { $count = 0; $batch_size = 20; $this->ensure_draft_status_registered(); $orders = wc_get_orders( [ 'date_modified' => '<=' . strtotime( '-1 DAY' ), 'limit' => $batch_size, 'status' => self::DB_STATUS, 'type' => 'shop_order', ] ); // do we bail because the query results are unexpected? try { $this->assert_order_results( $orders, $batch_size ); if ( $orders ) { foreach ( $orders as $order ) { $order->delete( true ); $count ++; } } if ( $batch_size === $count && function_exists( 'as_enqueue_async_action' ) ) { as_enqueue_async_action( 'woocommerce_cleanup_draft_orders' ); } } catch ( Exception $error ) { wc_caught_exception( $error, __METHOD__ ); } } /** * Since it's possible for third party code to clobber the `$wp_post_statuses` global, * we need to do a final check here to make sure the draft post status is * registered with the global so that it is not removed by WP_Query status * validation checks. */ private function ensure_draft_status_registered() { $is_registered = get_post_stati( [ 'name' => self::DB_STATUS ] ); if ( empty( $is_registered ) ) { register_post_status( self::DB_STATUS, $this->get_post_status_properties() ); } } /** * Asserts whether incoming order results are expected given the query * this service class executes. * * @param WC_Order[] $order_results The order results being asserted. * @param int $expected_batch_size The expected batch size for the results. * @throws Exception If any assertions fail, an exception is thrown. */ private function assert_order_results( $order_results, $expected_batch_size ) { // if not an array, then just return because it won't get handled // anyways. if ( ! is_array( $order_results ) ) { return; } $suffix = ' This is an indicator that something is filtering WooCommerce or WordPress queries and modifying the query parameters.'; // if count is greater than our expected batch size, then that's a problem. if ( count( $order_results ) > 20 ) { throw new Exception( 'There are an unexpected number of results returned from the query.' . $suffix ); } // if any of the returned orders are not draft (or not a WC_Order), then that's a problem. foreach ( $order_results as $order ) { if ( ! ( $order instanceof WC_Order ) ) { throw new Exception( 'The returned results contain a value that is not a WC_Order.' . $suffix ); } if ( ! $order->has_status( self::STATUS ) ) { throw new Exception( 'The results contain an order that is not a `wc-checkout-draft` status in the results.' . $suffix ); } } } }
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Blocks\Domain\Services\DraftOrders" not found in /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php:285 Stack trace: #0 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Domain\Bootstrap->Automattic\WooCommerce\Blocks\Domain\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #1 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #2 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #3 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(128): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #4 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(80): Automattic\WooCommerce\Blocks\Domain\Bootstrap->init() #5 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Package.php(124): Automattic\WooCommerce\Blocks\Domain\Bootstrap->__construct(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #6 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Package::Automattic\WooCommerce\Blocks\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #7 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #8 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #9 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Package.php(44): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #10 [internal function]: Automattic\WooCommerce\Blocks\Package::init() #11 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(128): call_user_func(Array) #12 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(64): Automattic\WooCommerce\Packages::initialize_packages() #13 /htdocs/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Packages::on_init('') #14 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #15 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #16 /htdocs/wp-settings.php(559): do_action('plugins_loaded') #17 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #18 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #19 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #20 /htdocs/index.php(17): require('/htdocs/wp-blog...') #21 {main} thrown in /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php on line 285
) ) { $relative_path = trim( substr( $frame['file'], strlen( $path ) ), DIRECTORY_SEPARATOR ); if ( 'mu-plugin' === $type ) { $info = pathinfo( $relative_path ); if ( '.' === $info['dirname'] ) { $source = "$type-" . $info['filename']; } else { $source = "$type-" . $info['dirname']; } break 2; } $segments = explode( DIRECTORY_SEPARATOR, $relative_path ); if ( is_array( $segments ) ) { $source = "$type-" . reset( $segments ); } break 2; } } } if ( ! $source ) { $source = 'log'; } return sanitize_title( $source ); } /** * Delete all logs from a specific source. * * @param string $source The source of the log entries. * * @return int The number of files that were deleted. */ public function clear( string $source ): int { $source = File::sanitize_source( $source ); $files = $this->file_controller->get_files( array( 'source' => $source, ) ); if ( is_wp_error( $files ) || count( $files ) < 1 ) { return 0; } $file_ids = array_map( fn( $file ) => $file->get_file_id(), $files ); $deleted = $this->file_controller->delete_files( $file_ids ); if ( $deleted > 0 ) { $this->handle( time(), 'info', sprintf( esc_html( // translators: %1$s is a number of log files, %2$s is a slug-style name for a file. _n( '%1$s log file from source %2$s was deleted.', '%1$s log files from source %2$s were deleted.', $deleted, 'woocommerce' ) ), number_format_i18n( $deleted ), sprintf( '%s', esc_html( $source ) ) ), array( 'source' => 'wc_logger', 'backtrace' => true, ) ); } return $deleted; } /** * Delete all logs older than a specified timestamp. * * @param int $timestamp All files created before this timestamp will be deleted. * * @return int The number of files that were deleted. */ public function delete_logs_before_timestamp( int $timestamp = 0 ): int { if ( ! $timestamp ) { return 0; } $files = $this->file_controller->get_files( array( 'date_filter' => 'created', 'date_start' => 1, 'date_end' => $timestamp, ) ); if ( is_wp_error( $files ) ) { return 0; } $files = array_filter( $files, function( $file ) use ( $timestamp ) { /** * Allows preventing an expired log file from being deleted. * * @param bool $delete True to delete the file. * @param File $file The log file object. * @param int $timestamp The expiration threshold. * * @since 8.7.0 */ $delete = apply_filters( 'woocommerce_logger_delete_expired_file', true, $file, $timestamp ); return boolval( $delete ); } ); if ( count( $files ) < 1 ) { return 0; } $file_ids = array_map( fn( $file ) => $file->get_file_id(), $files ); $deleted = $this->file_controller->delete_files( $file_ids ); $retention_days = $this->settings->get_retention_period(); if ( $deleted > 0 ) { $this->handle( time(), 'info', sprintf( esc_html( // translators: %s is a number of log files. _n( '%s expired log file was deleted.', '%s expired log files were deleted.', $deleted, 'woocommerce' ) ), number_format_i18n( $deleted ) ), array( 'source' => 'wc_logger', ) ); } return $deleted; } }
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2" not found in /htdocs/wp-content/plugins/woocommerce/includes/class-wc-logger.php:58 Stack trace: #0 /htdocs/wp-content/plugins/woocommerce/includes/class-wc-logger.php(176): WC_Logger->get_handlers() #1 /htdocs/wp-content/plugins/woocommerce/includes/class-wc-logger.php(236): WC_Logger->log('critical', 'Uncaught Error:...', Array) #2 /htdocs/wp-content/plugins/woocommerce/includes/class-woocommerce.php(358): WC_Logger->critical('Uncaught Error:...', Array) #3 [internal function]: WooCommerce->log_errors() #4 {main} thrown in /htdocs/wp-content/plugins/woocommerce/includes/class-wc-logger.php on line 58