Class: OnlineMigrations::DataMigrations::RewriteLegacyFaClassesInArticles

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

Overview

Note:

Seo::FaClassRewriter is idempotent — already-canonical rows
are no-ops and contribute no DB writes.

Note:

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
whose class attribute 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,
bare fa for FA4-default markup).

Anchored to <i ... class="..." so plain body text containing
words like "fasten" or "fast" doesn't match. \m / \M are
Postgres word-boundary anchors. Seo::FaClassRewriter is
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

Instance Method Summary collapse

Instance Method Details

#collectionActiveRecord::Batches::BatchEnumerator

Yields batches of candidate Article rows.

Returns:

  • (ActiveRecord::Batches::BatchEnumerator)

    over rows whose
    solution or description matches LEGACY_FA_REGEX.

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



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

#countInteger

Total number of candidate rows the SQL pre-filter selects.
Used by online_migrations for progress reporting.

Returns:

  • (Integer)

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



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).

Parameters:

  • articles (ActiveRecord::Relation<Article>)

    batch of
    articles yielded by #collection.

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



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