Class: AttachFilesToWorkJob

Inherits:
Hyrax::ApplicationJob show all
Defined in:
app/jobs/attach_files_to_work_job.rb

Overview

Converts UploadedFiles into FileSets and attaches them to works.

Direct Known Subclasses

AttachFilesToWorkWithOrderedMembersJob

Instance Method Summary collapse

Instance Method Details

#perform(work, uploaded_files, **work_attributes) ⇒ Object

Parameters:

  • work (ActiveFedora::Base)
    • the work object

  • uploaded_files (Array<Hyrax::UploadedFile>)
    • an array of files to attach



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/jobs/attach_files_to_work_job.rb', line 7

def perform(work, uploaded_files, **work_attributes)
  validate_files!(uploaded_files)
  depositor = proxy_or_depositor(work)
  user = User.find_by_user_key(depositor)
  work_permissions = work.permissions.map(&:to_hash)
   = visibility_attributes(work_attributes)
  uploaded_files.each do |uploaded_file|
    next if uploaded_file.file_set_uri.present?

    actor = Hyrax::Actors::FileSetActor.new(FileSet.create, user)
    uploaded_file.update(file_set_uri: actor.file_set.uri)
    actor.file_set.permissions_attributes = work_permissions
    actor.()
    actor.create_content(uploaded_file)
    actor.attach_to_work(work)
  end
end