Made article attachment creation thread safe.

This commit is contained in:
Thorsten Eckel 2015-07-24 12:10:36 +02:00
parent befab460a5
commit ef9dbde59d

View file

@ -668,18 +668,23 @@ module Import::OTRS
# import article attachments # import article attachments
article['Attachments'].each { |attachment| article['Attachments'].each { |attachment|
Store.add( begin
object: 'Ticket::Article', Store.add(
o_id: article_object.id, object: 'Ticket::Article',
filename: Base64.decode64(attachment['Filename']), o_id: article_object.id,
data: Base64.decode64(attachment['Content']), filename: Base64.decode64(attachment['Filename']),
preferences: { data: Base64.decode64(attachment['Content']),
'Mime-Type' => attachment['ContentType'], preferences: {
'Content-ID' => attachment['ContentID'], 'Mime-Type' => attachment['ContentType'],
'content-alternative' => attachment['ContentAlternative'], 'Content-ID' => attachment['ContentID'],
}, 'content-alternative' => attachment['ContentAlternative'],
created_by_id: 1, },
) created_by_id: 1,
)
rescue ActiveRecord::RecordNotUnique
log "Ticket #{ticket_new[:id]} (article #{article_object.id}, Content-ID #{attachment['ContentID']}) is handled by another thead, skipping."
next
end
} }
end end
end end