20221031105713_issue_4316_template_options_migration.rb 834 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue4316TemplateOptionsMigration < ActiveRecord::Migration[6.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. Template.all.each do |template|
  7. template.options = migrate_template_options(template.options)
  8. template.save!
  9. end
  10. end
  11. private
  12. def migrate_template_options(options)
  13. new_options = {}
  14. options.each do |key, value|
  15. next if key.ends_with?('_completion')
  16. if value.is_a?(Hash)
  17. new_options[key] = value
  18. next
  19. end
  20. new_options[key] = { value: value }
  21. if options.key?("#{key}_completion")
  22. new_options[key]['value_completion'] = options["#{key}_completion"]
  23. end
  24. end
  25. new_options
  26. end
  27. end