ticket_rebuild_escalation.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
  3. observe 'sla', 'calendar'
  4. def after_commit(record)
  5. _rebuild(record)
  6. end
  7. private
  8. def _rebuild(record)
  9. Cache.delete('SLA::List::Active')
  10. # send background job
  11. Delayed::Job.enqueue( Observer::Sla::TicketRebuildEscalation::BackgroundJob.new(record.id) )
  12. end
  13. def _check(record)
  14. # return if we run import mode
  15. return true if Setting.get('import_mode') && !Setting.get('import_ignore_sla')
  16. # check if condition has changed
  17. changed = false
  18. fields_to_check = nil
  19. fields_to_check = if record.class == Sla
  20. %w[condition calendar_id first_response_time update_time solution_time]
  21. else
  22. %w[timezone business_hours default ical_url public_holidays]
  23. end
  24. fields_to_check.each do |item|
  25. next if !record.saved_change_to_attribute(item)
  26. next if record.saved_change_to_attribute(item)[0] == record.saved_change_to_attribute(item)[1]
  27. changed = true
  28. end
  29. return true if !changed
  30. _rebuild(record)
  31. end
  32. end