Fixed issue: Zendesk attachments might get imported multiple times for single article.
This commit is contained in:
parent
2b2ceeebab
commit
d96d02c83f
2 changed files with 21 additions and 3 deletions
|
@ -7,8 +7,26 @@ module Import
|
||||||
# so we can use the default import factory here
|
# so we can use the default import factory here
|
||||||
extend Import::Factory
|
extend Import::Factory
|
||||||
|
|
||||||
|
# rubocop:disable Style/ModuleFunction
|
||||||
|
extend self
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# special handling which only starts import if needed
|
||||||
|
# Attention: skip? method can't be used since it (currently)
|
||||||
|
# only checks for single records - not all
|
||||||
|
def import_loop(records, *args, &import_block)
|
||||||
|
local_article = args[0]
|
||||||
|
local_attachments = local_article.attachments
|
||||||
|
|
||||||
|
return if local_attachments.count == records.count
|
||||||
|
# get a common ground
|
||||||
|
local_attachments.each(&:delete)
|
||||||
|
return if records.empty?
|
||||||
|
|
||||||
|
records.each(&import_block)
|
||||||
|
end
|
||||||
|
|
||||||
def create_instance(record, *args)
|
def create_instance(record, *args)
|
||||||
local_article = args[0]
|
local_article = args[0]
|
||||||
backend_class(record).new(record, local_article)
|
backend_class(record).new(record, local_article)
|
||||||
|
|
|
@ -384,7 +384,7 @@ If you\'re reading this message in your email, click the ticket number link that
|
||||||
|
|
||||||
checks = [
|
checks = [
|
||||||
{
|
{
|
||||||
id: 5,
|
message_id: 39_984_258_725,
|
||||||
data: {
|
data: {
|
||||||
count: 1,
|
count: 1,
|
||||||
1 => {
|
1 => {
|
||||||
|
@ -396,7 +396,7 @@ If you\'re reading this message in your email, click the ticket number link that
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 7,
|
message_id: 32_817_827_921,
|
||||||
data: {
|
data: {
|
||||||
count: 1,
|
count: 1,
|
||||||
1 => {
|
1 => {
|
||||||
|
@ -410,7 +410,7 @@ If you\'re reading this message in your email, click the ticket number link that
|
||||||
]
|
]
|
||||||
|
|
||||||
checks.each { |check|
|
checks.each { |check|
|
||||||
article = Ticket::Article.find(check[:id])
|
article = Ticket::Article.find_by(message_id: check[:message_id])
|
||||||
|
|
||||||
assert_equal(check[:data][:count], article.attachments.count, 'attachemnt count')
|
assert_equal(check[:data][:count], article.attachments.count, 'attachemnt count')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue