Sha256: 8a13789726fd55d17c12ba0c5935651970dc993459b7436fff0c833f8d9b1a78

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Bulkrax
  class ImportCollectionJob < ApplicationJob
    queue_as :import

    # rubocop:disable Rails/SkipsModelValidations
    def perform(*args)
      entry = Entry.find(args[0])
      begin
        entry.build
        entry.save
        add_user_to_permission_template!(entry)
        ImporterRun.find(args[1]).increment!(:processed_records)
        ImporterRun.find(args[1]).increment!(:processed_collections)
        ImporterRun.find(args[1]).decrement!(:enqueued_records)
      rescue => e
        ImporterRun.find(args[1]).increment!(:failed_records)
        ImporterRun.find(args[1]).increment!(:failed_collections)
        ImporterRun.find(args[1]).decrement!(:enqueued_records)
        raise e
      end
    end
    # rubocop:enable Rails/SkipsModelValidations

    private

    def add_user_to_permission_template!(entry)
      user                = ::User.find(entry.importerexporter.user_id)
      collection          = entry.factory.find
      permission_template = Hyrax::PermissionTemplate.find_or_create_by!(source_id: collection.id)

      Hyrax::PermissionTemplateAccess.find_or_create_by!(
        permission_template_id: permission_template.id,
        agent_id: user.user_key,
        agent_type: 'user',
        access: 'manage'
      )

      collection.reset_access_controls!
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bulkrax-3.0.0.beta6 app/jobs/bulkrax/import_collection_job.rb
bulkrax-3.0.0.beta5 app/jobs/bulkrax/import_collection_job.rb
bulkrax-3.0.0.beta4 app/jobs/bulkrax/import_collection_job.rb
bulkrax-3.0.0.beta3 app/jobs/bulkrax/import_collection_job.rb
bulkrax-3.0.0.beta2 app/jobs/bulkrax/import_collection_job.rb
bulkrax-3.0.0.beta1 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.3.0 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.2.4 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.2.3 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.2.2 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.2.1 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.2.0 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.1.1 app/jobs/bulkrax/import_collection_job.rb
bulkrax-2.1.0 app/jobs/bulkrax/import_collection_job.rb