20170516000001_trigger_recipient_update.rb 825 B

123456789101112131415161718192021222324
  1. class TriggerRecipientUpdate < ActiveRecord::Migration[4.2]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.find_by(name: 'system_init_done')
  5. ['auto reply (on new tickets)', 'auto reply (on follow-up of tickets)'].each do |name|
  6. trigger = Trigger.find_by(name: name)
  7. next if trigger.blank?
  8. next if trigger.perform.blank?
  9. next if trigger.perform['notification.email'].blank?
  10. next if trigger.perform['notification.email']['recipient'].blank?
  11. next if trigger.perform['notification.email']['recipient'] != 'ticket_customer'
  12. trigger.perform['notification.email']['recipient'] = 'article_last_sender'
  13. trigger.save!
  14. rescue => e
  15. Rails.logger.error "Unable to update Trigger.find(#{trigger.id}) '#{trigger.inspect}': #{e.message}"
  16. end
  17. end
  18. end