Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog

AsyncGenerator::force_regenerationpublicWC 10.5.0

Forces a regeneration of the feed.

Method of the class: AsyncGenerator{}

No Hooks.

Returns

Array. The feed generation status.

Usage

$AsyncGenerator = new AsyncGenerator();
$AsyncGenerator->force_regeneration( ?array $args ): array;
?array $args
.
Default: null

Changelog

Since 10.5.0 Introduced.

AsyncGenerator::force_regeneration() code WC 11.0.0

public function force_regeneration( ?array $args = null ): array {
	$option_key = $this->get_option_key( $args );
	$status     = get_option( $option_key );

	// An invalid status (stale, expired, or a stalled in-progress job) always regenerates from
	// scratch: discard any partial feed and clear the option so the restart starts clean.
	if ( ! is_array( $status ) || ! $this->validate_status( $status ) ) {
		if ( is_array( $status ) ) {
			// A stuck in-progress job adapts its chunk size on a forced rebuild too, the same way an
			// ordinary poll does, so the rebuild does not re-die at the size that just got it killed.
			$this->reduce_chunk_size_if_stuck( $status, $option_key );
			$this->discard_feed( $status );
			delete_option( $option_key );
		}
		return $this->get_status( $args );
	}

	switch ( $status['state'] ?? '' ) {
		case self::STATE_SCHEDULED:
			// Generation is already scheduled and should start shortly; leave it be.
			return $status;

		case self::STATE_IN_PROGRESS:
			// A genuinely running job (fresh heartbeat) cannot be interrupted mid-flight.
			throw new \Exception( 'Feed generation is already in progress and cannot be stopped.' );

		case self::STATE_COMPLETED:
			$this->discard_feed( $status );
			delete_option( $option_key );
			return $this->get_status( $args );

		// A failed job is invalid (see validate_status()), so it never reaches this switch; it is
		// discarded and regenerated by the early return above.
		default:
			throw new \Exception( 'Unknown feed generation state.' );
	}
}