trigger.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2024 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, triggers_scope, @item, @params)
  32. UserInfo.current_user_id = original_user_id
  33. end
  34. private
  35. def triggers_scope
  36. ::Trigger
  37. .activated_by(trigger_activator)
  38. .reorder(reorder_clause)
  39. end
  40. def trigger_activator
  41. :action
  42. end
  43. def reorder_clause
  44. if Rails.configuration.db_case_sensitive
  45. return Arel.sql('LOWER(name)')
  46. end
  47. :name
  48. end
  49. end