Prevent type error in `BatchProcessingController` (#49728)
This PR introduces some type checking around the value of options involved in batch processing, particularly the one controlling which processors are enqueued. * Add changelog * Make BatchProcessingController's handling of internal options more robust * Remove queue if invalid * Implement suggestion
This commit is contained in:
parent
8c82d8dff3
commit
d53744187f
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Prevent possible type error in BatchProcessingController.
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue