|
@@ -40,19 +40,19 @@ add a new history entry for an object
|
|
|
return if Setting.get('import_mode') && !data[:id]
|
|
|
|
|
|
# lookups
|
|
|
- if data[:history_type]
|
|
|
+ if data[:history_type].present?
|
|
|
history_type = type_lookup(data[:history_type])
|
|
|
end
|
|
|
- if data[:history_object]
|
|
|
+ if data[:history_object].present?
|
|
|
history_object = object_lookup(data[:history_object])
|
|
|
end
|
|
|
related_history_object_id = nil
|
|
|
- if data[:related_history_object]
|
|
|
+ if data[:related_history_object].present?
|
|
|
related_history_object = object_lookup(data[:related_history_object])
|
|
|
related_history_object_id = related_history_object.id
|
|
|
end
|
|
|
history_attribute_id = nil
|
|
|
- if data[:history_attribute]
|
|
|
+ if data[:history_attribute].present?
|
|
|
history_attribute = attribute_lookup(data[:history_attribute])
|
|
|
history_attribute_id = history_attribute.id
|
|
|
end
|
|
@@ -80,11 +80,11 @@ add a new history entry for an object
|
|
|
if history_record
|
|
|
history_record.update!(record)
|
|
|
else
|
|
|
- record_new = History.create(record)
|
|
|
+ record_new = History.create!(record)
|
|
|
if record[:id]
|
|
|
record_new.id = record[:id]
|
|
|
end
|
|
|
- record_new.save
|
|
|
+ record_new.save!
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -148,7 +148,7 @@ returns
|
|
|
=end
|
|
|
|
|
|
def self.list(requested_object, requested_object_id, related_history_object = nil, assets = nil)
|
|
|
- if !related_history_object
|
|
|
+ if related_history_object.blank?
|
|
|
history_object = object_lookup(requested_object)
|
|
|
history = History.where(history_object_id: history_object.id)
|
|
|
.where(o_id: requested_object_id)
|
|
@@ -220,14 +220,10 @@ returns
|
|
|
def self.type_lookup(name)
|
|
|
# lookup
|
|
|
history_type = History::Type.lookup(name: name)
|
|
|
- if history_type
|
|
|
- return history_type
|
|
|
- end
|
|
|
+ return history_type if history_type
|
|
|
|
|
|
# create
|
|
|
- History::Type.create(
|
|
|
- name: name
|
|
|
- )
|
|
|
+ History::Type.create!(name: name)
|
|
|
end
|
|
|
|
|
|
def self.object_lookup_id(id)
|
|
@@ -237,14 +233,10 @@ returns
|
|
|
def self.object_lookup(name)
|
|
|
# lookup
|
|
|
history_object = History::Object.lookup(name: name)
|
|
|
- if history_object
|
|
|
- return history_object
|
|
|
- end
|
|
|
+ return history_object if history_object
|
|
|
|
|
|
# create
|
|
|
- History::Object.create(
|
|
|
- name: name
|
|
|
- )
|
|
|
+ History::Object.create!(name: name)
|
|
|
end
|
|
|
|
|
|
def self.attribute_lookup_id(id)
|
|
@@ -254,14 +246,10 @@ returns
|
|
|
def self.attribute_lookup(name)
|
|
|
# lookup
|
|
|
history_attribute = History::Attribute.lookup(name: name)
|
|
|
- if history_attribute
|
|
|
- return history_attribute
|
|
|
- end
|
|
|
+ return history_attribute if history_attribute
|
|
|
|
|
|
# create
|
|
|
- History::Attribute.create(
|
|
|
- name: name
|
|
|
- )
|
|
|
+ History::Attribute.create!(name: name)
|
|
|
end
|
|
|
|
|
|
class Object < ApplicationModel
|