close_time.rb 798 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::CloseTime < ActiveRecord::Observer
  3. observe 'ticket'
  4. def after_create(record)
  5. _check(record)
  6. end
  7. def after_update(record)
  8. _check(record)
  9. end
  10. private
  11. def _check(record)
  12. # puts 'check close time'
  13. # return if we run import mode
  14. return if Setting.get('import_mode')
  15. # check if close_time is already set
  16. return true if record.close_time
  17. # check if ticket is closed now
  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_time
  22. record.close_time = Time.now
  23. # save ticket
  24. record.save
  25. end
  26. end