Fixes #3582 - Freshdesk import attribute ID mapping lookup constants fail application boot in systems with changed default names.
This commit is contained in:
parent
8d01fdd7cc
commit
18b88920e7
3 changed files with 66 additions and 50 deletions
|
@ -8,25 +8,31 @@ class Sequencer
|
||||||
|
|
||||||
uses :resource, :id_map
|
uses :resource, :id_map
|
||||||
|
|
||||||
SOURCE_MAP = {
|
# Since the imports rely on a fresh Zammad installation, we
|
||||||
0 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Reply
|
# can require the default article types and senders to be present.
|
||||||
1 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Email
|
def source_map # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
||||||
2 => ::Ticket::Article::Type.select(:id).find_by(name: 'web').id, # Note
|
@source_map ||= {
|
||||||
3 => ::Ticket::Article::Type.select(:id).find_by(name: 'phone').id, # Phone
|
0 => ::Ticket::Article::Type.select(:id).find_by(name: 'email')&.id, # Reply
|
||||||
4 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # UNKNOWN!
|
1 => ::Ticket::Article::Type.select(:id).find_by(name: 'email')&.id, # Email
|
||||||
5 => ::Ticket::Article::Type.select(:id).find_by(name: 'twitter status').id, # Created from tweets
|
2 => ::Ticket::Article::Type.select(:id).find_by(name: 'web')&.id, # Note
|
||||||
6 => ::Ticket::Article::Type.select(:id).find_by(name: 'web').id, # Created from survey feedback
|
3 => ::Ticket::Article::Type.select(:id).find_by(name: 'phone')&.id, # Phone
|
||||||
7 => ::Ticket::Article::Type.select(:id).find_by(name: 'facebook feed post').id, # Created from Facebook post
|
4 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # UNKNOWN!
|
||||||
8 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Created from Forwarded Email
|
5 => ::Ticket::Article::Type.select(:id).find_by(name: 'twitter status')&.id, # Created from tweets
|
||||||
9 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # Created from Phone
|
6 => ::Ticket::Article::Type.select(:id).find_by(name: 'web')&.id, # Created from survey feedback
|
||||||
10 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # Created from Mobihelp
|
7 => ::Ticket::Article::Type.select(:id).find_by(name: 'facebook feed post')&.id, # Created from Facebook post
|
||||||
11 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # E-Commerce
|
8 => ::Ticket::Article::Type.select(:id).find_by(name: 'email')&.id, # Created from Forwarded Email
|
||||||
|
9 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # Created from Phone
|
||||||
|
10 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # Created from Mobihelp
|
||||||
|
11 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # E-Commerce
|
||||||
}.freeze
|
}.freeze
|
||||||
|
end
|
||||||
|
|
||||||
INCOMING_MAP = {
|
def incoming_map
|
||||||
true => ::Ticket::Article::Sender.select(:id).find_by(name: 'Customer').id,
|
@incoming_map ||= {
|
||||||
false => ::Ticket::Article::Sender.select(:id).find_by(name: 'Agent').id,
|
true => ::Ticket::Article::Sender.select(:id).find_by(name: 'Customer')&.id,
|
||||||
|
false => ::Ticket::Article::Sender.select(:id).find_by(name: 'Agent')&.id,
|
||||||
}.freeze
|
}.freeze
|
||||||
|
end
|
||||||
|
|
||||||
def process # rubocop:disable Metrics/AbcSize
|
def process # rubocop:disable Metrics/AbcSize
|
||||||
provide_mapped do
|
provide_mapped do
|
||||||
|
@ -41,8 +47,8 @@ class Sequencer
|
||||||
message_id: resource['id'],
|
message_id: resource['id'],
|
||||||
updated_by_id: user_id,
|
updated_by_id: user_id,
|
||||||
created_by_id: user_id,
|
created_by_id: user_id,
|
||||||
sender_id: INCOMING_MAP[ resource['incoming'] ],
|
sender_id: incoming_map[ resource['incoming'] ],
|
||||||
type_id: SOURCE_MAP[ resource['source'] ],
|
type_id: source_map[ resource['source'] ],
|
||||||
created_at: resource['created_at'],
|
created_at: resource['created_at'],
|
||||||
updated_at: resource['updated_at'],
|
updated_at: resource['updated_at'],
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,20 +8,24 @@ class Sequencer
|
||||||
|
|
||||||
uses :resource, :id_map
|
uses :resource, :id_map
|
||||||
|
|
||||||
SOURCE_MAP = {
|
# Since the imports rely on a fresh Zammad installation, we
|
||||||
0 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Reply
|
# can require the default article types to be present.
|
||||||
1 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Email
|
def source_map # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
||||||
2 => ::Ticket::Article::Type.select(:id).find_by(name: 'web').id, # Note
|
@source_map ||= {
|
||||||
3 => ::Ticket::Article::Type.select(:id).find_by(name: 'phone').id, # Phone
|
0 => ::Ticket::Article::Type.select(:id).find_by(name: 'email')&.id, # Reply
|
||||||
4 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # UNKNOWN!
|
1 => ::Ticket::Article::Type.select(:id).find_by(name: 'email')&.id, # Email
|
||||||
5 => ::Ticket::Article::Type.select(:id).find_by(name: 'twitter status').id, # Created from tweets
|
2 => ::Ticket::Article::Type.select(:id).find_by(name: 'web')&.id, # Note
|
||||||
6 => ::Ticket::Article::Type.select(:id).find_by(name: 'web').id, # Created from survey feedback
|
3 => ::Ticket::Article::Type.select(:id).find_by(name: 'phone')&.id, # Phone
|
||||||
7 => ::Ticket::Article::Type.select(:id).find_by(name: 'facebook feed post').id, # Created from Facebook post
|
4 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # UNKNOWN!
|
||||||
8 => ::Ticket::Article::Type.select(:id).find_by(name: 'email').id, # Created from Forwarded Email
|
5 => ::Ticket::Article::Type.select(:id).find_by(name: 'twitter status')&.id, # Created from tweets
|
||||||
9 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # Created from Phone
|
6 => ::Ticket::Article::Type.select(:id).find_by(name: 'web')&.id, # Created from survey feedback
|
||||||
10 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # Created from Mobihelp
|
7 => ::Ticket::Article::Type.select(:id).find_by(name: 'facebook feed post')&.id, # Created from Facebook post
|
||||||
11 => ::Ticket::Article::Type.select(:id).find_by(name: 'note').id, # E-Commerce
|
8 => ::Ticket::Article::Type.select(:id).find_by(name: 'email')&.id, # Created from Forwarded Email
|
||||||
|
9 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # Created from Phone
|
||||||
|
10 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # Created from Mobihelp
|
||||||
|
11 => ::Ticket::Article::Type.select(:id).find_by(name: 'note')&.id, # E-Commerce
|
||||||
}.freeze
|
}.freeze
|
||||||
|
end
|
||||||
|
|
||||||
def process # rubocop:disable Metrics/AbcSize
|
def process # rubocop:disable Metrics/AbcSize
|
||||||
provide_mapped do
|
provide_mapped do
|
||||||
|
@ -35,7 +39,7 @@ class Sequencer
|
||||||
internal: false,
|
internal: false,
|
||||||
message_id: "ticketid#{resource['id']}@freshdesk.com",
|
message_id: "ticketid#{resource['id']}@freshdesk.com",
|
||||||
sender_id: ::Ticket::Article::Sender.select(:id).find_by(name: 'Customer').id,
|
sender_id: ::Ticket::Article::Sender.select(:id).find_by(name: 'Customer').id,
|
||||||
type_id: SOURCE_MAP[ resource['source'] ],
|
type_id: source_map[ resource['source'] ],
|
||||||
updated_by_id: requester_id,
|
updated_by_id: requester_id,
|
||||||
created_by_id: requester_id,
|
created_by_id: requester_id,
|
||||||
created_at: resource['created_at'],
|
created_at: resource['created_at'],
|
||||||
|
|
|
@ -8,19 +8,25 @@ class Sequencer
|
||||||
|
|
||||||
uses :resource, :id_map
|
uses :resource, :id_map
|
||||||
|
|
||||||
PRIORITY_MAP = {
|
# Since the imports rely on a fresh Zammad installation, we
|
||||||
1 => ::Ticket::Priority.find_by(name: '1 low').id, # low
|
# can require the default priority and state names to be present.
|
||||||
2 => ::Ticket::Priority.find_by(name: '2 normal').id, # medium
|
def priority_map
|
||||||
3 => ::Ticket::Priority.find_by(name: '3 high').id, # high
|
@priority_map ||= {
|
||||||
4 => ::Ticket::Priority.find_by(name: '3 high').id, # urgent
|
1 => ::Ticket::Priority.find_by(name: '1 low')&.id, # low
|
||||||
|
2 => ::Ticket::Priority.find_by(name: '2 normal')&.id, # medium
|
||||||
|
3 => ::Ticket::Priority.find_by(name: '3 high')&.id, # high
|
||||||
|
4 => ::Ticket::Priority.find_by(name: '3 high')&.id, # urgent
|
||||||
}.freeze
|
}.freeze
|
||||||
|
end
|
||||||
|
|
||||||
STATE_MAP = {
|
def state_map
|
||||||
2 => ::Ticket::State.find_by(name: 'open').id, # open
|
@state_map ||= {
|
||||||
3 => ::Ticket::State.find_by(name: 'open').id, # pending
|
2 => ::Ticket::State.find_by(name: 'open')&.id, # open
|
||||||
4 => ::Ticket::State.find_by(name: 'closed').id, # resolved
|
3 => ::Ticket::State.find_by(name: 'open')&.id, # pending
|
||||||
5 => ::Ticket::State.find_by(name: 'closed').id, # closed
|
4 => ::Ticket::State.find_by(name: 'closed')&.id, # resolved
|
||||||
|
5 => ::Ticket::State.find_by(name: 'closed')&.id, # closed
|
||||||
}.freeze
|
}.freeze
|
||||||
|
end
|
||||||
|
|
||||||
def process # rubocop:disable Metrics/AbcSize
|
def process # rubocop:disable Metrics/AbcSize
|
||||||
provide_mapped do
|
provide_mapped do
|
||||||
|
@ -28,8 +34,8 @@ class Sequencer
|
||||||
title: resource['subject'],
|
title: resource['subject'],
|
||||||
number: resource['id'],
|
number: resource['id'],
|
||||||
group_id: group_id,
|
group_id: group_id,
|
||||||
priority_id: PRIORITY_MAP[resource['priority']],
|
priority_id: priority_map[resource['priority']],
|
||||||
state_id: STATE_MAP[resource['status']],
|
state_id: state_map[resource['status']],
|
||||||
owner_id: owner_id,
|
owner_id: owner_id,
|
||||||
customer_id: customer_id,
|
customer_id: customer_id,
|
||||||
created_at: resource['created_at'],
|
created_at: resource['created_at'],
|
||||||
|
|
Loading…
Reference in a new issue