Refactored history creation and made it thread safe.
This commit is contained in:
parent
899d56434a
commit
29235acd90
1 changed files with 104 additions and 105 deletions
|
@ -686,9 +686,10 @@ module Import::OTRS
|
||||||
|
|
||||||
#puts "HS: #{record['History'].inspect}"
|
#puts "HS: #{record['History'].inspect}"
|
||||||
record['History'].each { |history|
|
record['History'].each { |history|
|
||||||
|
|
||||||
|
begin
|
||||||
if history['HistoryType'] == 'NewTicket'
|
if history['HistoryType'] == 'NewTicket'
|
||||||
#puts "HS.add( #{history.inspect} )"
|
History.add(
|
||||||
res = History.add(
|
|
||||||
id: history['HistoryID'],
|
id: history['HistoryID'],
|
||||||
o_id: history['TicketID'],
|
o_id: history['TicketID'],
|
||||||
history_type: 'created',
|
history_type: 'created',
|
||||||
|
@ -696,9 +697,7 @@ module Import::OTRS
|
||||||
created_at: history['CreateTime'],
|
created_at: history['CreateTime'],
|
||||||
created_by_id: history['CreateBy']
|
created_by_id: history['CreateBy']
|
||||||
)
|
)
|
||||||
#puts "res #{res.inspect}"
|
elsif history['HistoryType'] == 'StateUpdate'
|
||||||
end
|
|
||||||
if history['HistoryType'] == 'StateUpdate'
|
|
||||||
data = history['Name']
|
data = history['Name']
|
||||||
# "%%new%%open%%"
|
# "%%new%%open%%"
|
||||||
from = nil
|
from = nil
|
||||||
|
@ -728,8 +727,7 @@ module Import::OTRS
|
||||||
created_at: history['CreateTime'],
|
created_at: history['CreateTime'],
|
||||||
created_by_id: history['CreateBy']
|
created_by_id: history['CreateBy']
|
||||||
)
|
)
|
||||||
end
|
elsif history['HistoryType'] == 'Move'
|
||||||
if history['HistoryType'] == 'Move'
|
|
||||||
data = history['Name']
|
data = history['Name']
|
||||||
# "%%Queue1%%5%%Postmaster%%1"
|
# "%%Queue1%%5%%Postmaster%%1"
|
||||||
from = nil
|
from = nil
|
||||||
|
@ -753,8 +751,7 @@ module Import::OTRS
|
||||||
created_at: history['CreateTime'],
|
created_at: history['CreateTime'],
|
||||||
created_by_id: history['CreateBy']
|
created_by_id: history['CreateBy']
|
||||||
)
|
)
|
||||||
end
|
elsif history['HistoryType'] == 'PriorityUpdate'
|
||||||
if history['HistoryType'] == 'PriorityUpdate'
|
|
||||||
data = history['Name']
|
data = history['Name']
|
||||||
# "%%3 normal%%3%%5 very high%%5"
|
# "%%3 normal%%3%%5 very high%%5"
|
||||||
from = nil
|
from = nil
|
||||||
|
@ -778,11 +775,7 @@ module Import::OTRS
|
||||||
created_at: history['CreateTime'],
|
created_at: history['CreateTime'],
|
||||||
created_by_id: history['CreateBy']
|
created_by_id: history['CreateBy']
|
||||||
)
|
)
|
||||||
end
|
elsif history['ArticleID'] && !history['ArticleID'].zero?
|
||||||
|
|
||||||
next if !history['ArticleID']
|
|
||||||
next if history['ArticleID'] == 0
|
|
||||||
|
|
||||||
History.add(
|
History.add(
|
||||||
id: history['HistoryID'],
|
id: history['HistoryID'],
|
||||||
o_id: history['ArticleID'],
|
o_id: history['ArticleID'],
|
||||||
|
@ -793,6 +786,12 @@ module Import::OTRS
|
||||||
created_at: history['CreateTime'],
|
created_at: history['CreateTime'],
|
||||||
created_by_id: history['CreateBy']
|
created_by_id: history['CreateBy']
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
rescue ActiveRecord::RecordNotUnique
|
||||||
|
log "Ticket #{ticket_new[:id]} (history #{history['HistoryID']}) is handled by another thead, skipping."
|
||||||
|
next
|
||||||
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue