2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-03-29 11:58:39 +00:00
|
|
|
class Issue1660FixTreeSelectConfigurations < ActiveRecord::Migration[5.1]
|
|
|
|
def change
|
|
|
|
|
|
|
|
# return if it's a new setup
|
2020-08-03 08:35:43 +00:00
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
2018-03-29 11:58:39 +00:00
|
|
|
|
|
|
|
return if attributes.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-03-29 11:58:39 +00:00
|
|
|
attributes.each do |attribute|
|
|
|
|
|
|
|
|
next if attribute.data_option.blank?
|
|
|
|
next if attribute.data_option[:options].blank?
|
|
|
|
|
|
|
|
fixed_options = fix(attribute.data_option[:options])
|
|
|
|
|
|
|
|
attribute.data_option[:options] = fixed_options
|
|
|
|
|
|
|
|
attribute.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def attributes
|
|
|
|
@attributes ||= ObjectManager::Attribute.where(data_type: 'tree_select')
|
|
|
|
end
|
|
|
|
|
|
|
|
def fix(options, namespace = nil)
|
|
|
|
|
|
|
|
options.tap do |ref|
|
|
|
|
|
|
|
|
ref.each do |option|
|
|
|
|
|
|
|
|
option_namespace = Array(namespace.dup)
|
|
|
|
option_namespace.push(option['name'])
|
|
|
|
|
|
|
|
option['value'] = option_namespace.join('::')
|
|
|
|
|
|
|
|
next if option['children'].blank?
|
|
|
|
|
|
|
|
option['children'] = fix(option['children'], option_namespace)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|