Skip to content

Commit

Permalink
Only sync fields for created page
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertandy committed Dec 19, 2018
1 parent 7248713 commit 7425efb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/models/content/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def available_for_site?(site)
protected

def import_fields_from_blueprint
page_blueprint.send :sync_page_fields
page_blueprint.sync_fields_for_page(self)
end

def should_generate_new_friendly_id?
Expand Down
28 changes: 16 additions & 12 deletions app/models/content/page_blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ class PageBlueprint < ActiveRecord::Base

validates :name, :template, presence: true, uniqueness: true

protected
def sync_fields_for_page(page)
existing_fields = page.fields.map do |field|
field.from_blueprint

def sync_page_fields
pages.each do |page|
existing_fields = page.fields.map do |field|
field.from_blueprint
field.field_blueprint_id
end

# Iterate over the field blueprints and create any that are new
field_blueprints.each do |field_blueprint|
next if existing_fields.include? field_blueprint.id

field.field_blueprint_id
end
page.fields << field_blueprint.field_type.constantize.new.from_blueprint(field_blueprint)
end
end

# Iterate over the field blueprints and create any that are new
field_blueprints.each do |field_blueprint|
next if existing_fields.include? field_blueprint.id
protected

page.fields << field_blueprint.field_type.constantize.new.from_blueprint(field_blueprint)
end
def sync_page_fields
pages.each do |page|
sync_fields_for_page(page)
end
end
end
Expand Down

0 comments on commit 7425efb

Please sign in to comment.