Sha256: db69826a678429d460fea12e1fcb408ceff7da4c524d0abd2166bd7d473c64ed

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # After renaming an exhibit-specific field, we also
  # need to update the sidecars that may contain that field
  class RenameSidecarFieldJob < ActiveJob::Base
    queue_as :default

    def perform(exhibit, old_field, new_field, old_slug = nil, new_slug = nil)
      exhibit.solr_document_sidecars.find_each do |s|
        # this data migration should be relatively rare
        migrate_data!(s, old_slug, new_slug)
        migrate_data!(s, old_field, new_slug || new_field) # for backwards compatibility

        # more likely, the indexing rules changed and we have to reindex
        reindex_document!(s) if old_field != new_field && s.data[new_slug || new_field]
      end
    end

    private

    def migrate_data!(sidecar, old_field, new_field)
      return if old_field == new_field || !sidecar.data.key?(old_field)

      sidecar.data_will_change!
      sidecar.data[new_field] = sidecar.data.delete(old_field)
      sidecar.save
    end

    def reindex_document!(sidecar)
      sidecar.document.reindex
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc3 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.rc2 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.rc1 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.10 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.9 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.8 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.7 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.6 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.5 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.4 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.3 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.2 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-3.0.0.alpha.1 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-2.13.0 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-2.12.1 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-2.12.0 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-2.11.0 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-2.10.0 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-2.9.0 app/jobs/spotlight/rename_sidecar_field_job.rb
blacklight-spotlight-2.8.0 app/jobs/spotlight/rename_sidecar_field_job.rb