Browse Source

Fixes #5114 - OTRS import: When importing queues with a parent queue to Zammad the migration then stops

Dominik Klein 11 months ago
parent
commit
fecdb19362

+ 9 - 0
lib/import/otrs/queue_factory.rb

@@ -4,6 +4,15 @@ module Import
   module OTRS
     module QueueFactory
       extend Import::Factory
+
+      # rubocop:disable Style/ModuleFunction
+      extend self
+      # rubocop:enable Style/ModuleFunction
+
+      # We need to sort the records by name, to avoid missing parent queues.
+      def pre_import_hook(records, *_args)
+        records.sort_by! { |record| record['Name'] }
+      end
     end
   end
 end

+ 25 - 0
spec/fixtures/files/import/otrs/queue/child.json

@@ -0,0 +1,25 @@
+{
+  "ValidID": "2",
+  "FollowUpLock": "0",
+  "RealName": "UnitTest49130",
+  "QueueID": "12",
+  "FirstResponseNotify": "0",
+  "UpdateTime": "0",
+  "Email": "unittest15486@example.com",
+  "ChangeTime": "2014-05-13 10:54:11",
+  "UnlockTimeout": "0",
+  "Calendar": "",
+  "CreateTime": "2014-05-13 10:54:11",
+  "Comment": "Some comment",
+  "UpdateNotify": "0",
+  "DefaultSignKey": "",
+  "GroupID": "1",
+  "SolutionTime": "0",
+  "SolutionNotify": "0",
+  "SystemAddressID": "8",
+  "FollowUpID": "1",
+  "SalutationID": "1",
+  "Name": "UnitTestQueue45699::UnitTest49130",
+  "SignatureID": "8",
+  "FirstResponseTime": "0"
+}

+ 19 - 0
spec/lib/import/otrs/queue_factory_spec.rb

@@ -5,4 +5,23 @@ require 'lib/import/factory_examples'
 
 RSpec.describe Import::OTRS::QueueFactory do
   it_behaves_like 'Import::Factory'
+
+  def load_queue_json(file)
+    json_fixture("import/otrs/queue/#{file}")
+  end
+
+  context 'when parent and child queues are imported' do
+    let(:parent_queue) { load_queue_json('default') }
+    let(:child_queue)  { load_queue_json('child') }
+
+    it 'sorts queues by name and imports successfully', :aggregate_failures do
+      expect(described_class.import([child_queue, parent_queue])).to include(
+        hash_including('Name' => parent_queue['Name']),
+        hash_including('Name' => child_queue['Name'])
+      )
+
+      expect(Group.find_by(name: parent_queue['Name'])).to be_present
+      expect(Group.find_by(name: child_queue['Name'])).to be_present
+    end
+  end
 end