Skip to content

Commit

Permalink
do not mutate file_set instance variable
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle authored and tamsin johnson committed Mar 16, 2021
1 parent 10f92a2 commit 3c89fd5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/actors/hyrax/actors/create_with_remote_files_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def attach_files(env, remote_files)
end

def create_file_from_url(env, uri, file_name, auth_header)
if env.curation_concern.is_a? Valkyrie::Resource
case env.curation_concern
when Valkyrie::Resource
create_file_from_url_through_valkyrie(env, uri, file_name, auth_header)
else
create_file_from_url_through_active_fedora(env, uri, file_name, auth_header)
Expand Down
12 changes: 7 additions & 5 deletions app/actors/hyrax/actors/file_set_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def create_metadata(file_set_params = {})
yield(file_set) if block_given?
end

# Adds a FileSet to the work using ore:Aggregations.
# Locks to ensure that only one process is operating on the list at a time.
def attach_to_work(work, file_set_params = {})
acquire_lock_for(work.id) do
Expand All @@ -87,15 +86,18 @@ def attach_to_work(work, file_set_params = {})
def attach_to_valkyrie_work(work, file_set_params)
work = Hyrax.query_service.find_by(id: work.id) unless work.new_record
file_set.visibility = work.visibility unless assign_visibility?(file_set_params)
@file_set = Hyrax.persister.save(resource: file_set)
work.member_ids << file_set.id
work.representative_id = file_set.id if work.representative_id.blank?
work.thumbnail_id = file_set.id if work.thumbnail_id.blank?
fs = Hyrax.persister.save(resource: file_set)
Hyrax.publisher.publish('object.metadata.updated', object: fs, user: user)
work.member_ids << fs.id
work.representative_id = fs.id if work.representative_id.blank?
work.thumbnail_id = fs.id if work.thumbnail_id.blank?
# Save the work so the association between the work and the file_set is persisted (head_id)
# NOTE: the work may not be valid, in which case this save doesn't do anything.
Hyrax.persister.save(resource: work)
Hyrax.publisher.publish('object.metadata.updated', object: work, user: user)
end

# Adds a FileSet to the work using ore:Aggregations.
def attach_to_af_work(work, file_set_params)
work.reload unless work.new_record?
file_set.visibility = work.visibility unless assign_visibility?(file_set_params)
Expand Down

0 comments on commit 3c89fd5

Please sign in to comment.