20190408000001_issue_2541_fix_notification_email_without_body.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue2541FixNotificationEmailWithoutBody < ActiveRecord::Migration[5.1]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. # there might be Job/Trigger selectors referencing the current user
  7. # that get e.g. validated in callbacks
  8. UserInfo.current_user_id = 1
  9. # update jobs and triggers
  10. actions = %w[notification.email notification.sms]
  11. [::Job, ::Trigger].each do |model|
  12. model.all.each do |record|
  13. next if record.perform.blank?
  14. actions.each do |action|
  15. next if record.perform[action].blank?
  16. next if record.perform[action]['body'].present?
  17. record.perform[action]['body'] = '-'
  18. record.save!
  19. end
  20. end
  21. end
  22. # re-enable jobs again
  23. scheduler = Scheduler.find_by(method: 'Job.run')
  24. return if !scheduler
  25. return if scheduler.active?
  26. scheduler.update!(active: true)
  27. end
  28. end