escalation.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module Ticket::Escalation
  3. extend ActiveSupport::Concern
  4. included do
  5. after_commit :update_escalation_information
  6. end
  7. =begin
  8. rebuild escalations for all open tickets
  9. result = Ticket::Escalation.rebuild_all
  10. returns
  11. result = true
  12. =end
  13. def self.rebuild_all
  14. ActiveSupport::Deprecation.warn("Method 'rebuild_all' is deprecated. Run `TicketEscalationRebuildJob.perform_now` instead")
  15. TicketEscalationRebuildJob.perform_now
  16. end
  17. =begin
  18. rebuild escalation for ticket
  19. ticket = Ticket.find(123)
  20. result = ticket.escalation_calculation
  21. returns
  22. result = true # true = ticket has been updated | false = no changes on ticket
  23. =end
  24. def escalation_calculation(force = false)
  25. ::Escalation.new(self, force: force).calculate!
  26. end
  27. private
  28. def update_escalation_information
  29. # return if we run import mode
  30. return if Setting.get('import_mode')
  31. # return if ticket was destroyed in this transaction
  32. return if destroyed?
  33. return if callback_loop
  34. # needs to operate on a copy because otherwise caching breaks
  35. record_copy = Ticket.find_by(id: id)
  36. return if !record_copy
  37. record_copy.callback_loop = true
  38. # needs saving explicitly because this is after_commit!
  39. record_copy.escalation_calculation
  40. end
  41. end