20220124101834_setting_updates2.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class SettingUpdates2 < ActiveRecord::Migration[6.0]
  3. def change # rubocop:disable Metrics/AbcSize
  4. return if !Setting.exists?(name: 'system_init_done')
  5. settings_update = [
  6. {
  7. title: 'Ticket Last Contact Behaviour',
  8. name: 'ticket_last_contact_behaviour',
  9. description: 'Defines how the last customer contact time of tickets should be calculated.',
  10. options: {
  11. form: [
  12. {
  13. display: '',
  14. null: true,
  15. name: 'ticket_last_contact_behaviour',
  16. tag: 'select',
  17. translate: true,
  18. options: {
  19. 'based_on_customer_reaction' => 'Use the time of the very last customer article.',
  20. 'check_if_agent_already_replied' => 'Use the start time of the last customer thread (which may consist of multiple articles).',
  21. },
  22. },
  23. ],
  24. },
  25. },
  26. {
  27. title: 'Sender based on Reply-To header',
  28. name: 'postmaster_sender_based_on_reply_to',
  29. description: 'Set/overwrite sender/from of email based on "Reply-To" header. Useful to set correct customer if email is received from a third-party system on behalf of a customer.',
  30. options: {
  31. form: [
  32. {
  33. display: '',
  34. null: true,
  35. name: 'postmaster_sender_based_on_reply_to',
  36. tag: 'select',
  37. options: {
  38. '' => '-',
  39. 'as_sender_of_email' => 'Take Reply-To header as sender/from of email.',
  40. 'as_sender_of_email_use_from_realname' => 'Take Reply-To header as sender/from of email and use the real name of origin from.',
  41. },
  42. },
  43. ],
  44. },
  45. },
  46. ]
  47. settings_update.each do |setting|
  48. fetched_setting = Setting.find_by(name: setting[:name])
  49. next if !fetched_setting
  50. if setting[:title]
  51. # "Updating title of #{setting[:name]} to #{setting[:title]}"
  52. fetched_setting.title = setting[:title]
  53. end
  54. if setting[:description]
  55. # "Updating description of #{setting[:name]} to #{setting[:description]}"
  56. fetched_setting.description = setting[:description]
  57. end
  58. if setting[:options]
  59. # "Updating description of #{setting[:name]} to #{setting[:description]}"
  60. fetched_setting.options = setting[:options]
  61. end
  62. fetched_setting.save!
  63. end
  64. end
  65. end