Automattic\WooCommerce\Internal\VariationGallery

Package{} │ WC 1.0

Variation gallery package entry point.

Registered in \Automattic\WooCommerce\Packages::$merged_packages against the woocommerce-additional-variation-images slug, so this class is the single bootstrap surface for the merged variation gallery feature.

No Hooks.

Usage

$Package = new Package();
// use class methods

Methods

  1. public wc_get_container()
  2. public WC()->queue()
  3. public get( LegacyVariationGalleryCompatibility::class )->register()
  4. ERROR: no method name found on line `public const FEATURE_ID = 'variation_gallery';`
  5. public static is_enabled()
  6. ERROR: no method name found on line `public const ENABLE_OPTION_NAME = 'wc_feature_woocommerce_additional_variation_images_enabled';`
  7. public init()
  8. ERROR: no method name found on line `public const FEATURE_ID = 'variation_gallery';`
  9. public static is_in_canary_cohort()
  10. public static maybe_schedule_migration()
  11. public static prepare()
  12. public add_action( 'init', array( __CLASS__, 'maybe_schedule_migration' ), 20 )
  13. ERROR: no method name found on line `* @return bool`
  14. ERROR: no method name found on line `*`
  15. ERROR: no method name found on line `*`
  16. ERROR: no method name found on line ``
  17. ERROR: no method name found on line `}`
  18. ERROR: no method name found on line `*`
  19. ERROR: no method name found on line `/**`
  20. ERROR: no method name found on line `);`
  21. ERROR: no method name found on line `* @return bool`
  22. ERROR: no method name found on line ``
  23. ERROR: no method name found on line `*`
  24. ERROR: no method name found on line `* @return bool`
  25. ERROR: no method name found on line `*/`
  26. ERROR: no method name found on line `* @internal`
  27. private static has_pending_or_running_migration( array $args )
  28. ERROR: no method name found on line ``
  29. ERROR: no method name found on line `* Whether the current store is in the former canary cohort.`
  30. ERROR: no method name found on line `*`
  31. ERROR: no method name found on line ``
  32. ERROR: no method name found on line `* plugins_loaded priority -100. No-op for the variation gallery feature.`
  33. ERROR: no method name found on line `$args,`
  34. ERROR: no method name found on line `*`

Package{} code WC 11.1.2

class Package {

	/**
	 * Action Scheduler hook for DB update callbacks.
	 */
	private const UPDATE_CALLBACK_HOOK = 'woocommerce_run_update_callback';

	/**
	 * Action Scheduler group for DB update callbacks.
	 */
	private const UPDATE_CALLBACK_GROUP = 'woocommerce-db-updates';

	/**
	 * The feature id used by `FeaturesController` (Settings → Advanced → Features).
	 */
	public const FEATURE_ID = 'variation_gallery';

	/**
	 * Option backing the variation gallery feature toggle.
	 */
	public const ENABLE_OPTION_NAME = 'wc_feature_woocommerce_additional_variation_images_enabled';

	/**
	 * Highest variant bucket in the former canary cohort.
	 *
	 * @deprecated 11.1.0 The variation gallery is enabled for all users.
	 */
	public const CANARY_MAX_VARIANT = 6;

	/**
	 * Whether the current store is in the former canary cohort.
	 *
	 * @deprecated 11.1.0 Use Package::is_enabled() instead.
	 * @return bool
	 */
	public static function is_in_canary_cohort(): bool {
		wc_deprecated_function( __METHOD__, '11.1.0', __CLASS__ . '::is_enabled' );
		return self::is_enabled();
	}

	/**
	 * As of WooCommerce 11.1, the variation gallery is enabled for all users.
	 *
	 * @return bool
	 */
	public static function is_enabled() {
		return true;
	}

	/**
	 * Early bootstrap hook fired by `Packages::prepare_packages` at
	 * plugins_loaded priority -100. No-op for the variation gallery feature.
	 *
	 * @internal
	 */
	public static function prepare(): void {
	}

	/**
	 * Initialize the merged variation gallery feature.
	 *
	 * @internal
	 */
	final public static function init(): void {
		$container = wc_get_container();
		$container->get( ClassicVariationGalleryAdmin::class )->register();
		$container->get( LegacyVariationGalleryCompatibility::class )->register();

		// Action Scheduler initializes on `init`, not `plugins_loaded`.
		add_action( 'init', array( __CLASS__, 'maybe_schedule_migration' ), 20 );
	}

	/**
	 * Schedule the legacy variation gallery migration if it hasn't already
	 * completed and isn't already pending or running.
	 *
	 * @internal
	 */
	public static function maybe_schedule_migration(): void {
		if ( get_option( Migration::COMPLETED_OPTION ) ) {
			return;
		}

		$args = array( 'update_callback' => array( Migration::class, 'run' ) );

		if ( self::has_pending_or_running_migration( $args ) ) {
			return;
		}

		WC()->queue()->add(
			self::UPDATE_CALLBACK_HOOK,
			$args,
			self::UPDATE_CALLBACK_GROUP
		);
	}

	/**
	 * Determine whether the migration is already pending or running.
	 *
	 * @param array<string, array<int, string>> $args Exact callback args for the migration action.
	 * @return bool
	 */
	private static function has_pending_or_running_migration( array $args ): bool {
		if ( null !== WC()->queue()->get_next( self::UPDATE_CALLBACK_HOOK, $args, self::UPDATE_CALLBACK_GROUP ) ) {
			return true;
		}

		$running_actions = WC()->queue()->search(
			array(
				'hook'     => self::UPDATE_CALLBACK_HOOK,
				'args'     => $args,
				'status'   => \ActionScheduler_Store::STATUS_RUNNING,
				'per_page' => 1,
				'group'    => self::UPDATE_CALLBACK_GROUP,
			),
			'ids'
		);

		return ! empty( $running_actions );
	}
}