2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2016-05-03 00:36:44 +00:00
|
|
|
|
|
|
|
class Transaction::Trigger
|
|
|
|
|
|
|
|
=begin
|
|
|
|
{
|
|
|
|
object: 'Ticket',
|
|
|
|
type: 'update',
|
|
|
|
object_id: 123,
|
2016-08-20 19:29:22 +00:00
|
|
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
2016-05-03 00:36:44 +00:00
|
|
|
changes: {
|
|
|
|
'attribute1' => [before, now],
|
|
|
|
'attribute2' => [before, now],
|
2016-07-16 21:43:08 +00:00
|
|
|
},
|
|
|
|
created_at: Time.zone.now,
|
2016-05-03 00:36:44 +00:00
|
|
|
user_id: 123,
|
|
|
|
},
|
|
|
|
=end
|
|
|
|
|
|
|
|
def initialize(item, params = {})
|
|
|
|
@item = item
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
|
|
|
return if @item[:object] != 'Ticket'
|
|
|
|
|
2018-06-05 10:37:52 +00:00
|
|
|
ticket = Ticket.find_by(id: @item[:object_id])
|
2016-05-03 00:36:44 +00:00
|
|
|
return if !ticket
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-05-03 00:36:44 +00:00
|
|
|
if @item[:article_id]
|
2018-06-05 10:37:52 +00:00
|
|
|
article = Ticket::Article.find_by(id: @item[:article_id])
|
2016-05-03 00:36:44 +00:00
|
|
|
end
|
|
|
|
|
2016-05-04 09:45:05 +00:00
|
|
|
original_user_id = UserInfo.current_user_id
|
2016-11-18 07:25:07 +00:00
|
|
|
|
2018-05-29 15:42:14 +00:00
|
|
|
Ticket.perform_triggers(ticket, article, @item, @params)
|
2016-05-04 09:45:05 +00:00
|
|
|
UserInfo.current_user_id = original_user_id
|
2016-05-03 00:36:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|