article_note.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Ticket::PerformChanges::Action::ArticleNote < Ticket::PerformChanges::Action
  3. def self.phase
  4. :after_save
  5. end
  6. def execute(...)
  7. add_note(execution_data)
  8. end
  9. private
  10. def add_note(note)
  11. rendered_subject = NotificationFactory::Mailer.template(
  12. templateInline: note[:subject],
  13. objects: notification_factory_template_objects,
  14. quote: true,
  15. locale: locale,
  16. timezone: timezone,
  17. )
  18. rendered_body = NotificationFactory::Mailer.template(
  19. templateInline: note[:body],
  20. objects: notification_factory_template_objects,
  21. quote: true,
  22. locale: locale,
  23. timezone: timezone,
  24. )
  25. article = Ticket::Article.new(
  26. ticket_id: id,
  27. subject: rendered_subject,
  28. content_type: 'text/html',
  29. body: rendered_body,
  30. internal: note[:internal],
  31. sender: Ticket::Article::Sender.find_by(name: 'System'),
  32. type: Ticket::Article::Type.find_by(name: 'note'),
  33. preferences: {
  34. perform_origin: origin,
  35. notification: true,
  36. },
  37. updated_by_id: 1,
  38. created_by_id: 1,
  39. )
  40. article.history_change_source_attribute(performable, 'created')
  41. article.save!
  42. end
  43. end