Class: Hyrax::Listeners::MemberCleanupListener

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/listeners/member_cleanup_listener.rb

Overview

Listens for object deleted events and cleans up associated members

Instance Method Summary collapse

Instance Method Details

#on_object_deleted(event) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/hyrax/listeners/member_cleanup_listener.rb', line 8

def on_object_deleted(event)
  return unless event.payload.key?(:object) # legacy callback
  return if event[:object].is_a?(ActiveFedora::Base) # handled by legacy code

  Hyrax.custom_queries.find_child_filesets(resource: event[:object]).each do |file_set|
    begin
      Hyrax.persister.delete(resource: file_set)
      Hyrax.publisher
           .publish('object.deleted', object: file_set, id: file_set.id, user: user)
    rescue StandardError # we don't uncaught errors looping filesets
      Hyrax.logger.warn "Failed to delete #{file_set.class}:#{file_set.id} " \
                        "during cleanup for resource: #{event[:object]}. " \
                        'This member may now be orphaned.'
    end
  end
end