From 6d4949644678037d14a87c32a1445a0986ead70a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 23 Nov 2014 14:01:08 +0100 Subject: [PATCH] Added system settings to import. --- lib/import/otrs2.rb | 79 +++++++++++++++++++++++++--- test/integration/otrs_import_test.rb | 21 +++++++- 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index 4e7dfb540..2035a04f6 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -231,13 +231,29 @@ module Import::OTRS2 "API key not valid!" end + # set settings + settings = load('SysConfig') + setting(settings) + + # dynamic fields + dynamic_fields = load('DynamicField') + #settings(dynamic_fields, settings) + + # email accounts + #accounts = load('PostMasterAccount') + #account(accounts) + + # email filter + #filters = load('PostMasterFilter') + #filter(filters) + # create states - records = load('State') - state(records) + states = load('State') + state(states) # create priorities - records = load('Priority') - priority(records) + priorities = load('Priority') + priority(priorities) # create groups queues = load('Queue') @@ -689,7 +705,6 @@ module Import::OTRS2 end # sync ticket states - def self.state(records) map = { :ChangeTime => :updated_at, @@ -744,7 +759,6 @@ module Import::OTRS2 end # sync ticket priorities - def self.priority(records) map = { @@ -787,7 +801,6 @@ module Import::OTRS2 end # sync ticket groups / queues - def self.ticket_group(records) map = { :ChangeTime => :updated_at, @@ -1069,6 +1082,58 @@ module Import::OTRS2 end + # sync settings + + def self.setting(records) + + + records.each { |setting| + + # fqdn + if setting['Key'] == 'FQDN' + Setting.set( 'fqdn', setting['Value'] ) + end + + # http type + if setting['Key'] == 'HttpType' + Setting.set( 'http_type', setting['Value'] ) + end + + # system id + if setting['Key'] == 'SystemID' + Setting.set( 'system_id', setting['Value'] ) + end + + # organization + if setting['Key'] == 'Organization' + Setting.set( 'organization', setting['Value'] ) + end + + # sending emails + if setting['Key'] == 'SendmailModule' + # TODO + end + + # number generater + if setting['Key'] == 'Ticket::NumberGenerator' + if setting['Value'] == 'Kernel::System::Ticket::Number::DateChecksum' + Setting.set( 'ticket_number', 'Ticket::Number::Date' ) + Setting.set( 'ticket_number_date', { :checksum => true } ) + elsif setting['Value'] == 'Kernel::System::Ticket::Number::Date' + Setting.set( 'ticket_number', 'Ticket::Number::Date' ) + Setting.set( 'ticket_number_date', { :checksum => false } ) + end + end + + # ticket hook + if setting['Key'] == 'Ticket::Hook' + Setting.set( 'ticket_hook', setting['Value'] ) + end + + } + end + + # set translate valid ids to active = true|false def self._set_valid(record) diff --git a/test/integration/otrs_import_test.rb b/test/integration/otrs_import_test.rb index d60febe93..838bce906 100644 --- a/test/integration/otrs_import_test.rb +++ b/test/integration/otrs_import_test.rb @@ -3,13 +3,20 @@ require 'integration_test_helper' class OtrsImportTest < ActiveSupport::TestCase + # check settings items + test 'check settings' do + assert_equal( '305', Setting.get('system_id'), 'system_id' ) + assert_equal( 'vz305.demo.znuny.com', Setting.get('fqdn'), 'fqdn' ) + assert_equal( 'http', Setting.get('http_type'), 'http_type' ) + assert_equal( 'Example Company VZ305', Setting.get('organization'), 'organization' ) + + end + # check count of imported items test 'check counts' do - #agent_count = User.where() assert_equal( 603, Ticket.count, 'tickets' ) assert_equal( 10, Ticket::State.count, 'ticket states' ) assert_equal( 24, Group.count, 'groups' ) - end # check imported users and permission @@ -147,6 +154,9 @@ class OtrsImportTest < ActiveSupport::TestCase assert_equal( Time.parse('2014-11-20 22:33:41 +0000').gmtime.to_s, ticket.created_at.to_s ) assert_equal( nil, ticket.close_time ) + # check history + # create entry + # ticket is created with state closed ticket = Ticket.find(729) assert_equal( 'test #2', ticket.title ) @@ -159,6 +169,9 @@ class OtrsImportTest < ActiveSupport::TestCase assert_equal( Time.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.created_at.to_s ) assert_equal( Time.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.close_time.to_s ) + # check history + # create entry + # ticket is created open and now closed ticket = Ticket.find(730) assert_equal( 'test #3', ticket.title ) @@ -170,5 +183,9 @@ class OtrsImportTest < ActiveSupport::TestCase assert_equal( 'Noch ein betreuter Kunde', ticket.organization.name ) assert_equal( Time.parse('2014-11-21 00:17:40 +0000').gmtime.to_s, ticket.created_at.to_s ) assert_equal( Time.parse('2014-11-21 00:21:08 +0000').gmtime.to_s, ticket.close_time.to_s ) + + # check history + # create entry + # state change entry end end \ No newline at end of file