From ef9dbde59d08bd5f49e29fdbf78869d810324125 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 24 Jul 2015 12:10:36 +0200 Subject: [PATCH] Made article attachment creation thread safe. --- lib/import/otrs.rb | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index bf91a64d4..faf93660e 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -668,18 +668,23 @@ module Import::OTRS # import article attachments article['Attachments'].each { |attachment| - Store.add( - object: 'Ticket::Article', - o_id: article_object.id, - filename: Base64.decode64(attachment['Filename']), - data: Base64.decode64(attachment['Content']), - preferences: { - 'Mime-Type' => attachment['ContentType'], - 'Content-ID' => attachment['ContentID'], - 'content-alternative' => attachment['ContentAlternative'], - }, - created_by_id: 1, - ) + begin + Store.add( + object: 'Ticket::Article', + o_id: article_object.id, + filename: Base64.decode64(attachment['Filename']), + data: Base64.decode64(attachment['Content']), + preferences: { + 'Mime-Type' => attachment['ContentType'], + 'Content-ID' => attachment['ContentID'], + 'content-alternative' => attachment['ContentAlternative'], + }, + 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