Class: OnlineMigrations::DataMigrations::RewriteLegacyFaClassesInArticles
- Inherits:
-
OnlineMigrations::DataMigration
- Object
- OnlineMigrations::DataMigration
- OnlineMigrations::DataMigrations::RewriteLegacyFaClassesInArticles
- Defined in:
- lib/online_migrations/data_migrations/rewrite_legacy_fa_classes_in_articles.rb
Overview
Seo::FaClassRewriter is idempotent — already-canonical rows
are no-ops and contribute no DB writes.
update_columns is intentional. It skips
update_revised_at / publish_content_updated_event so this
doesn't look like a content edit to downstream consumers
(SEO recrawl, content-updated subscribers).
Rewrites legacy Font Awesome <i> class strings in stored
articles.solution and articles.description HTML to the project's
Sharp family (fa-sharp fa-solid / fa-sharp fa-regular).
Targets every Article STI subclass (Post, KB articles, FAQs,
procedures, technical, training) — anything whose body may render
in either the www or CRM SCSS bundle. After this migration succeeds
plus its article_revisions sibling, both bundles can drop the
solid.min.css import that exists today as a backstop for legacy
<i class="fa-solid …"> content.
Constant Summary collapse
- BATCH_SIZE =
Batch size — solution bodies are large, so keep batches small.
100- LEGACY_FA_REGEX =
Postgres POSIX regex (case-insensitive) that matches an
<i>tag
whoseclassattribute carries any legacy FA family token —
both long form (fa-solid,fa-regular,fa-light,fa-thin,
fa-duotone) and short form (fas,far,fal,fat,fad,
barefafor FA4-default markup).Anchored to
<i ... class="..."so plain body text containing
words like "fasten" or "fast" doesn't match.\m/\Mare
Postgres word-boundary anchors.Seo::FaClassRewriteris
idempotent, so any false positives that slip through are no-op
passes that don't write to the DB. %q{<i\y[^>]*\yclass\s*=\s*["'][^"']*\m(fa-solid|fa-regular|fa-light|fa-thin|fa-duotone|fas|far|fal|fat|fad|fa)\M}
Delegated Instance Attributes collapse
-
#count ⇒ Integer
Total number of candidate rows the SQL pre-filter selects.
Instance Method Summary collapse
-
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of candidate
Articlerows. -
#process(articles) ⇒ void
Rewrites every article in the batch in place.
Instance Method Details
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of candidate Article rows.
50 51 52 |
# File 'lib/online_migrations/data_migrations/rewrite_legacy_fa_classes_in_articles.rb', line 50 def collection candidate_relation.in_batches(of: BATCH_SIZE) end |
#count ⇒ Integer
Total number of candidate rows the SQL pre-filter selects.
Used by online_migrations for progress reporting.
71 |
# File 'lib/online_migrations/data_migrations/rewrite_legacy_fa_classes_in_articles.rb', line 71 delegate :count, to: :candidate_relation |
#process(articles) ⇒ void
This method returns an undefined value.
Rewrites every article in the batch in place. Already-canonical
rows incur a no-op pass (no DB write).
61 62 63 |
# File 'lib/online_migrations/data_migrations/rewrite_legacy_fa_classes_in_articles.rb', line 61 def process(articles) articles.each { |article| rewrite_article(article) } end |