bcms_mobile 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.0.11'
4
+
5
+ gem 'sqlite3'
6
+
7
+
8
+ group :test do
9
+ gem 'cucumber-rails'
10
+ gem 'database_cleaner'
11
+ # gem 'cucumber-browsercms' # This is what I want
12
+ gem 'bcms_support', :path=>"~/projects/bcms_support"
13
+
14
+ gem 'mocha'
15
+ gem 'launchy'
16
+ gem 'factory_girl_rails'
17
+ end
18
+
19
+ gemspec
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,107 @@
1
+ # Mobile Module for BrowserCMS
2
+
3
+ A 'Mobile First' module that allows any BrowserCMS page to be served in a mobile optimized format for specific mobile devices. Pages can have mobile optimized templates that can reduce their download weight and layout for reduced screen/bandwidth platforms.
4
+
5
+ ## Features
6
+
7
+ * Developers can define a mobile template for any existing .html.erb template on a project. These template are named the same as the existing templates, but are placed in a separate layouts/mobile directory.
8
+ * View as Mobile: Editors should be able to preview the mobile templates. Once in 'mobile' mode, all pages should be viewed as mobile until they disable it.
9
+ * Mobile assumes a m. subdomain will exist. It will return the mobile template for all requests to pages on that domain.
10
+ * Fallback Templates: If page uses a template which has no mobile counterpart, it will display using its normal template.
11
+ * Agent Redirection: Users on mobile devices can be automatically redirected to the m. site. (Handled via Apache User Agent detection.)
12
+ * Mobile Site Opt Out: Users on mobile device can opt to be redirected to the desktop site if they want. (Handled via a cookie)
13
+ * Mobile caching: The mobile and full sites have their own separate page cache, mean both can be served quickly by Apache.
14
+
15
+ ## Installation
16
+
17
+ To install bcms_mobile, run the following commands in your browsercms project:
18
+
19
+ ```
20
+ $ gem install bcms_mobile
21
+ $ rails g cms:install bcms_mobile
22
+ ```
23
+
24
+ This will add a new directory to the project, `app/views/layouts/mobile`. Delete the following line from your config/production.rb file:
25
+ ```
26
+ # Delete this next line as it won't work if you make changes
27
+ config.action_controller.page_cache_directory = File.join(Rails.root, 'public', 'cache')
28
+ ```
29
+
30
+ ### Configuring the Cache Directories
31
+
32
+ Since this module requires a separate top level domain in production (m.), it needs a separate page cache from the 'full' site version. By default, these will be:
33
+
34
+ public/cache -> Full site cache
35
+ public/mobile_cache -> Mobile Cache
36
+
37
+ To configure these directories, you can specify new locations in the production.rb via:
38
+
39
+ ```
40
+ config.bcms_mobile_cache_directory = File.join(Rails.root, 'public', 'cache' 'mobile')
41
+ config.browsercms_cache_directory = File.join(Rails.root, 'public', 'cache', 'full')
42
+ ```
43
+
44
+ However, the defaults will be used even if you don't specify the cache directories.
45
+
46
+ ## Making a Mobile Template
47
+
48
+ To make a mobile template, you can then copy any page template from your `app/views/layouts/templates` into the mobile directory. The file name should be the same. Make any necessary edits to 'mobilize' it (i.e. remove sidebars, image, etc). When you view a page in the CMS, you can toggle between the mobile and desktop templates.
49
+
50
+ ### Add Full/Mobile Site links
51
+
52
+ Because the module will automatically redirect mobile users to the mobile site, they may want to visit the full site. So make sure they are conveniently placed on both mobile and full templates. You can do this with the following helpers:
53
+
54
+ <%= link_to "See the Full Site", full_site_url %>
55
+ <%= link_to "See the Mobile Site", mobile_site_url %>
56
+
57
+
58
+ ## Development
59
+
60
+ ### Things to improve
61
+
62
+ * The Apache conf file has way too much logic in it. Specifically, the device types and matching rules really can't be tested, at all. We also have to have a 3rd virtual host for the m. site which isn't so hot.
63
+
64
+ ### Resources
65
+
66
+ Mobilette - https://github.com/tscolari/mobylette
67
+ Using m.subdomains - http://erniemiller.org/2011/01/05/mobile-devices-and-rails-maintaining-your-sanity/
68
+ Presentation on Rails for Subdomains - http://www.slideshare.net/alberto.perdomo/rails-for-mobile-devices-conferencia-rails-2011-8613648
69
+ Apache Mobile Filters - http://webdirect.no/mobile/apache-rewrite-rule-for-iphone-users/
70
+ RailsCast - http://railscasts.com/episodes/199-mobile-devices?view=comments
71
+
72
+ http://ryanbigg.com/2009/04/how-rails-works-2-mime-types-respond_to/
73
+ http://blog.bigbinary.com/2010/11/23/mime-type-resolution-in-rails.html
74
+ Verify if views exist - http://stackoverflow.com/questions/2853355/check-if-a-layout-exists-in-rails
75
+
76
+ Excellent Cookie Setting solution for Apache: http://www.phillipadsmith.com/2011/11/note-to-self-a-simple-way-to-accomplish-mobile-site-redirection-using-mod-rewrite.html
77
+ Modern Mobile Detection - http://ohryan.ca/blog/2011/01/21/modern-mobile-redirect-using-htaccess/
78
+ Using Apache for User Agent/Detection - http://mobiledrupal.com/simple-apache-configuration-file-mobile-device-detection
79
+ http://ohryan.ca/blog/2011/01/21/modern-mobile-redirect-using-htaccess/
80
+
81
+ ### Getting setup
82
+
83
+ Working on the bcms_mobile and getting accurate testing requires subdomains enabled locally. If you [set up POW](http://pow.cx/), you can use the basic subdomains.
84
+
85
+ Steps:
86
+
87
+ ```
88
+ $ gem install powder
89
+ $ cd bcms_mobile
90
+ $ powder link bcms-mobile
91
+ ```
92
+
93
+ This will make the following subdomains available for testing.
94
+
95
+ m.bcms-mobile.dev
96
+ www.bcms-mobile.dev
97
+ cms.bcms-mobile.dev
98
+
99
+ ## Testing Agent Redirection with Passenger/Apache
100
+
101
+ Using POW will not enable Agent Redirection, since that is configured via Apache. To adequately test this, you will need to enable Apache/Passenger and configure the virtual hosts as [documented here](https://github.com/browsermedia/bcms_mobile/wiki/Configuring-Apache). On OSX, you can can create a new file called /private/etc/apache2/other/bcms_mobile.conf . This [page here](https://github.com/browsermedia/bcms_mobile/wiki/Developing-bcms_mobile) has a sample configuration file
102
+
103
+ To get configuration right, need Apache/Passenger so you can fool around with Apache specific rewrite rules. See these instructions for setting up Passenger on OSX.
104
+
105
+ - http://www.robbyonrails.com/articles/2009/02/11/switch-to-passenger-mod_rails-in-development-on-osx-in-less-than-7-minutes-or-your-money-back
106
+ - http://www.fngtps.com/2008/using-passenger-on-osx-for-rails-development/
107
+
@@ -0,0 +1,31 @@
1
+ <style>
2
+ #mobile_toggle {
3
+ float: left;
4
+ text-transform: uppercase;
5
+ padding-left: 110px;
6
+ margin-top: 12px;
7
+ margin-right: 0px;
8
+ color: black;
9
+ font-weight: bold;
10
+ width: 200px;
11
+ }
12
+
13
+ #mobile_toggle div {
14
+ float: left;
15
+ }
16
+ </style>
17
+ <%
18
+ mobile_state = session[:mobile_mode] == true ? "ON" : "OFF"
19
+ button_text = session[:mobile_mode] == true ? "TURN OFF" : "TURN ON"
20
+ new_template = session[:mobile_mode] == true ? "full" : "mobile"
21
+ %>
22
+
23
+ <div id="mobile_toggle">
24
+ <div class="visual_editor_label">View As Mobile?:</div>
25
+ <div class="visual_editor_value_container">
26
+ <div><span id="visual_editor_state"><%= mobile_state %></span></div>
27
+ </div>
28
+ <div class="visual_editor_toggle_container">
29
+ <div class="sm_button"><%= link_to "<span id='visual_editor_action'>#{button_text}</span>".html_safe, "#{@page.path}?template=#{new_template}", :target => "_top", :class => "sm_button" %></div>
30
+ </div>
31
+ </div>
@@ -0,0 +1,121 @@
1
+ <% if (logged_in? && @page && !@hide_page_toolbar) %>
2
+ <% status = @page.live? ? 'published' : 'draft' %>
3
+ <%= image_tag "cms/page_toolbar/page_toolbar_l.gif", :style => "float: left;" %>
4
+ <%= image_tag "cms/page_toolbar/status_#{status}_l.gif", :style => "float: left;" %>
5
+ <%= image_tag "cms/page_toolbar/page_toolbar_r.gif", :style => "float: right;" %>
6
+ <div id="page_toolbar">
7
+ <div id="status_div" class="<%= status %> page_attribute_div">
8
+ <div class="page_attribute_label">Status:</div>
9
+ <div id="<%= status %>_page_status_container" class="page_attribute_value_container">
10
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_#{ status }_l.gif", :style => "float: left;" %>
11
+ <div id="page_status" class="page_attribute_value"><%= status %></div>
12
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_#{ status }_r.gif", :style => "float: left;" %>
13
+ </div>
14
+ </div>
15
+ <div class="page_attribute_div">
16
+ <div class="page_attribute_label">Section:</div>
17
+ <div class="page_attribute_value_container">
18
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_l.gif", :style => "float: left;" %>
19
+ <div id="section_link" class="page_attribute_value"><%= link_to h(@page.section.name), cms_sections_path(:page_id => @page), :target => "_top" %></div>
20
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_r.gif", :style => "float: left;" %>
21
+ </div>
22
+ </div>
23
+ <div class="page_attribute_div">
24
+ <div class="page_attribute_label">Page:</div>
25
+ <div class="page_attribute_value_container">
26
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_l.gif", :style => "float: left;" %>
27
+ <div class="page_attribute_value"><%= h(@page.name) %></div>
28
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_r.gif", :style => "float: left;" %>
29
+ </div>
30
+ </div>
31
+ <div class="page_attribute_div">
32
+ <div class="page_attribute_label">Template:</div>
33
+ <div class="page_attribute_value_container">
34
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_l.gif", :style => "float: left;" %>
35
+ <div class="page_attribute_value"><%= h(@page.template_name) %></div>
36
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_r.gif", :style => "float: left;" %>
37
+ </div>
38
+ </div>
39
+ <div class="page_attribute_div">
40
+ <div class="page_attribute_label">Version:</div>
41
+ <div class="page_attribute_value_container">
42
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_l.gif", :style => "float: left;" %>
43
+ <div class="page_attribute_value"><%= h(@page.version) %><%= ' (LIVE)' if @page.live_version && @page.version == @page.live_version.version %></div>
44
+ <%= image_tag "cms/page_toolbar/page_toolbar_inset_r.gif", :style => "float: left;" %>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ <div class="buttons">
49
+
50
+ <%= link_to "<span>Publish</span>".html_safe,
51
+ @page.live? ? '#' : publish_cms_page_path(@page),
52
+ :id => "publish_button",
53
+ :class => "http_put button#{' disabled' if !current_user.able_to?(:publish_content) || !current_user.able_to_edit?(@page) || @page.version != @page.draft.version || @page.live?} left",
54
+ :target => "_top" %>
55
+
56
+ <%= link_to "<span>Assign</span>".html_safe,
57
+ new_cms_page_task_path(@page),
58
+ :id => "assign_button",
59
+ :class => "button#{ ' disabled' if @page.assigned_to == current_user || !current_user.able_to_edit?(@page) } middle",
60
+ :target => "_top" %>
61
+
62
+ <%= link_to "<span>Complete Task</span>".html_safe,
63
+ @page.current_task ? complete_cms_task_path(@page.current_task) : '#',
64
+ :id => "complete_task_button",
65
+ :class => "http_put button#{ ' disabled' if @page.assigned_to != current_user || !current_user.able_to_edit?(@page) } right",
66
+ :target => "_top" %>
67
+
68
+ <%= link_to "<span>Edit Properties</span>".html_safe,
69
+ [:edit, :cms, @page],
70
+ :id => "edit_properties_button",
71
+ :class => "spacer button#{ ' disabled' unless current_user.able_to_edit?(@page) }",
72
+ :target => "_top" %>
73
+
74
+ <%= link_to "<span>List Versions</span>".html_safe,
75
+ versions_cms_page_path(@page),
76
+ :class => "spacer button#{ ' disabled' unless current_user.able_to_edit?(@page) }",
77
+ :target => "_top" %>
78
+
79
+ <%= able_to? :publish_content do %>
80
+ <% if @page.draft_version? %>
81
+ <%= link_to "<span><span class=\"delete_img\">&nbsp;</span>Delete</span>".html_safe,
82
+ [:cms, @page],
83
+ :id => "delete_button",
84
+ :title => "Are you sure you want to delete '#{@page.name}'?",
85
+ :target => "_top",
86
+ :class => "spacer button confirm_with_title http_delete#{ ' disabled' unless current_user.able_to_publish?(@page) }" %>
87
+ <% else %>
88
+ <%= link_to "<span>Revert to this Version</span>".html_safe,
89
+ revert_to_cms_page_path(@page, @page.version),
90
+ :id => "revert_button",
91
+ :class => "button http_put",
92
+ :target => "_top" %>
93
+ <% end %>
94
+ <% end %>
95
+ <%= render :partial => "bcms_mobile/mobile_toggle" %>
96
+ <div id="visual_editor_toggle">
97
+ <% if @page.version == @page.draft.version %>
98
+ <div class="visual_editor_label">Visual Editor:</div>
99
+ <div class="visual_editor_value_container">
100
+ <% if @mode == "edit" %>
101
+ <div>
102
+ <span id="visual_editor_state"<%= ' title="You don\'t have permission to edit this page"' unless current_user.able_to_edit?(@page) %>>ON<%= '*' unless current_user.able_to_edit?(@page) %></span>
103
+ </div>
104
+ <% else %>
105
+ <div><span id="visual_editor_state">OFF</span></div>
106
+ <% end %>
107
+ </div>
108
+ <div class="visual_editor_toggle_container">
109
+ <% if @mode == "edit" %>
110
+ <div class="sm_button"><%= link_to '<span id="visual_editor_action">TURN OFF</span>'.html_safe, url_with_mode(request.referrer, "view"), :target => "_top", :class => "sm_button" %></div>
111
+ <% else %>
112
+ <div class="sm_button"><%= link_to '<span id="visual_editor_action">TURN ON</span>'.html_safe, url_with_mode(request.referrer, "edit"), :target => "_top", :class => "sm_button" %></div>
113
+ <% end %>
114
+ </div>
115
+ <% else %>
116
+ </div>
117
+ <%= link_to("<span>View Current Version</span>".html_safe, @page.path, :class => "button current_version", :target => "_top") %>
118
+ <% end %>
119
+ </div>
120
+ </div>
121
+ <% end %>
@@ -0,0 +1,94 @@
1
+ class Browsercms315 < ActiveRecord::Migration
2
+ def self.up
3
+ generate_ancestry_from_section_id
4
+ update_latest_version_cache
5
+
6
+ INDEXES.each do |index|
7
+ add_index *index
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ # This migration is not reversible since it removes the original section_id column.
13
+ end
14
+
15
+ # Add some very commonly used indexes to improve the site performance as the # of pages/content grows (i.e. several thousand pages)
16
+ INDEXES = [
17
+ [:pages, :deleted],
18
+ [:pages, :path],
19
+ [:pages, :version],
20
+ [:page_versions, :page_id],
21
+ [:groups, :code],
22
+ [:groups, :group_type_id],
23
+ [:group_types, :cms_access],
24
+ [:group_sections, :section_id],
25
+ [:group_sections, :group_id],
26
+ [:users, :expires_at],
27
+ [:user_group_memberships, :group_id],
28
+ [:user_group_memberships, :user_id],
29
+ [:group_permissions, :group_id],
30
+ [:group_permissions, :permission_id],
31
+ [:group_permissions, [:group_id, :permission_id]],
32
+ [:section_nodes, :node_type],
33
+ [:section_nodes, :ancestry],
34
+ [:connectors, :page_id],
35
+ [:connectors, :page_version],
36
+ [:html_blocks, :deleted],
37
+ [:html_block_versions, :html_block_id],
38
+ [:html_block_versions, :version],
39
+ [:portlet_attributes, :portlet_id],
40
+ [:portlets, :name],
41
+ [:sections, :path],
42
+ [:redirects, :from_path],
43
+ [:connectors, :connectable_version],
44
+ [:connectors, :connectable_type],
45
+ [:content_types, :content_type_group_id],
46
+ [:content_types, :name],
47
+ [:file_block_versions, :file_block_id],
48
+ [:file_block_versions, :version],
49
+ [:file_blocks, :deleted],
50
+ [:file_blocks, :type],
51
+ [:attachment_versions, :attachment_id],
52
+ [:tasks, :page_id],
53
+ [:tasks, :completed_at],
54
+ [:tasks, :assigned_to_id],
55
+ ]
56
+
57
+ private
58
+
59
+ # v3.1.5 uses Ancestry to manage the parent child relationship between sections and their children.
60
+ # This converts the data from the old section_id to use the ancestry column.
61
+ def self.generate_ancestry_from_section_id
62
+ add_column :section_nodes, :ancestry, :string
63
+ add_column :section_nodes, :temp_parent_id, :integer
64
+
65
+ SectionNode.reset_column_information
66
+ root_section = Section.root.first
67
+ SectionNode.create!(:node => root_section) if root_section
68
+
69
+ all_nodes_but_root = SectionNode.find(:all, :conditions=>["section_id IS NOT NULL"])
70
+ all_nodes_but_root.each do |sn|
71
+ parent_node = SectionNode.find(:first, :conditions => ["node_id = ? and node_type = 'Section'", sn.section_id])
72
+ sn.temp_parent_id = parent_node.id
73
+ sn.save!
74
+ end
75
+ rename_column :section_nodes, :temp_parent_id, :parent_id # Ancestry works off the 'parent_id' column.
76
+
77
+ SectionNode.build_ancestry_from_parent_ids!
78
+ remove_column :section_nodes, :section_id
79
+ remove_column :section_nodes, :parent_id
80
+ SectionNode.reset_column_information
81
+ end
82
+
83
+ # Adds a 'latest_version' pointer to pages and links. Greatly reduces the number of queries the sitemap requires to determine if pages are in draft/published mode
84
+ def self.update_latest_version_cache
85
+ add_column :pages, :latest_version, :integer
86
+ add_column :links, :latest_version, :integer
87
+ Page.all.each do |p|
88
+ p.update_latest_version
89
+ end
90
+ Link.all.each do |link|
91
+ link.update_latest_version
92
+ end
93
+ end
94
+ end