Sha256: f866314020277e063ad8f2bc060a31b485a9ebab7618973bbb8a3a6d82a1e2e2

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

class FixParagraphsData < ActiveRecord::Migration[5.2]
  def up
    reset_column_information

    PaperTrail.request(enabled: false) do
      Decidim::EnhancedTextwork::Paragraph.find_each do |paragraph|
        next if paragraph.title.is_a?(Hash) && paragraph.body.is_a?(Hash)

        author = paragraph.coauthorships.first.author

        locale = author.try(:locale).presence || author.try(:default_locale).presence || author.try(:organization).try(:default_locale).presence

        # rubocop:disable Rails/SkipsModelValidations
        values = {}
        values[:title] = { locale => paragraph.title } unless paragraph.title.is_a?(Hash)
        values[:body] = { locale => paragraph.body } unless paragraph.body.is_a?(Hash)

        paragraph.update_columns(values)
        # rubocop:enable Rails/SkipsModelValidations
      end
    end

    reset_column_information
  end

  def down; end

  def reset_column_information
    Decidim::User.reset_column_information
    Decidim::Coauthorship.reset_column_information
    Decidim::EnhancedTextwork::Paragraph.reset_column_information
    Decidim::Organization.reset_column_information
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-enhanced_textwork-1.0.5 db/migrate/20201002085508_fix_paragraphs_data.rb
decidim-enhanced_textwork-1.0.4 db/migrate/20201002085508_fix_paragraphs_data.rb
decidim-enhanced_textwork-1.0.3 db/migrate/20201002085508_fix_paragraphs_data.rb
decidim-enhanced_textwork-1.0.2 db/migrate/20201002085508_fix_paragraphs_data.rb
decidim-enhanced_textwork-1.0.1 db/migrate/20201002085508_fix_paragraphs_data.rb
decidim-enhanced_textwork-1.0.0 db/migrate/20201002085508_fix_paragraphs_data.rb