Improved import of articles.
This commit is contained in:
parent
8850bf299b
commit
41d2c6c881
1 changed files with 86 additions and 74 deletions
|
@ -340,9 +340,7 @@ module Import::OTRS2
|
|||
end
|
||||
|
||||
# get agents groups
|
||||
ActiveRecord::Base.transaction do
|
||||
groups = load('Group')
|
||||
end
|
||||
|
||||
# get agents roles
|
||||
roles = load('Role')
|
||||
|
@ -581,28 +579,27 @@ module Import::OTRS2
|
|||
ticket.save
|
||||
end
|
||||
|
||||
# utf8 encode
|
||||
record['Articles'].each { |article|
|
||||
article.each { |key, value|
|
||||
next if !value
|
||||
next if value.class != String
|
||||
article[key] = Encode.conv( 'utf8', value )
|
||||
}
|
||||
}
|
||||
|
||||
# lookup customers to create first
|
||||
record['Articles'].each { |article|
|
||||
|
||||
# get article values
|
||||
article_new = {
|
||||
created_by_id: 1,
|
||||
updated_by_id: 1,
|
||||
}
|
||||
map[:Article].each { |key, value|
|
||||
if article[key.to_s]
|
||||
article_new[value] = Encode.conv( 'utf8', article[key.to_s] )
|
||||
end
|
||||
}
|
||||
|
||||
# create customer/sender if needed
|
||||
if article_new[:sender] == 'customer' && article_new[:created_by_id].to_i == 1 && !article_new[:from].empty?
|
||||
if article['sender'] == 'customer' && article['created_by_id'].to_i == 1 && !article['from'].empty?
|
||||
|
||||
email = nil
|
||||
begin
|
||||
email = Mail::Address.new( article_new[:from] ).address
|
||||
email = Mail::Address.new( article['from'] ).address
|
||||
rescue
|
||||
email = article_new[:from]
|
||||
if article_new[:from] =~ /<(.+?)>/
|
||||
email = article['from']
|
||||
if article['from'] =~ /<(.+?)>/
|
||||
email = $1
|
||||
end
|
||||
end
|
||||
|
@ -622,10 +619,10 @@ module Import::OTRS2
|
|||
end
|
||||
if !user
|
||||
begin
|
||||
display_name = Mail::Address.new( article_new[:from] ).display_name ||
|
||||
( Mail::Address.new( article_new[:from] ).comments && Mail::Address.new( article_new[:from] ).comments[0] )
|
||||
display_name = Mail::Address.new( article['from'] ).display_name ||
|
||||
( Mail::Address.new( article['from'] ).comments && Mail::Address.new( article['from'] ).comments[0] )
|
||||
rescue
|
||||
display_name = article_new[:from]
|
||||
display_name = article['from']
|
||||
end
|
||||
|
||||
# do extra decoding because we needed to use field.value
|
||||
|
@ -644,11 +641,27 @@ module Import::OTRS2
|
|||
created_by_id: 1,
|
||||
)
|
||||
end
|
||||
article_new[:created_by_id] = user.id
|
||||
article['created_by_id'] = user.id
|
||||
|
||||
# unlock user
|
||||
locks[:User][ email ] = false
|
||||
end
|
||||
}
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
record['Articles'].each { |article|
|
||||
|
||||
# get article values
|
||||
article_new = {
|
||||
created_by_id: 1,
|
||||
updated_by_id: 1,
|
||||
}
|
||||
|
||||
map[:Article].each { |key, value|
|
||||
if article[key.to_s]
|
||||
article_new[value] = Encode.conv( 'utf8', article[key.to_s] )
|
||||
end
|
||||
}
|
||||
|
||||
if article_new[:sender] == 'customer'
|
||||
article_new[:sender_id] = Ticket::Article::Sender.lookup( name: 'Customer' ).id
|
||||
|
@ -697,10 +710,9 @@ module Import::OTRS2
|
|||
article.id = article_new[:id]
|
||||
article.save
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
#puts "HS: #{record['History'].inspect}"
|
||||
ActiveRecord::Base.transaction do
|
||||
record['History'].each { |history|
|
||||
if history['HistoryType'] == 'NewTicket'
|
||||
#puts "HS.add( #{history.inspect} )"
|
||||
|
@ -807,8 +819,8 @@ module Import::OTRS2
|
|||
created_by_id: history['CreateBy']
|
||||
)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue