2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-11-18 10:56:48 +00:00
|
|
|
class Observer::Ticket::CloseTime < ActiveRecord::Observer
|
|
|
|
observe 'ticket'
|
|
|
|
|
2015-05-01 14:26:28 +00:00
|
|
|
def before_create(record)
|
2012-12-30 11:48:53 +00:00
|
|
|
_check(record)
|
|
|
|
end
|
|
|
|
|
2015-05-01 14:26:28 +00:00
|
|
|
def before_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
|
2015-05-01 12:31:46 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
def _check(record)
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
# check if close_time is already set
|
|
|
|
return true if record.close_time
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
# check if ticket is closed now
|
2016-08-23 18:46:04 +00:00
|
|
|
return if !record.state_id
|
2016-03-08 06:32:58 +00:00
|
|
|
state = Ticket::State.lookup(id: record.state_id)
|
|
|
|
state_type = Ticket::StateType.lookup(id: state.state_type_id)
|
2014-06-08 22:01:20 +00:00
|
|
|
return true if state_type.name != 'closed'
|
2012-11-18 10:56:48 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
# set close_time
|
2015-05-08 10:20:33 +00:00
|
|
|
record.close_time = Time.zone.now
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|
|
|
|
end
|