20170516000001_trigger_recipient_update.rb 902 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TriggerRecipientUpdate < ActiveRecord::Migration[4.2]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. ['auto reply (on new tickets)', 'auto reply (on follow-up of tickets)'].each do |name|
  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