dynamic_field_factory.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Import
  3. module OTRS
  4. module DynamicFieldFactory
  5. extend Import::Factory
  6. extend Import::Helper
  7. extend self
  8. def skip?(record, *_args)
  9. return true if skip_field?(record['Name'])
  10. return false if importable?(record)
  11. @skip_fields.push(record['Name'])
  12. true
  13. end
  14. def backend_class(record, *_args)
  15. "Import::OTRS::DynamicField::#{record['FieldType']}".constantize
  16. end
  17. def skip_field?(dynamic_field_name)
  18. skip_fields.include?(dynamic_field_name)
  19. end
  20. private
  21. def importable?(dynamic_field)
  22. return false if !supported_object_type?(dynamic_field)
  23. supported_field_type?(dynamic_field)
  24. end
  25. def supported_object_type?(dynamic_field)
  26. return true if dynamic_field['ObjectType'] == 'Ticket'
  27. log "ERROR: Unsupported dynamic field object type '#{dynamic_field['ObjectType']}' for dynamic field '#{dynamic_field['Name']}'"
  28. false
  29. end
  30. def supported_field_type?(dynamic_field)
  31. return true if supported_field_types.include?(dynamic_field['FieldType'])
  32. log "ERROR: Unsupported dynamic field field type '#{dynamic_field['FieldType']}' for dynamic field '#{dynamic_field['Name']}'"
  33. false
  34. end
  35. def supported_field_types
  36. %w[Text TextArea Checkbox DateTime Date Dropdown Multiselect]
  37. end
  38. def skip_fields
  39. return @skip_fields if @skip_fields
  40. @skip_fields = %w[ProcessManagementProcessID ProcessManagementActivityID ZammadMigratorChanged ZammadMigratorChangedOld]
  41. end
  42. end
  43. end
  44. end