triggers_subscriptions.rb 868 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Checklist::Item::TriggersSubscriptions
  3. extend ActiveSupport::Concern
  4. included do
  5. after_save_commit :trigger_item_reference_change_subscription
  6. after_destroy_commit :trigger_item_reference_destroy_subscription
  7. end
  8. private
  9. def trigger_item_reference_change_subscription
  10. return if !saved_change_to_ticket_id?
  11. if (old_ticket = Ticket.find_by(id: ticket_id_previously_was))
  12. trigger_subscription(old_ticket)
  13. end
  14. trigger_subscription(ticket) if ticket
  15. end
  16. def trigger_item_reference_destroy_subscription
  17. return if !ticket
  18. trigger_subscription(ticket)
  19. end
  20. def trigger_subscription(ticket)
  21. Gql::Subscriptions::TicketUpdates
  22. .trigger(ticket, arguments: { ticket_id: Gql::ZammadSchema.id_from_object(ticket) })
  23. end
  24. end