123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- class Transaction::Trigger
- =begin
- {
- object: 'Ticket',
- type: 'update',
- object_id: 123,
- interface_handle: 'application_server', # application_server|websocket|scheduler
- changes: {
- 'attribute1' => [before, now],
- 'attribute2' => [before, now],
- },
- created_at: Time.zone.now,
- 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'
- ticket = Ticket.find_by(id: @item[:object_id])
- return if !ticket
- if @item[:article_id]
- article = Ticket::Article.find_by(id: @item[:article_id])
- end
- original_user_id = UserInfo.current_user_id
- Ticket.perform_triggers(ticket, article, triggers_scope, @item, @params)
- UserInfo.current_user_id = original_user_id
- end
- private
- def triggers_scope
- ::Trigger
- .activated_by(trigger_activator)
- .reorder(reorder_clause)
- end
- def trigger_activator
- :action
- end
- def reorder_clause
- if Rails.configuration.db_case_sensitive
- return Arel.sql('LOWER(name)')
- end
- :name
- end
- end
|