# frozen_string_literal: true

module Hyrax
  module Listeners
    ##
    # Listens for object deleted events and cleans up associated members
    class TrophyCleanupListener
      def on_object_deleted(event)
        Trophy.where(work_id: event[: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
    end
  end
end
