2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
module Ticket::Escalation
|
2021-02-15 13:55:00 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
after_commit :update_escalation_information
|
|
|
|
end
|
2013-08-16 14:30:51 +00:00
|
|
|
|
2013-08-17 16:09:19 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
rebuild escalations for all open tickets
|
|
|
|
|
|
|
|
result = Ticket::Escalation.rebuild_all
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
def self.rebuild_all
|
2021-02-15 13:55:00 +00:00
|
|
|
ActiveSupport::Deprecation.warn("Method 'rebuild_all' is deprecated. Run `TicketEscalationRebuildJob.perform_now` instead")
|
2013-08-16 14:30:51 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
TicketEscalationRebuildJob.perform_now
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
2013-08-16 14:30:51 +00:00
|
|
|
|
2013-08-17 16:09:19 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
rebuild escalation for ticket
|
|
|
|
|
|
|
|
ticket = Ticket.find(123)
|
|
|
|
result = ticket.escalation_calculation
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
2016-09-02 10:54:13 +00:00
|
|
|
result = true # true = ticket has been updated | false = no changes on ticket
|
2013-08-17 16:09:19 +00:00
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-09-02 10:54:13 +00:00
|
|
|
def escalation_calculation(force = false)
|
2021-02-15 13:55:00 +00:00
|
|
|
::Escalation.new(self, force: force).calculate!
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
2015-04-27 21:27:51 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
private
|
2013-08-16 14:30:51 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
def update_escalation_information
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
2015-04-27 23:19:26 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
# return if ticket was destroyed in this transaction
|
|
|
|
return if destroyed?
|
2013-08-16 14:30:51 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
return if callback_loop
|
2015-04-27 23:19:26 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
# needs to operate on a copy because otherwise caching breaks
|
2021-06-02 14:45:37 +00:00
|
|
|
record_copy = Ticket.find_by(id: id)
|
|
|
|
return if !record_copy
|
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
record_copy.callback_loop = true
|
2021-06-02 14:45:37 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
# needs saving explicitly because this is after_commit!
|
|
|
|
record_copy.escalation_calculation
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
2014-02-03 19:23:00 +00:00
|
|
|
end
|