2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
module SysConfigFactory
|
|
|
|
extend self
|
|
|
|
|
2016-12-20 15:16:09 +00:00
|
|
|
def import(settings, *_args)
|
2016-11-25 16:10:37 +00:00
|
|
|
settings.each do |setting|
|
|
|
|
next if direct_copy?(setting)
|
|
|
|
next if number_generator?(setting)
|
2017-02-14 17:44:14 +00:00
|
|
|
next if postmaster_default?(setting)
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-14 17:44:14 +00:00
|
|
|
def postmaster_default_lookup(key)
|
|
|
|
@postmaster_defaults ||= {}
|
|
|
|
@postmaster_defaults[key]
|
|
|
|
end
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def direct_settings
|
2017-11-23 08:09:44 +00:00
|
|
|
%w[HttpType SystemID Organization TicketHook]
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def direct_copy?(setting)
|
|
|
|
cleaned_name = cleanup_name(setting['Key'])
|
2020-09-30 09:07:01 +00:00
|
|
|
return false if direct_settings.exclude?(cleaned_name)
|
2016-11-25 16:10:37 +00:00
|
|
|
|
|
|
|
internal_name = cleaned_name.underscore
|
|
|
|
Setting.set(internal_name, setting['Value'])
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup_name(key)
|
|
|
|
key.tr('::', '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def number_generator?(setting)
|
|
|
|
return false if setting['Key'] != 'Ticket::NumberGenerator'
|
|
|
|
|
|
|
|
case setting['Value']
|
|
|
|
when 'Kernel::System::Ticket::Number::DateChecksum'
|
|
|
|
Setting.set('ticket_number', 'Ticket::Number::Date')
|
|
|
|
Setting.set('ticket_number_date', { checksum: true })
|
|
|
|
when 'Kernel::System::Ticket::Number::Date'
|
|
|
|
Setting.set('ticket_number', 'Ticket::Number::Date')
|
|
|
|
Setting.set('ticket_number_date', { checksum: false })
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
2017-02-14 17:44:14 +00:00
|
|
|
|
|
|
|
def postmaster_default?(setting)
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
relevant_configs = %w[PostmasterDefaultPriority PostmasterDefaultState PostmasterFollowUpState]
|
2020-09-30 09:07:01 +00:00
|
|
|
return false if relevant_configs.exclude?(setting['Key'])
|
2017-02-14 17:44:14 +00:00
|
|
|
|
|
|
|
map = {
|
|
|
|
'PostmasterDefaultPriority' => :priority_default_create,
|
|
|
|
'PostmasterDefaultState' => :state_default_create,
|
|
|
|
'PostmasterFollowUpState' => :state_default_follow_up,
|
|
|
|
}
|
|
|
|
|
|
|
|
@postmaster_defaults ||= {}
|
|
|
|
@postmaster_defaults[ map[setting['Key']] ] = setting['Value']
|
|
|
|
true
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|