2018-03-23 14:26:09 +00:00
|
|
|
class CheckForObjectAttributes < ActiveRecord::Migration[5.1]
|
|
|
|
def change
|
|
|
|
return if !Setting.find_by(name: 'system_init_done')
|
|
|
|
|
|
|
|
attributes.each do |attribute|
|
|
|
|
|
|
|
|
fix_nil_data_option(attribute)
|
|
|
|
fix_options(attribute)
|
|
|
|
fix_relation(attribute)
|
2018-10-31 13:14:26 +00:00
|
|
|
fix_interger_missing_min_max(attribute)
|
2018-03-23 14:26:09 +00:00
|
|
|
|
|
|
|
next if !attribute.changed?
|
|
|
|
|
|
|
|
attribute.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def attributes
|
|
|
|
ObjectManager::Attribute.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def fix_nil_data_option(attribute)
|
2018-03-29 01:07:13 +00:00
|
|
|
return if attribute[:data_option].is_a?(Hash) || attribute[:data_option][:options].is_a?(Array)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-03-23 14:26:09 +00:00
|
|
|
attribute[:data_option] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def fix_options(attribute)
|
2018-03-29 11:46:15 +00:00
|
|
|
return if attribute[:data_option][:options].is_a?(Hash)
|
|
|
|
return if attribute[:data_option][:options].is_a?(Array)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-03-23 14:26:09 +00:00
|
|
|
attribute[:data_option][:options] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def fix_relation(attribute)
|
|
|
|
return if attribute[:data_option][:relation].is_a?(String)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-03-23 14:26:09 +00:00
|
|
|
attribute[:data_option][:relation] = ''
|
|
|
|
end
|
2018-10-31 13:14:26 +00:00
|
|
|
|
|
|
|
# fixes issue #2318 - Upgrade to Zammad 2.7 was not possible (migration 20180220171219 CheckForObjectAttributes failed)
|
|
|
|
def fix_interger_missing_min_max(attribute)
|
|
|
|
return if attribute[:data_type] != 'integer'
|
|
|
|
|
|
|
|
attribute[:data_option][:min] = 0 if !attribute[:data_option][:min]
|
|
|
|
attribute[:data_option][:max] = 1_000_000 if !attribute[:data_option][:max]
|
|
|
|
end
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|