2016-11-29 11:04:09 +00:00
|
|
|
# rubocop:disable Style/ClassVars
|
2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
class History
|
|
|
|
|
|
|
|
def initialize(history)
|
|
|
|
init_callback(history)
|
2016-11-29 11:04:09 +00:00
|
|
|
ensure_history_attribute
|
2016-11-25 16:10:37 +00:00
|
|
|
add
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_callback(_)
|
|
|
|
raise 'No init callback defined for this history!'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def add
|
|
|
|
::History.add(@history_attributes)
|
|
|
|
end
|
2016-11-29 11:04:09 +00:00
|
|
|
|
|
|
|
# make sure that no other thread is importing just the same
|
|
|
|
# history attribute which causes a ActiveRecord::RecordNotUnique
|
|
|
|
# exception we (currently) can't handle otherwise
|
|
|
|
def ensure_history_attribute
|
|
|
|
history_attribute = @history_attributes[:history_attribute]
|
|
|
|
return if !history_attribute
|
|
|
|
@@created_history_attributes ||= {}
|
|
|
|
return if @@created_history_attributes[history_attribute]
|
|
|
|
@@created_history_attributes[history_attribute] = true
|
|
|
|
::History.attribute_lookup(history_attribute)
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|