sys_config_factory.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Import
  3. module OTRS
  4. module SysConfigFactory
  5. extend self
  6. def import(settings, *_args)
  7. settings.each do |setting|
  8. next if direct_copy?(setting)
  9. next if number_generator?(setting)
  10. next if postmaster_default?(setting)
  11. end
  12. end
  13. def postmaster_default_lookup(key)
  14. @postmaster_defaults ||= {}
  15. @postmaster_defaults[key]
  16. end
  17. private
  18. def direct_settings
  19. %w[HttpType SystemID Organization TicketHook]
  20. end
  21. def direct_copy?(setting)
  22. cleaned_name = cleanup_name(setting['Key'])
  23. return false if direct_settings.exclude?(cleaned_name)
  24. internal_name = cleaned_name.underscore
  25. Setting.set(internal_name, setting['Value'])
  26. true
  27. end
  28. def cleanup_name(key)
  29. key.tr('::', '')
  30. end
  31. def number_generator?(setting)
  32. return false if setting['Key'] != 'Ticket::NumberGenerator'
  33. case setting['Value']
  34. when 'Kernel::System::Ticket::Number::DateChecksum'
  35. Setting.set('ticket_number', 'Ticket::Number::Date')
  36. Setting.set('ticket_number_date', { checksum: true })
  37. when 'Kernel::System::Ticket::Number::Date'
  38. Setting.set('ticket_number', 'Ticket::Number::Date')
  39. Setting.set('ticket_number_date', { checksum: false })
  40. end
  41. true
  42. end
  43. def postmaster_default?(setting)
  44. relevant_configs = %w[PostmasterDefaultPriority PostmasterDefaultState PostmasterFollowUpState]
  45. return false if relevant_configs.exclude?(setting['Key'])
  46. map = {
  47. 'PostmasterDefaultPriority' => :priority_default_create,
  48. 'PostmasterDefaultState' => :state_default_create,
  49. 'PostmasterFollowUpState' => :state_default_follow_up,
  50. }
  51. @postmaster_defaults ||= {}
  52. @postmaster_defaults[ map[setting['Key']] ] = setting['Value']
  53. true
  54. end
  55. end
  56. end
  57. end