Sha256: 1f243037d78506e7d57b44881431f6105530ec543e60625f200afa60cf196b2c

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

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

    PaperTrail.request(enabled: false) do
      Decidim::Attachment.find_each do |attachment|
        next if attachment.title.is_a?(Hash) && attachment.description.is_a?(Hash)

        attached_to = attachment.attached_to
        locale = attached_to.try(:locale).presence ||
                 attached_to.try(:default_locale).presence ||
                 attached_to.try(:organization).try(:default_locale).presence ||
                 Decidim.default_locale

        # rubocop:disable Rails/SkipsModelValidations
        attachment.update_columns(
          title: {
            locale => attachment.title
          },
          description: {
            locale => attachment.description
          }
        )
        # rubocop:enable Rails/SkipsModelValidations
      end
    end

    reset_column_information
  end

  def down; end

  def reset_column_information
    Decidim::Attachment.reset_column_information
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.23.6 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.24.2 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.23.5 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.24.1 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.24.0 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.24.0.rc2 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.23.4 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.24.0.rc1 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.23.3 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.23.2 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.23.1 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.23.1.rc1 db/migrate/20201006072346_fix_attachments_titles.rb
decidim-participatory_processes-0.23.0 db/migrate/20201006072346_fix_attachments_titles.rb