2012-11-18 10:56:48 +00:00
|
|
|
class Observer::Ticket::CloseTime < ActiveRecord::Observer
|
|
|
|
observe 'ticket'
|
|
|
|
|
2012-12-30 11:48:53 +00:00
|
|
|
def after_create(record)
|
|
|
|
_check(record)
|
|
|
|
end
|
|
|
|
|
2012-11-18 10:56:48 +00:00
|
|
|
def after_update(record)
|
2012-12-30 11:48:53 +00:00
|
|
|
_check(record)
|
|
|
|
end
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2012-12-30 11:48:53 +00:00
|
|
|
private
|
|
|
|
def _check(record)
|
|
|
|
# puts 'check close time'
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2012-12-30 11:48:53 +00:00
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2012-12-30 11:48:53 +00:00
|
|
|
# check if close_time is already set
|
|
|
|
return true if record.close_time
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2012-12-30 11:48:53 +00:00
|
|
|
# check if ticket is closed now
|
2013-01-01 20:29:26 +00:00
|
|
|
ticket_state = Ticket::State.lookup( :id => record.ticket_state_id )
|
|
|
|
ticket_state_type = Ticket::StateType.lookup( :id => ticket_state.ticket_state_type_id )
|
2012-12-30 11:48:53 +00:00
|
|
|
return true if ticket_state_type.name != 'closed'
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2012-12-30 11:48:53 +00:00
|
|
|
# set close_time
|
|
|
|
record.close_time = Time.now
|
|
|
|
|
|
|
|
# save ticket
|
|
|
|
record.save
|
|
|
|
end
|
|
|
|
end
|