Skip to content

Commit

Permalink
Fixes #5114 - OTRS import: When importing queues with a parent queue …
Browse files Browse the repository at this point in the history
…to Zammad the migration then stops
  • Loading branch information
dominikklein committed Apr 9, 2024
1 parent b08d6c9 commit fecdb19
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/import/otrs/queue_factory.rb
Expand Up @@ -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 changes: 25 additions & 0 deletions 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 changes: 19 additions & 0 deletions spec/lib/import/otrs/queue_factory_spec.rb
Expand Up @@ -5,4 +5,23 @@

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

0 comments on commit fecdb19

Please sign in to comment.