2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2013-01-04 08:10:36 +00:00
|
|
|
class Observer::Ticket::ResetNewState < ActiveRecord::Observer
|
|
|
|
observe 'ticket::_article'
|
|
|
|
|
|
|
|
def after_create(record)
|
|
|
|
|
|
|
|
# return if we run import mode
|
2018-06-12 11:59:18 +00:00
|
|
|
return true if Setting.get('import_mode')
|
2013-01-04 08:10:36 +00:00
|
|
|
|
2017-09-27 18:12:21 +00:00
|
|
|
# only change state if not processed via postmaster
|
2018-06-12 11:59:18 +00:00
|
|
|
return true if ApplicationHandleInfo.postmaster?
|
2017-09-27 18:12:21 +00:00
|
|
|
|
2013-01-04 08:10:36 +00:00
|
|
|
# if article in internal
|
|
|
|
return true if record.internal
|
|
|
|
|
|
|
|
# if sender is agent
|
2016-03-08 06:32:58 +00:00
|
|
|
return true if Ticket::Article::Sender.lookup(id: record.sender_id).name != 'Agent'
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# if article is a message to customer
|
2016-03-08 06:32:58 +00:00
|
|
|
return true if !Ticket::Article::Type.lookup(id: record.type_id).communication
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# if current ticket state is still new
|
2018-06-12 11:59:18 +00:00
|
|
|
ticket = Ticket.find_by(id: record.ticket_id)
|
|
|
|
return true if !ticket
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-02-12 17:21:03 +00:00
|
|
|
new_state = Ticket::State.find_by(default_create: true)
|
|
|
|
return true if ticket.state_id != new_state.id
|
2013-01-04 08:10:36 +00:00
|
|
|
|
2017-02-12 17:21:03 +00:00
|
|
|
state = Ticket::State.find_by(default_follow_up: true)
|
2018-06-12 11:59:18 +00:00
|
|
|
return true if !state
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# set ticket to open
|
2014-06-08 22:01:20 +00:00
|
|
|
ticket.state_id = state.id
|
2013-01-04 08:10:36 +00:00
|
|
|
|
|
|
|
# save ticket
|
|
|
|
ticket.save
|
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|