Sha256: 4c2bf79aa1ce2faabd19713e7ab6d673751e29623bc92a74425971770acba0df

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Spotlight
  ###
  class RenameTagsJob < Spotlight::ApplicationJob
    include Spotlight::JobTracking

    with_job_tracking(resource: ->(job) { job.arguments.first })

    # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
    def perform(exhibit, tag, to: nil, **)
      @errors = 0

      tag.taggings.owned_by(exhibit).find_each do |tagging|
        sidecar = tagging.taggable
        all_tags = sidecar.all_tags_list
        all_tags -= [tag.name]
        all_tags += [to] unless to.nil?

        exhibit.tag(sidecar, with: all_tags, on: :tags)
        sidecar.document.reindex(update_params: {})
      rescue StandardError => e
        job_tracker.append_log_entry(type: :error, exhibit:, message: e.to_s)
        @errors += 1
        mark_job_as_failed!
      end

      exhibit.blacklight_config.repository.connection.commit
      job_tracker.append_log_entry(type: :info, exhibit:, message: "#{progress.progress} of #{progress.total} (#{@errors} errors)")
    end
    # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-spotlight-4.7.0 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.6.1 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.6.0 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.5.0 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.4.0 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.3.6 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.3.5 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.3.4 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.3.3 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.3.2 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.3.1 app/jobs/spotlight/rename_tags_job.rb
blacklight-spotlight-4.3.0 app/jobs/spotlight/rename_tags_job.rb