public
Description: OneBody is web-based software that connects community members, especially churches, on the web.
Homepage: http://beonebody.com
Clone URL: git://github.com/seven1m/onebody.git
Fix broken pages migration (again).
Don't duplicate page when creating a new site.
Tim Morgan (author)
Sun Aug 17 19:16:07 -0700 2008
commit  e14a3a39fdaece81684f1df6ceab5ec67f3117c1
tree    d58e29b9e5c991f11a34fd8fda757e9d96275309
parent  75034c80e44a35a8d47de01128e67db22c01f0c7
...
95
96
97
98
 
99
100
101
...
95
96
97
 
98
99
100
101
0
@@ -95,7 +95,7 @@ class Site < ActiveRecord::Base
0
   end
0
   
0
   def add_pages
0
-    if connection.select_value("SELECT count(*) from pages where site_id=#{id}").to_i == 0
0
+    if Page.table_exists?
0
       require Rails.root + "/db/migrate/20080722143227_move_system_content_to_pages"
0
       MoveSystemContentToPages.up
0
     end
...
5
6
7
8
 
 
 
9
10
11
...
13
14
15
16
 
 
 
 
17
18
19
...
5
6
7
 
8
9
10
11
12
13
...
15
16
17
 
18
19
20
21
22
23
24
0
@@ -5,7 +5,9 @@ class MoveSystemContentToPages < ActiveRecord::Migration
0
         html = File.read(filename)
0
         path, filename = filename.split('pages/').last.split('/')
0
         pub = nav = path != 'system'
0
-        Page.create!(:slug => path, :title => path.titleize, :body => html, :system => true, :navigation => nav, :published => pub)
0
+        unless Page.find_by_path(path)
0
+          Page.create!(:slug => path, :title => path.titleize, :body => html, :system => true, :navigation => nav, :published => pub)
0
+        end
0
       end
0
       Dir[File.dirname(__FILE__) + "/20080722143227_move_system_content_to_pages/**/*.html"].each do |filename|
0
         next if filename =~ /index\.html$/
0
@@ -13,7 +15,10 @@ class MoveSystemContentToPages < ActiveRecord::Migration
0
         path, filename = filename.split('pages/').last.split('/')
0
         slug = filename.split('.').first
0
         nav = path != 'system'
0
-        Page.find_by_path(path).children.create!(:slug => slug, :title => slug.titleize, :body => html, :system => true, :navigation => nav, :published => true)
0
+        parent = Page.find_by_path(path)
0
+        unless parent.children.find_by_slug(slug)
0
+          parent.children.create!(:slug => slug, :title => slug.titleize, :body => html, :system => true, :navigation => nav, :published => true)
0
+        end
0
       end
0
       unless Page.find_by_path('home')
0
         Page.create!(:slug => 'home', :title => 'Home', :body => 'Congratulations! OneBody is up and running.', :system => true)

Comments