20190408000001_issue_2541_fix_notification_email_without_body.rb 927 B

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