close_time.rb 833 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2013 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. ticket_state = Ticket::State.lookup( :id => record.ticket_state_id )
  19. ticket_state_type = Ticket::StateType.lookup( :id => ticket_state.state_type_id )
  20. return true if ticket_state_type.name != 'closed'
  21. # set close_time
  22. record.close_time = Time.now
  23. # save ticket
  24. record.save
  25. end
  26. end