Class: AttachFilesToWorkJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/attach_files_to_work_job.rb

Overview

Converts UploadedFiles into FileSets and attaches them to works.

Instance Method Summary collapse

Instance Method Details

#perform(work, uploaded_files) ⇒ Object

Parameters:

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

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



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

def perform(work, uploaded_files)
  uploaded_files.each do |uploaded_file|
    file_set = FileSet.new
    user = User.find_by_user_key(work.depositor)
    actor = Hyrax::Actors::FileSetActor.new(file_set, user)
    actor.(visibility: work.visibility)
    attach_content(actor, uploaded_file.file)
    actor.attach_file_to_work(work)
    actor.file_set.permissions_attributes = work.permissions.map(&:to_hash)

    uploaded_file.update(file_set_uri: file_set.uri)
  end
end