close_time.rb 759 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::CloseTime < ActiveRecord::Observer
  3. observe 'ticket'
  4. def before_create(record)
  5. _check(record)
  6. end
  7. def before_update(record)
  8. _check(record)
  9. end
  10. private
  11. def _check(record)
  12. # return if we run import mode
  13. return true if Setting.get('import_mode')
  14. # check if close_at is already set
  15. return true if record.close_at
  16. # check if ticket is closed now
  17. return true if !record.state_id
  18. state = Ticket::State.lookup(id: record.state_id)
  19. state_type = Ticket::StateType.lookup(id: state.state_type_id)
  20. return true if state_type.name != 'closed'
  21. # set close_at
  22. record.close_at = Time.zone.now
  23. end
  24. end