Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateDivergenceDetector::run_sweeppublic staticWC 10.8.0

Run the post-upgrade divergence sweep.

Intended to be hooked on woocommerce_updated, which fires once per WC upgrade inside \WC_Install::check_version() under a distributed install lock — that guarantees the sweep runs at most once per upgrade without any additional fence option or cache lock on our side.

Early-returns when the RSM-149 backfill has not yet flagged completion, so we never classify a half-populated set of posts.

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

Возвращает

null. Ничего (null).

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

$result = WCEmailTemplateDivergenceDetector::run_sweep(): void;

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

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

Код WCEmailTemplateDivergenceDetector::run_sweep() WC 10.9.1

public static function run_sweep(): void {
	if ( 'yes' !== get_option( self::BACKFILL_COMPLETE_OPTION ) ) {
		return;
	}

	$registry = WCEmailTemplateSyncRegistry::get_sync_enabled_emails();
	if ( empty( $registry ) ) {
		return;
	}

	$posts_manager = WCTransactionalEmailPostsManager::get_instance();

	foreach ( $registry as $email_id => $_config ) {
		try {
			$post = $posts_manager->get_email_post( (string) $email_id );
			if ( ! $post instanceof \WP_Post ) {
				continue;
			}

			self::reclassify( (int) $post->ID );
		} catch ( \Throwable $e ) {
			self::get_logger()->error(
				sprintf(
					'Email template divergence sweep failed for email "%s": %s',
					(string) $email_id,
					$e->getMessage()
				),
				array(
					'email_id' => (string) $email_id,
					'context'  => 'email_template_divergence_detector',
				)
			);
			continue;
		}//end try
	}//end foreach

	/**
	 * Fires once after the post-upgrade divergence sweep finishes classifying
	 * every sync-registered email post.
	 *
	 * Hooked by {@see \Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCEmailTemplateAutoApplier::schedule()}
	 * to enqueue the batched auto-apply job for posts classified as
	 * `core_updated_uncustomized`. Fires unconditionally — auto-applier
	 * short-circuits when no candidates exist.
	 *
	 * @since 10.8.0
	 */
	do_action( 'woocommerce_email_template_divergence_sweep_complete' );
}