Class: Hyrax::Listeners::TrophyCleanupListener

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/listeners/trophy_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) ⇒ void

This method returns an undefined value.

Called when ‘object.deleted’ event is published

Parameters:

  • event (Dry::Events::Event)


11
12
13
14
15
16
17
18
# File 'app/services/hyrax/listeners/trophy_cleanup_listener.rb', line 11

def on_object_deleted(event)
  object_id = event[:object]&.id || event[:id]
  Trophy.where(work_id: object_id).destroy_all
rescue StandardError => err
  Hyrax.logger.warn "Failed to delete trophies for #{event[:id]}. " \
                    'These trophies might be orphaned.' \
                    "\n\t#{err.message}"
end