Class: OnlineMigrations::DataMigrations::DelocalizeBlogEmbedLinks

Inherits:
OnlineMigrations::DataMigration
  • Object
show all
Defined in:
lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb

Overview

Note:

Idempotent — Oembed::EmbedLinkDelocalizer leaves already-{{locale}}
links (and external / CDN links) untouched, so healed rows incur a no-op
pass and contribute no DB writes.

Note:

update_columns is intentional: it skips update_revised_at /
publish_content_updated_event, so this system rewrite doesn't look like
a content edit to downstream consumers (SEO recrawl, content-updated
subscribers). Mirrors RewriteLegacyFaClassesInArticles.

Heals blog posts whose oEmbed blocks baked a concrete locale into their
internal links — chiefly the unroutable bare /en/... fabricated when
Oembed::ContentRefreshService re-rendered an embed under the
framework-default :en locale, plus any hard-coded /en-US/ / /en-CA/
left by older refreshes.

Rewrites those links back to the {{locale}} placeholder via
Oembed::EmbedLinkDelocalizer — the same transform the now-fixed
ContentRefreshService applies after every refresh — so each post body
once again:

  • passes Blog::ContentRules#internal_links_use_locale_placeholder
    (i.e. is saveable through edit_blog_post), and
  • resolves to the correct per-market locale at display.

Constant Summary collapse

BATCH_SIZE =

Solution bodies are large, so keep batches small.

100
'(href|action)="(/|https?://www\.warmlyyours\.com/)(en-US|en-CA|fr-CA|en)/'
OEMBED_MARKER_SQL =

SQL OR-chain matching a post body that carries any oEmbed marker.

<<~SQL.squish
  solution LIKE '%data-wy-oembed%' OR solution LIKE '%wy-product-embed%'
  OR solution LIKE '%wy-faq-embed%' OR solution LIKE '%wy-video-embed%'
  OR solution LIKE '%wy-image-embed%'
SQL

Delegated Instance Attributes collapse

Instance Method Summary collapse

Instance Method Details

#collectionActiveRecord::Batches::BatchEnumerator

Yields batches of candidate Posts.

Returns:

  • (ActiveRecord::Batches::BatchEnumerator)

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



57
58
59
# File 'lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb', line 57

def collection
  candidate_relation.in_batches(of: BATCH_SIZE)
end

#countInteger

Total candidate rows the SQL pre-filter selects, for progress reporting.

Returns:

  • (Integer)

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



76
# File 'lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb', line 76

delegate :count, to: :candidate_relation

#process(posts) ⇒ void

This method returns an undefined value.

Heals every post in the batch in place. Already-canonical rows incur a
no-op pass (no DB write).

Parameters:

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



67
68
69
# File 'lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb', line 67

def process(posts)
  posts.each { |post| heal(post) }
end