escalation.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2024 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 escalation for ticket
  9. ticket = Ticket.find(123)
  10. result = ticket.escalation_calculation
  11. returns
  12. result = true # true = ticket has been updated | false = no changes on ticket
  13. =end
  14. def escalation_calculation(force = false)
  15. ::Escalation.new(self, force: force).calculate!
  16. end
  17. private
  18. def update_escalation_information
  19. # return if we run import mode
  20. return if Setting.get('import_mode')
  21. # return if ticket was destroyed in this transaction
  22. return if destroyed?
  23. return if callback_loop
  24. # needs to operate on a copy because otherwise caching breaks
  25. record_copy = Ticket.find_by(id: id)
  26. return if !record_copy
  27. record_copy.callback_loop = true
  28. # needs saving explicitly because this is after_commit!
  29. record_copy.escalation_calculation
  30. end
  31. end