20150828000001_add_setting_online_service2.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class AddSettingOnlineService2 < ActiveRecord::Migration
  2. def up
  3. # add preferences
  4. add_column :channels, :preferences, :string, limit: 2000, null: true
  5. Channel.reset_column_information
  6. Channel.where(area: 'Email::Notification').each {|channel|
  7. channel.preferences = {}
  8. channel.preferences[:online_service_disable] = true
  9. channel.save
  10. }
  11. Channel.where(area: 'Email::Account').each {|channel|
  12. next if !channel.options
  13. next if !channel.options[:inbound][:options]
  14. next if !channel.options[:inbound][:options][:host]
  15. next if channel.options[:inbound][:options][:host] !~ /zammad/i
  16. channel.preferences = {}
  17. channel.preferences[:online_service_disable] = true
  18. channel.save
  19. }
  20. add_column :email_addresses, :preferences, :string, limit: 2000, null: true
  21. EmailAddress.reset_column_information
  22. EmailAddress.all.each {|email_address|
  23. next if email_address.email !~ /zammad/i
  24. email_address.preferences = {}
  25. email_address.preferences[:online_service_disable] = true
  26. email_address.save
  27. }
  28. # return if it's a new setup
  29. return if !Setting.find_by(name: 'system_init_done')
  30. Setting.create_or_update(
  31. title: 'Block Notifications',
  32. name: 'send_no_auto_response_reg_exp',
  33. area: 'Email::Base',
  34. description: 'If this regex matches, no notification will be send by the sender.',
  35. options: {
  36. form: [
  37. {
  38. display: '',
  39. null: false,
  40. name: 'send_no_auto_response_reg_exp',
  41. tag: 'input',
  42. },
  43. ],
  44. },
  45. state: '(MAILER-DAEMON|postmaster|abuse)@.+?\..+?',
  46. preferences: { online_service_disable: true },
  47. frontend: false
  48. )
  49. end
  50. end