Sha256: bb6dcc76a4ed29f38f9da974ebeadb30d237c9a96d1ab100c0f2180293c256cc

Contents?: true

Size: 745 Bytes

Versions: 46

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

# Remove the class field from the block; ostruct 0.3 helpfully allows it to override
# this field and that confuses sir trevor..
class RemoveClassFromSirtrevorImageBlocks < ActiveRecord::Migration[5.2]
  def up
    Spotlight::Page.reset_column_information
    image = SirTrevorRails::Block.block_class('image')

    Spotlight::Page.find_each do |page|
      next unless page.content.any? { |block| block.is_a? image }
      page.content.select { |block| block.is_a?(image) && block.respond_to?(:class=) }.each do |block|
        block.delete_field(:class)
        block.attachment = Spotlight::Attachment.find(block.id).to_global_id rescue nil
      end

      page.update(content: page.content)
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.3.5 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.3.4 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.3.3 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.3.2 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.3.1 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.3.0 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.2.0 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.1.2 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.1.1 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.1.0 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.0.3 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.0.2 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.0.1 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-4.0.0 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-3.6.0.beta10 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-3.6.0.beta9 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-3.6.0.beta8 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-3.5.0.4 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb
blacklight-spotlight-3.6.0.beta7 db/migrate/20210305070001_remove_class_from_sirtrevor_image_blocks.rb