20170516000001_trigger_recipient_update.rb 864 B

1234567891011121314151617181920212223
  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. begin
  7. trigger = Trigger.find_by(name: name)
  8. next if trigger.blank?
  9. next if trigger.perform.blank?
  10. next if trigger.perform['notification.email'].blank?
  11. next if trigger.perform['notification.email']['recipient'].blank?
  12. next if trigger.perform['notification.email']['recipient'] != 'ticket_customer'
  13. trigger.perform['notification.email']['recipient'] = 'article_last_sender'
  14. trigger.save!
  15. rescue => e
  16. Rails.logger.error "Unable to update Trigger.find(#{trigger.id}) '#{trigger.inspect}': #{e.message}"
  17. end
  18. end
  19. end
  20. end