trabajo-afectivo/db/migrate/20190408000001_issue_2541_fix_notification_email_without_body.rb

34 lines
927 B
Ruby
Raw Normal View History

class Issue2541FixNotificationEmailWithoutBody < ActiveRecord::Migration[5.1]
def up
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')
# there might be Job/Trigger selectors referencing the current user
# that get e.g. validated in callbacks
UserInfo.current_user_id = 1
# update jobs and triggers
[::Job, ::Trigger].each do |model|
model.all.each do |record|
next if record.perform.blank?
%w[notification.email notification.sms].each do |action|
next if record.perform[action].blank?
next if record.perform[action]['body'].present?
record.perform[action]['body'] = '-'
record.save!
end
end
end
# re-enable jobs again
scheduler = Scheduler.find_by(method: 'Job.run')
return if !scheduler
return if scheduler.active?
scheduler.update!(active: true)
end
end