FIX: Wrap custom fields database statements in a transaction.
Kind of strange that we don't do it because a database statement may fail and leave us in a weird state.
This commit is contained in:
parent
287e780f22
commit
22408f93c9
|
@ -194,9 +194,9 @@ module HasCustomFields
|
||||||
def save_custom_fields(force = false)
|
def save_custom_fields(force = false)
|
||||||
if force || !custom_fields_clean?
|
if force || !custom_fields_clean?
|
||||||
dup = @custom_fields.dup
|
dup = @custom_fields.dup
|
||||||
|
|
||||||
array_fields = {}
|
array_fields = {}
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
_custom_fields.reload.each do |f|
|
_custom_fields.reload.each do |f|
|
||||||
if dup[f.name].is_a?(Array)
|
if dup[f.name].is_a?(Array)
|
||||||
# we need to collect Arrays fully before we can compare them
|
# we need to collect Arrays fully before we can compare them
|
||||||
|
@ -205,7 +205,7 @@ module HasCustomFields
|
||||||
else
|
else
|
||||||
array_fields[f.name] << f
|
array_fields[f.name] << f
|
||||||
end
|
end
|
||||||
elsif dup[f.name].is_a? Hash
|
elsif dup[f.name].is_a?(Hash)
|
||||||
if dup[f.name].to_json != f.value
|
if dup[f.name].to_json != f.value
|
||||||
f.destroy!
|
f.destroy!
|
||||||
else
|
else
|
||||||
|
@ -228,7 +228,7 @@ module HasCustomFields
|
||||||
if fields.length == dup[field_name].length && fields.map(&:value) == dup[field_name]
|
if fields.length == dup[field_name].length && fields.map(&:value) == dup[field_name]
|
||||||
dup.delete(field_name)
|
dup.delete(field_name)
|
||||||
else
|
else
|
||||||
fields.each(&:destroy)
|
fields.each(&:destroy!)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -244,6 +244,7 @@ module HasCustomFields
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
refresh_custom_fields_from_db
|
refresh_custom_fields_from_db
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue