20190408000001_issue_2541_fix_notification_email_without_body.rb 949 B

12345678910111213141516171819202122232425262728293031323334
  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. actions = %w[notification.email notification.sms]
  10. [::Job, ::Trigger].each do |model|
  11. model.all.each do |record|
  12. next if record.perform.blank?
  13. actions.each do |action|
  14. next if record.perform[action].blank?
  15. next if record.perform[action]['body'].present?
  16. record.perform[action]['body'] = '-'
  17. record.save!
  18. end
  19. end
  20. end
  21. # re-enable jobs again
  22. scheduler = Scheduler.find_by(method: 'Job.run')
  23. return if !scheduler
  24. return if scheduler.active?
  25. scheduler.update!(active: true)
  26. end
  27. end