Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
WCEmailTemplateSyncBackfill::run
Action Scheduler entry point for the RSM-149 migration.
Always returns false (one-shot). The return type is declared bool to match the contract \WC_Install::run_update_callback_end() expects; (bool) false tells the queue manager this callback is complete and should not be re-scheduled.
The woocommerce_db_version fence around $db_updates provides the once-per-site guarantee, so there is no internal idempotency gate here; retry-safety comes from the NOT EXISTS filter on the stored source hash in {@see self::fetch_eligible_posts()}.
Method of the class: WCEmailTemplateSyncBackfill{}
No Hooks.
Returns
true|false. Always false.
Usage
$result = WCEmailTemplateSyncBackfill::run(): bool;
Changelog
| Since 10.8.0 | Introduced. |
WCEmailTemplateSyncBackfill::run() WCEmailTemplateSyncBackfill::run code WC 10.8.1
public static function run(): bool {
$eligible = self::fetch_eligible_posts();
if ( empty( $eligible ) ) {
self::finalize();
return false;
}
$registry = WCEmailTemplateSyncRegistry::get_sync_enabled_emails();
if ( empty( $registry ) ) {
self::finalize();
return false;
}
$posts_manager = WCTransactionalEmailPostsManager::get_instance();
$emails_by_id = $posts_manager->get_emails_by_id();
foreach ( $eligible as $row ) {
try {
$post_id = (int) $row->ID;
$email_id = (string) $posts_manager->get_email_type_from_post_id( $post_id );
if ( '' === $email_id || ! isset( $registry[ $email_id ] ) ) {
continue;
}
$email = $emails_by_id[ $email_id ] ?? null;
if ( ! $email instanceof \WC_Email ) {
continue;
}
$canonical_post_content = WCTransactionalEmailPostsGenerator::compute_canonical_post_content( $email );
$current_core_hash = sha1( $canonical_post_content );
$case_id = self::classify( $row, $current_core_hash );
self::apply_case_to_post( $post_id, $case_id, $canonical_post_content, $current_core_hash, $email );
} catch ( \Throwable $e ) {
self::get_logger()->error(
sprintf(
'Email template sync backfill failed for post %d: %s',
(int) $row->ID,
$e->getMessage()
),
array(
'post_id' => (int) $row->ID,
'context' => 'email_template_sync_backfill',
)
);
continue;
}//end try
}//end foreach
self::finalize();
return false;
}