Class: Oembed::LiquidTagMigrator
- Inherits:
-
Object
- Object
- Oembed::LiquidTagMigrator
- Defined in:
- app/services/oembed/liquid_tag_migrator.rb
Overview
Migrates legacy Liquid video tags in article content to oEmbed HTML.
Tags handled:
cloudflare_video 'slug' % → WyVideoProvider HTML5 player + EmbeddedVideoAsset
video_tag 'slug' % → WyVideoProvider HTML5 player + EmbeddedVideoAsset
The articles.solution column is the single source of truth — update_columns
is used to bypass callbacks (url sanitizer, revision hooks, embedding triggers)
that must not fire during a bulk data migration.
Scope: all Article subclasses (blog posts, FAQs, procedures, etc.) — not just Posts.
Usage:
Dry run — reports what would change without writing anything
result = Oembed::LiquidTagMigrator.new(dry_run: true).migrate_all
puts result.inspect
Live run
result = Oembed::LiquidTagMigrator.new.migrate_all
Constant Summary collapse
- CLOUDFLARE_VIDEO_REGEX =
cloudflare_video 'slug' % or cloudflare_video "slug" %
/\{%\s*cloudflare_video\s+['"]?([^'"}\s]+)['"]?\s*%\}/i- VIDEO_TAG_REGEX =
video_tag 'slug' % or video_tag "slug" %
/\{%\s*video_tag\s+['"]?([^'"}\s]+)['"]?\s*%\}/i- LEGACY_TAG_LIKE_CONDITIONS =
[ "solution LIKE '%{%% cloudflare_video%'", "solution LIKE '%{%% video_tag%'" ].freeze
Instance Method Summary collapse
-
#initialize(dry_run: false) ⇒ LiquidTagMigrator
constructor
A new instance of LiquidTagMigrator.
-
#migrate_all ⇒ Hash
Migrate all articles that still contain legacy Liquid video tags.
-
#migrate_article(article) ⇒ Boolean
(also: #migrate_post)
Migrate a single article.
Constructor Details
#initialize(dry_run: false) ⇒ LiquidTagMigrator
Returns a new instance of LiquidTagMigrator.
36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/oembed/liquid_tag_migrator.rb', line 36 def initialize(dry_run: false) @dry_run = dry_run @stats = { articles_scanned: 0, articles_updated: 0, videos_migrated: 0, errors: [], updated_articles: [] } end |
Instance Method Details
#migrate_all ⇒ Hash
Migrate all articles that still contain legacy Liquid video tags.
49 50 51 52 53 54 |
# File 'app/services/oembed/liquid_tag_migrator.rb', line 49 def migrate_all .find_each do |article| migrate_article(article) end @stats end |
#migrate_article(article) ⇒ Boolean Also known as: migrate_post
Migrate a single article.
Updates both articles.solution and the active revision's solution.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/services/oembed/liquid_tag_migrator.rb', line 60 def migrate_article(article) @stats[:articles_scanned] += 1 content = article.solution return false if content.blank? return false unless (content) updated_content = (article, content) return false if updated_content == content @stats[:articles_updated] += 1 @stats[:updated_articles] << { id: article.id, subject: article.subject, type: article.type } unless @dry_run now = Time.current article.update_columns(solution: updated_content, updated_at: now) Rails.logger.info "[LiquidTagMigrator] Migrated article ##{article.id}: #{article.subject}" end true rescue StandardError => e @stats[:errors] << "Article ##{article.id}: #{e.}" Rails.logger.error "[LiquidTagMigrator] Error on article ##{article.id}: #{e.}\n#{e.backtrace.first(5).join("\n")}" false end |