diff --git a/plugins/woocommerce/changelog/fix-prevent-type-erorr-in-batch-processing b/plugins/woocommerce/changelog/fix-prevent-type-erorr-in-batch-processing new file mode 100644 index 00000000000..4bca714e8c9 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-prevent-type-erorr-in-batch-processing @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Prevent possible type error in BatchProcessingController. diff --git a/plugins/woocommerce/src/Internal/BatchProcessing/BatchProcessingController.php b/plugins/woocommerce/src/Internal/BatchProcessing/BatchProcessingController.php index bffe26bc7aa..d0a502d4844 100644 --- a/plugins/woocommerce/src/Internal/BatchProcessing/BatchProcessingController.php +++ b/plugins/woocommerce/src/Internal/BatchProcessing/BatchProcessingController.php @@ -220,17 +220,19 @@ class BatchProcessingController { * @return array Current state for the processor, or a "blank" state if none exists yet. */ private function get_process_details( BatchProcessorInterface $batch_processor ): array { - return get_option( - $this->get_processor_state_option_name( $batch_processor ), - array( - 'total_time_spent' => 0, - 'current_batch_size' => $batch_processor->get_default_batch_size(), - 'last_error' => null, - 'recent_failures' => 0, - 'batch_first_failure' => null, - 'batch_last_failure' => null, - ) + $defaults = array( + 'total_time_spent' => 0, + 'current_batch_size' => $batch_processor->get_default_batch_size(), + 'last_error' => null, + 'recent_failures' => 0, + 'batch_first_failure' => null, + 'batch_last_failure' => null, ); + + $process_details = get_option( $this->get_processor_state_option_name( $batch_processor ) ); + $process_details = wp_parse_args( is_array( $process_details ) ? $process_details : array(), $defaults ); + + return $process_details; } /** @@ -349,7 +351,15 @@ class BatchProcessingController { * @return array List (of string) of the class names of the enqueued processors. */ public function get_enqueued_processors(): array { - return get_option( self::ENQUEUED_PROCESSORS_OPTION_NAME, array() ); + $enqueued_processors = get_option( self::ENQUEUED_PROCESSORS_OPTION_NAME, array() ); + + if ( ! is_array( $enqueued_processors ) ) { + $this->logger->error( 'Could not fetch list of processors. Clearing up queue.', array( 'source' => 'batch-processing' ) ); + delete_option( self::ENQUEUED_PROCESSORS_OPTION_NAME ); + $enqueued_processors = array(); + } + + return $enqueued_processors; } /**