Automattic\WooCommerce\Internal\BatchProcessing

BatchProcessingController::enqueued_list_needs_updateprivateWC 11.0.0

Determine whether the stored enqueued-processors list needs to be rewritten to include a given processor or to heal pre-existing corruption (duplicates or non-string entries).

Method of the class: BatchProcessingController{}

No Hooks.

Returns

true|false. True if the list should be rewritten, false if it is already clean and contains the processor.

Usage

// private - for code of main (parent) class only
$result = $this->enqueued_list_needs_update( $processors, $processor_class_name ): bool;
$processors(array) (required)
Current list of enqueued processors.
$processor_class_name(string) (required)
Fully qualified class name of the processor to ensure is enqueued.

Changelog

Since 11.0.0 Introduced.

BatchProcessingController::enqueued_list_needs_update() code WC 11.0.1

private function enqueued_list_needs_update( array $processors, string $processor_class_name ): bool {
	$seen           = array();
	$contains_class = false;
	foreach ( $processors as $value ) {
		if ( ! is_string( $value ) || isset( $seen[ $value ] ) ) {
			// Non-string entry or duplicate: the list needs healing.
			return true;
		}
		$seen[ $value ] = true;
		if ( $value === $processor_class_name ) {
			$contains_class = true;
		}
	}

	return ! $contains_class;
}