trigger.rb 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://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