Skip to content

Commit

Permalink
use transaction to thoroughly delete members
Browse files Browse the repository at this point in the history
The Transaction ensures the members will be deleted thoroughly. For
example, using the transaction means all the related Sipity records will
be destroyed, which is what we want
  • Loading branch information
bkiahstroud committed Apr 12, 2024
1 parent ae13cd1 commit 1a0a4a6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/services/listeners/cascade_delete_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ def on_object_deleted(event)
resource = event.to_h.fetch(:object) { Hyrax.query_service.find_by(id: event[:object_id]) }
return unless resource.is_a?(AssetResource) || resource.is_a?(PhysicalInstantiationResource) || resource.is_a?(DigitalInstantiationResource)
resource.members.each do |member|
Hyrax.index_adapter.delete(resource: member)
Hyrax.persister.delete(resource: member)
Hyrax::Transactions::Container['work_resource.destroy']
.with_step_args('work_resource.delete' => { user: event[:user] },
'work_resource.delete_all_file_sets' => { user: event[:user] })
.call(member).value!
end
end
end
Expand Down

0 comments on commit 1a0a4a6

Please sign in to comment.