Fixed issues with the way import handled the content_type.name attribute.
This commit is contained in:
parent
707973be16
commit
a532bb4c60
@ -14,7 +14,13 @@ module Locomotive
|
|||||||
|
|
||||||
content_type = site.content_types.where(:slug => attributes['slug']).first
|
content_type = site.content_types.where(:slug => attributes['slug']).first
|
||||||
|
|
||||||
content_type ||= self.build_content_type(attributes.merge(:name => name))
|
content_type_name = attributes['name'] || name
|
||||||
|
|
||||||
|
if content_type.nil?
|
||||||
|
content_type = self.build_content_type(attributes.merge(:name => content_type_name))
|
||||||
|
else
|
||||||
|
self.update_attributes(content_type, attributes.merge(:name => content_type_name))
|
||||||
|
end
|
||||||
|
|
||||||
self.add_or_update_fields(content_type, attributes['fields'])
|
self.add_or_update_fields(content_type, attributes['fields'])
|
||||||
|
|
||||||
@ -51,14 +57,23 @@ module Locomotive
|
|||||||
database['site']['content_types']
|
database['site']['content_types']
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_content_type(data)
|
def cleanse_attributes(data)
|
||||||
attributes = { :group_by_field_name => data.delete('group_by') }.merge(data)
|
attributes = { :group_by_field_name => data.delete('group_by') }.merge(data)
|
||||||
|
|
||||||
attributes.delete_if { |name, value| %w{fields contents}.include?(name) }
|
attributes.delete_if { |name, value| %w{fields contents}.include?(name) }
|
||||||
|
attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_content_type(data)
|
||||||
|
attributes = cleanse_attributes(data)
|
||||||
site.content_types.build(attributes)
|
site.content_types.build(attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_attributes(content_type, data)
|
||||||
|
attributes = cleanse_attributes(data)
|
||||||
|
content_type.update(attributes)
|
||||||
|
end
|
||||||
|
|
||||||
def add_or_update_fields(content_type, fields)
|
def add_or_update_fields(content_type, fields)
|
||||||
fields.each_with_index do |data, position|
|
fields.each_with_index do |data, position|
|
||||||
name, data = data.keys.first, data.values.first
|
name, data = data.keys.first, data.values.first
|
||||||
|
Loading…
Reference in New Issue
Block a user