Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog

AsyncGenerator::force_regenerationpublicWC 10.5.0

Forces a regeneration of the feed.

Метод класса: AsyncGenerator{}

Хуков нет.

Возвращает

Массив. The feed generation status.

Использование

$AsyncGenerator = new AsyncGenerator();
$AsyncGenerator->force_regeneration( ?array $args ): array;
?array $args
.
По умолчанию: null

Список изменений

С версии 10.5.0 Введена.

Код AsyncGenerator::force_regeneration() WC 10.5.2

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

	// If there is no option, there is nothing to force. If the option is invalid, we can restart.
	if ( ! is_array( $status ) || ! $this->validate_status( $status ) ) {
		return $this->get_status( $args );
	}

	switch ( $status['state'] ?? '' ) {
		case self::STATE_SCHEDULED:
			// If generation is scheduled, we can just let it be and return the current status.
			// It should start shortly.
			return $status;

		case self::STATE_IN_PROGRESS:
			throw new \Exception( 'Feed generation is already in progress and cannot be stopped.' );

		case self::STATE_COMPLETED:
			// Delete the existing file, clear the option and let generation start again.
			wp_delete_file( (string) $status['path'] );
			delete_option( $option_key );
			return $this->get_status( $args );

		case self::STATE_FAILED:
			// Clear the failed status and restart generation.
			delete_option( $option_key );
			return $this->get_status( $args );

		default:
			throw new \Exception( 'Unknown feed generation state.' );
	}
}