Sha256: d34375760796a9ef146f436b40e8af753cd1c14d9bf1645f612ea5e36c8f7e01

Contents?: true

Size: 1.22 KB

Versions: 45

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

# Migrate caption fields for the document title (pointing at the solr field name) to use the
# new `Spotlight::PageConfigurations::DOCUMENT_TITLE_KEY` for run-time lookups instead.
class MigrateCaptionValuesForTitleKey < ActiveRecord::Migration[5.2]
  def up
    Spotlight::Page.reset_column_information
    change_caption_field_of(Spotlight::Page, from: CatalogController.blacklight_config.index.title_field, to: Spotlight::PageConfigurations::DOCUMENT_TITLE_KEY)
  end

  def down
    Spotlight::Page.reset_column_information
    change_caption_field_of(Spotlight::Page, from: Spotlight::PageConfigurations::DOCUMENT_TITLE_KEY, to: CatalogController.blacklight_config.index.title_field)
  end

  def change_caption_field_of(scope, from:, to:)
    scope.find_each do |page|
      changed = false

      page.content.select { |block| block['primary-caption-field'] == from || block['secondary-caption-field'] == from }.each do |block|
        changed = true
        block['primary-caption-field'] = to if block['primary-caption-field'] == from
        block['secondary-caption-field'] = to if block['secondary-caption-field'] == from
      end

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

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
blacklight-spotlight-3.5.0.3 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.6.0.beta6 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.6.0.beta5 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.6.0.beta4 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.6.0.beta3 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.6.0.beta1 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.5.0.2 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.5.0.1 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.5.0 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.4.1 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.4 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.3 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.2.2 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.2.1 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.2 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.1 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.4.0 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.3.0 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.2.0 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb
blacklight-spotlight-3.1.0 db/migrate/20210308090000_migrate_caption_values_for_title_key.rb