2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
class DynamicField
|
|
|
|
|
|
|
|
def initialize(dynamic_field)
|
|
|
|
@internal_name = self.class.convert_name(dynamic_field['Name'])
|
|
|
|
|
|
|
|
return if already_imported?(dynamic_field)
|
2022-05-10 10:21:53 +00:00
|
|
|
return if skip?(dynamic_field)
|
2016-11-25 16:10:37 +00:00
|
|
|
|
|
|
|
initialize_attribute_config(dynamic_field)
|
|
|
|
|
|
|
|
init_callback(dynamic_field)
|
|
|
|
add
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.convert_name(dynamic_field_name)
|
2021-05-12 11:37:44 +00:00
|
|
|
dynamic_field_name.underscore.sub(%r{_id(s)?\z}, '_no\1')
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def init_callback(_)
|
|
|
|
raise 'No init callback defined for this dynamic field!'
|
|
|
|
end
|
|
|
|
|
|
|
|
def already_imported?(dynamic_field)
|
|
|
|
attribute = ObjectManager::Attribute.get(
|
|
|
|
object: dynamic_field['ObjectType'],
|
|
|
|
name: @internal_name,
|
|
|
|
)
|
|
|
|
attribute ? true : false
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize_attribute_config(dynamic_field)
|
|
|
|
|
|
|
|
@attribute_config = {
|
2018-12-19 17:31:51 +00:00
|
|
|
object: dynamic_field['ObjectType'],
|
|
|
|
name: @internal_name,
|
|
|
|
display: dynamic_field['Label'],
|
|
|
|
screens: {
|
2016-11-25 16:10:37 +00:00
|
|
|
view: {
|
|
|
|
'-all-' => {
|
|
|
|
shown: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
active: true,
|
|
|
|
editable: dynamic_field['InternalField'] == '0',
|
|
|
|
position: dynamic_field['FieldOrder'],
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-05-10 10:21:53 +00:00
|
|
|
def skip?(_dynamic_field)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
def add
|
|
|
|
ObjectManager::Attribute.add(@attribute_config)
|
|
|
|
ObjectManager::Attribute.migration_execute(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|