trigger.rb 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Transaction::Trigger
  3. =begin
  4. {
  5. object: 'Ticket',
  6. type: 'update',
  7. object_id: 123,
  8. interface_handle: 'application_server', # application_server|websocket|scheduler
  9. changes: {
  10. 'attribute1' => [before, now],
  11. 'attribute2' => [before, now],
  12. },
  13. created_at: Time.zone.now,
  14. user_id: 123,
  15. },
  16. =end
  17. def initialize(item, params = {})
  18. @item = item
  19. @params = params
  20. end
  21. def perform
  22. # return if we run import mode
  23. return if Setting.get('import_mode')
  24. return if @item[:object] != 'Ticket'
  25. ticket = Ticket.find_by(id: @item[:object_id])
  26. return if !ticket
  27. if @item[:article_id]
  28. article = Ticket::Article.find_by(id: @item[:article_id])
  29. end
  30. original_user_id = UserInfo.current_user_id
  31. Ticket.perform_triggers(ticket, article, @item, @params)
  32. UserInfo.current_user_id = original_user_id
  33. end
  34. end