Class: OnlineMigrations::DataMigrations::RewriteLegacyFaClassesInArticleRevisions

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

Overview

Note:

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

Rewrites legacy Font Awesome <i> class strings in stored
article_revisions.solution and article_revisions.description HTML
to the project's Sharp family (fa-sharp fa-solid / fa-sharp fa-regular).

Sibling of RewriteLegacyFaClassesInArticles. Reverting an article to
an old revision restores those columns verbatim, so revisions need the
same rewrite — otherwise reverts re-introduce legacy classes that the
bundled SCSS no longer ships.

Constant Summary collapse

BATCH_SIZE =

Batch size — solution bodies are large, so keep batches small.

100
LEGACY_FA_REGEX =

See RewriteLegacyFaClassesInArticles::LEGACY_FA_REGEX for the
rationale. Same pattern, applied to article_revisions.

%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 ArticleRevision rows.

Returns:

  • (ActiveRecord::Batches::BatchEnumerator)

    over rows whose
    solution or description matches LEGACY_FA_REGEX.

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



34
35
36
# File 'lib/online_migrations/data_migrations/rewrite_legacy_fa_classes_in_article_revisions.rb', line 34

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.



55
# File 'lib/online_migrations/data_migrations/rewrite_legacy_fa_classes_in_article_revisions.rb', line 55

delegate :count, to: :candidate_relation

#process(revisions) ⇒ void

This method returns an undefined value.

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

Parameters:

  • revisions (ActiveRecord::Relation<ArticleRevision>)

    batch
    of revisions yielded by #collection.

Raises:

  • (ActiveRecord::ActiveRecordError)

    on database error.



45
46
47
# File 'lib/online_migrations/data_migrations/rewrite_legacy_fa_classes_in_article_revisions.rb', line 45

def process(revisions)
  revisions.each { |revision| rewrite_revision(revision) }
end