trabajo-afectivo/lib/import/otrs/dynamic_field_factory.rb

60 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
module Import
module OTRS
module DynamicFieldFactory
extend Import::Factory
extend Import::Helper
extend self
def skip?(record, *_args)
return true if skip_field?(record['Name'])
return false if importable?(record)
@skip_fields.push(record['Name'])
true
end
def backend_class(record, *_args)
"Import::OTRS::DynamicField::#{record['FieldType']}".constantize
end
def skip_field?(dynamic_field_name)
skip_fields.include?(dynamic_field_name)
end
private
def importable?(dynamic_field)
return false if !supported_object_type?(dynamic_field)
supported_field_type?(dynamic_field)
end
def supported_object_type?(dynamic_field)
return true if dynamic_field['ObjectType'] == 'Ticket'
log "ERROR: Unsupported dynamic field object type '#{dynamic_field['ObjectType']}' for dynamic field '#{dynamic_field['Name']}'"
false
end
def supported_field_type?(dynamic_field)
return true if supported_field_types.include?(dynamic_field['FieldType'])
log "ERROR: Unsupported dynamic field field type '#{dynamic_field['FieldType']}' for dynamic field '#{dynamic_field['Name']}'"
false
end
def supported_field_types
2017-11-23 08:09:44 +00:00
%w[Text TextArea Checkbox DateTime Date Dropdown Multiselect]
end
def skip_fields
return @skip_fields if @skip_fields
2017-11-23 08:09:44 +00:00
@skip_fields = %w[ProcessManagementProcessID ProcessManagementActivityID ZammadMigratorChanged ZammadMigratorChangedOld]
end
end
end
end