spontaneous 0.2.0.beta5 → 0.2.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +39 -0
  4. data/Gemfile +2 -0
  5. data/Readme.markdown +4 -4
  6. data/application/css/core.css.scss +144 -43
  7. data/application/css/definitions.css.scss +50 -16
  8. data/application/css/dialogue.css.scss +5 -2
  9. data/application/css/editing.css.scss +7 -7
  10. data/application/css/font.css.scss +1 -1
  11. data/application/css/meta.css.scss +6 -6
  12. data/application/css/popover.css.scss +6 -6
  13. data/application/css/top.css.scss +8 -1
  14. data/application/js/add_alias_dialogue.js +137 -36
  15. data/application/js/add_home_dialogue.js +10 -10
  16. data/application/js/ajax.js +26 -26
  17. data/application/js/authentication.js +2 -2
  18. data/application/js/box.js +21 -10
  19. data/application/js/box_container.js +13 -7
  20. data/application/js/compatibility.js +19 -17
  21. data/application/js/conflicted_field_dialogue.js +5 -5
  22. data/application/js/content.js +22 -16
  23. data/application/js/content_area.js +62 -33
  24. data/application/js/dialogue.js +16 -16
  25. data/application/js/dom.js +9 -10
  26. data/application/js/edit_panel.js +25 -20
  27. data/application/js/editing.js +21 -8
  28. data/application/js/entry.js +1 -1
  29. data/application/js/extensions.js +11 -11
  30. data/application/js/field/boolean.js +6 -6
  31. data/application/js/field/date.js +1 -1
  32. data/application/js/field/file.js +17 -17
  33. data/application/js/field/image.js +27 -27
  34. data/application/js/field/markdown.js +72 -71
  35. data/application/js/field/select.js +9 -9
  36. data/application/js/field/string.js +3 -3
  37. data/application/js/field/webvideo.js +2 -2
  38. data/application/js/field_preview.js +3 -0
  39. data/application/js/init.js +3 -2
  40. data/application/js/jquery-selection-position.js +13 -13
  41. data/application/js/location.js +17 -12
  42. data/application/js/login.js +2 -2
  43. data/application/js/meta_view/user_admin.js +101 -101
  44. data/application/js/metadata.js +1 -1
  45. data/application/js/page.js +2 -2
  46. data/application/js/page_browser.js +13 -13
  47. data/application/js/page_entry.js +1 -1
  48. data/application/js/panel/root_menu.js +10 -10
  49. data/application/js/popover.js +6 -5
  50. data/application/js/popover_view.js +5 -5
  51. data/application/js/preview.js +10 -4
  52. data/application/js/progress.js +6 -6
  53. data/application/js/properties.js +35 -6
  54. data/application/js/publish.js +43 -43
  55. data/application/js/require.js +14 -14
  56. data/application/js/services.js +3 -3
  57. data/application/js/sharded_upload.js +9 -8
  58. data/application/js/side_bar.js +5 -5
  59. data/application/js/state.js +2 -2
  60. data/application/js/status_bar.js +6 -6
  61. data/application/js/top_bar.js +97 -65
  62. data/application/js/types.js +9 -6
  63. data/application/js/upload.js +4 -4
  64. data/application/js/upload_manager.js +21 -21
  65. data/application/js/user.js +1 -1
  66. data/application/js/vendor/jquery.velocity.min.js +7 -0
  67. data/application/js/views.js +32 -8
  68. data/application/js/views/box_view.js +51 -31
  69. data/application/js/views/page_piece_view.js +17 -15
  70. data/application/js/views/page_view.js +54 -43
  71. data/application/js/views/piece_view.js +44 -37
  72. data/application/static/font/fontawesome-webfont-4f0022f25672c7f501c339cbf98d9117.ttf +0 -0
  73. data/application/views/index.erb +1 -0
  74. data/db/migrations/20130114120000_create_revision_tables.rb +2 -1
  75. data/db/migrations/20130813111009_increase_path_length.rb +11 -2
  76. data/db/migrations/20140506171823_add_index_to_target_id.rb +11 -0
  77. data/db/migrations/20140514090204_add_content_hash.rb +59 -0
  78. data/db/migrations/20140519150253_add_content_hash_timestamp.rb +20 -0
  79. data/lib/spontaneous.rb +0 -1
  80. data/lib/spontaneous/asset/environment.rb +77 -15
  81. data/lib/spontaneous/box.rb +21 -0
  82. data/lib/spontaneous/capistrano/deploy.rb +1 -1
  83. data/lib/spontaneous/capistrano/sync.rb +8 -7
  84. data/lib/spontaneous/change.rb +4 -2
  85. data/lib/spontaneous/cli/fields.rb +7 -3
  86. data/lib/spontaneous/cli/generate.rb +2 -0
  87. data/lib/spontaneous/cli/init.rb +24 -93
  88. data/lib/spontaneous/cli/init/db.rb +94 -0
  89. data/lib/spontaneous/cli/init/mysql.rb +17 -0
  90. data/lib/spontaneous/cli/init/postgresql.rb +33 -0
  91. data/lib/spontaneous/cli/init/sqlite.rb +14 -0
  92. data/lib/spontaneous/cli/site.rb +45 -20
  93. data/lib/spontaneous/collections/box_set.rb +3 -0
  94. data/lib/spontaneous/collections/entry_set.rb +43 -4
  95. data/lib/spontaneous/collections/field_set.rb +14 -2
  96. data/lib/spontaneous/data_mapper.rb +40 -7
  97. data/lib/spontaneous/data_mapper/content_model.rb +1 -1
  98. data/lib/spontaneous/data_mapper/content_model/associations.rb +63 -12
  99. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +9 -14
  100. data/lib/spontaneous/data_mapper/content_table.rb +4 -2
  101. data/lib/spontaneous/data_mapper/dataset.rb +31 -2
  102. data/lib/spontaneous/data_mapper/scope.rb +37 -20
  103. data/lib/spontaneous/errors.rb +6 -0
  104. data/lib/spontaneous/facet.rb +20 -10
  105. data/lib/spontaneous/field/base.rb +8 -1
  106. data/lib/spontaneous/field/file.rb +28 -3
  107. data/lib/spontaneous/field/image.rb +2 -0
  108. data/lib/spontaneous/field/update.rb +6 -0
  109. data/lib/spontaneous/field/webvideo/vimeo.rb +6 -1
  110. data/lib/spontaneous/field/webvideo/vine.rb +1 -1
  111. data/lib/spontaneous/field/webvideo/youtube.rb +1 -1
  112. data/lib/spontaneous/generators/site.rb +6 -4
  113. data/lib/spontaneous/generators/site/.gitignore +1 -0
  114. data/lib/spontaneous/generators/site/Gemfile.tt +3 -3
  115. data/lib/spontaneous/generators/site/config/{indexes.rb.tt → initializers/indexes.rb.tt} +0 -0
  116. data/lib/spontaneous/generators/site/config/initializers/publishing.rb.tt +78 -0
  117. data/lib/spontaneous/generators/site/{config/database.yml.tt → db/mysql2.yml.tt} +7 -6
  118. data/lib/spontaneous/generators/site/db/postgres.yml.tt +25 -0
  119. data/lib/spontaneous/generators/site/db/sqlite3.yml.tt +18 -0
  120. data/lib/spontaneous/generators/site/public/humans.txt.tt +14 -0
  121. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +51 -0
  122. data/lib/spontaneous/loader.rb +1 -1
  123. data/lib/spontaneous/logger.rb +1 -1
  124. data/lib/spontaneous/media/image/optimizer.rb +1 -1
  125. data/lib/spontaneous/media/image/processor.rb +11 -2
  126. data/lib/spontaneous/media/image/renderable.rb +2 -0
  127. data/lib/spontaneous/model.rb +3 -0
  128. data/lib/spontaneous/model/box/allowed_types.rb +17 -4
  129. data/lib/spontaneous/model/core.rb +36 -3
  130. data/lib/spontaneous/model/core/aliases.rb +5 -2
  131. data/lib/spontaneous/model/core/boxes.rb +6 -0
  132. data/lib/spontaneous/model/core/cascading_change.rb +38 -0
  133. data/lib/spontaneous/model/core/content_hash.rb +171 -0
  134. data/lib/spontaneous/model/core/entries.rb +0 -19
  135. data/lib/spontaneous/model/core/fields.rb +11 -0
  136. data/lib/spontaneous/model/core/modifications.rb +22 -21
  137. data/lib/spontaneous/model/core/render.rb +3 -0
  138. data/lib/spontaneous/model/core/serialisation.rb +18 -17
  139. data/lib/spontaneous/model/page.rb +35 -8
  140. data/lib/spontaneous/model/page/page_tree.rb +20 -8
  141. data/lib/spontaneous/model/page/paths.rb +79 -50
  142. data/lib/spontaneous/model/page/singleton.rb +71 -0
  143. data/lib/spontaneous/model/page/site_map.rb +2 -1
  144. data/lib/spontaneous/model/page/site_timestamps.rb +2 -2
  145. data/lib/spontaneous/model/piece.rb +10 -0
  146. data/lib/spontaneous/output/context.rb +13 -6
  147. data/lib/spontaneous/output/format.rb +30 -5
  148. data/lib/spontaneous/output/helpers/script_helper.rb +8 -0
  149. data/lib/spontaneous/output/helpers/stylesheet_helper.rb +7 -0
  150. data/lib/spontaneous/output/renderable.rb +16 -0
  151. data/lib/spontaneous/output/store.rb +1 -1
  152. data/lib/spontaneous/output/template/renderer.rb +2 -2
  153. data/lib/spontaneous/page_piece.rb +25 -1
  154. data/lib/spontaneous/prototypes/box_prototype.rb +13 -0
  155. data/lib/spontaneous/prototypes/field_prototype.rb +7 -4
  156. data/lib/spontaneous/publishing.rb +10 -5
  157. data/lib/spontaneous/publishing/immediate.rb +32 -349
  158. data/lib/spontaneous/publishing/pipeline.rb +43 -0
  159. data/lib/spontaneous/publishing/progress.rb +186 -0
  160. data/lib/spontaneous/publishing/publish.rb +107 -0
  161. data/lib/spontaneous/publishing/rerender.rb +17 -0
  162. data/lib/spontaneous/publishing/revision.rb +53 -18
  163. data/lib/spontaneous/publishing/simultaneous.rb +1 -1
  164. data/lib/spontaneous/publishing/steps.rb +154 -0
  165. data/lib/spontaneous/publishing/steps/activate_revision.rb +45 -0
  166. data/lib/spontaneous/publishing/steps/archive_old_revisions.rb +22 -0
  167. data/lib/spontaneous/publishing/steps/base_step.rb +49 -0
  168. data/lib/spontaneous/publishing/steps/copy_static_files.rb +74 -0
  169. data/lib/spontaneous/publishing/steps/create_revision_directory.rb +24 -0
  170. data/lib/spontaneous/publishing/steps/generate_rackup_file.rb +51 -0
  171. data/lib/spontaneous/publishing/steps/generate_search_indexes.rb +24 -0
  172. data/lib/spontaneous/publishing/steps/render_revision.rb +69 -0
  173. data/lib/spontaneous/publishing/steps/write_revision_file.rb +43 -0
  174. data/lib/spontaneous/rack/back.rb +3 -1
  175. data/lib/spontaneous/rack/back/alias.rb +9 -8
  176. data/lib/spontaneous/rack/front.rb +1 -1
  177. data/lib/spontaneous/rack/middleware.rb +7 -4
  178. data/lib/spontaneous/rack/middleware/transaction.rb +14 -0
  179. data/lib/spontaneous/rack/page_controller.rb +23 -8
  180. data/lib/spontaneous/revision.rb +5 -10
  181. data/lib/spontaneous/schema.rb +5 -0
  182. data/lib/spontaneous/server.rb +3 -1
  183. data/lib/spontaneous/site.rb +17 -10
  184. data/lib/spontaneous/site/publishing.rb +25 -3
  185. data/lib/spontaneous/site/state.rb +7 -3
  186. data/lib/spontaneous/tasks/database.rake +5 -10
  187. data/lib/spontaneous/utils/database/mysql_dumper.rb +5 -1
  188. data/lib/spontaneous/version.rb +1 -1
  189. data/spontaneous.gemspec +4 -3
  190. data/test/fixtures/example_application/config/initializers/initializer1.rb +1 -0
  191. data/test/fixtures/example_application/config/initializers/initializer2.rb +1 -0
  192. data/test/fixtures/example_application/config/initializers/publishing.rb +13 -0
  193. data/test/fixtures/search/config/{indexes.rb → initializers/indexes.rb} +0 -0
  194. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -4
  195. data/test/functional/test_application.rb +10 -0
  196. data/test/functional/test_back.rb +23 -5
  197. data/test/functional/test_cli.rb +98 -34
  198. data/test/functional/test_front.rb +7 -3
  199. data/test/test_helper.rb +35 -28
  200. data/test/unit/test_alias.rb +20 -3
  201. data/test/unit/test_assets.rb +58 -30
  202. data/test/unit/test_changesets.rb +20 -12
  203. data/test/unit/test_content_hash.rb +496 -0
  204. data/test/unit/test_context.rb +28 -1
  205. data/test/unit/test_controllers.rb +96 -61
  206. data/test/unit/test_crypt.rb +1 -8
  207. data/test/unit/test_datamapper.rb +95 -19
  208. data/test/unit/test_features.rb +1 -4
  209. data/test/unit/test_fields.rb +61 -12
  210. data/test/unit/test_generators.rb +39 -2
  211. data/test/unit/test_images.rb +3 -1
  212. data/test/unit/test_modifications.rb +224 -219
  213. data/test/unit/test_output_store.rb +10 -0
  214. data/test/unit/{test_formats.rb → test_outputs.rb} +75 -6
  215. data/test/unit/test_page.rb +61 -15
  216. data/test/unit/test_plugins.rb +2 -42
  217. data/test/unit/test_publishing_pipeline.rb +1050 -0
  218. data/test/unit/test_render.rb +30 -0
  219. data/test/unit/test_revisions.rb +110 -2
  220. data/test/unit/test_schema.rb +4 -0
  221. data/test/unit/test_search.rb +1 -1
  222. data/test/unit/test_serialisation.rb +6 -1
  223. data/test/unit/test_singletons.rb +159 -0
  224. data/test/unit/test_site.rb +71 -44
  225. metadata +140 -86
  226. data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
  227. data/test/unit/test_publishing.rb +0 -330
@@ -0,0 +1,186 @@
1
+ require 'logger'
2
+ require 'delegate'
3
+ require 'simultaneous'
4
+
5
+ module Spontaneous::Publishing
6
+ module Progress
7
+ class Duration < DelegateClass(Float)
8
+ def to_s
9
+ d = self.to_f
10
+ h, r = _factor(d, 3600)
11
+ m, _ = _factor(r, 60)
12
+ s = (d - (h*3600 + m * 60)).round(2)
13
+ "%02dh %02dm %02.2fs" % [h, m,s]
14
+ end
15
+
16
+ def _factor(d, f)
17
+ [d.to_i/f, d.to_i%f]
18
+ end
19
+ end
20
+
21
+ def self.registered
22
+ @registered ||= {}
23
+ end
24
+
25
+ class Progress
26
+ def self.register(klass, *names)
27
+ names.each do |name|
28
+ Spontaneous::Publishing::Progress.registered[name] = klass
29
+ end
30
+ end
31
+ end
32
+
33
+ class Silent < Progress
34
+ attr_reader :total, :stage
35
+
36
+ register self, :silent, :none
37
+
38
+ def initialize
39
+ @total = 0
40
+ @position = 0
41
+ @stage = ""
42
+ @start = Time.now
43
+ end
44
+
45
+ def start(total_steps)
46
+ @total = total_steps
47
+ end
48
+
49
+ def stage(name)
50
+ @stage = name
51
+ end
52
+
53
+ def current_stage
54
+ @stage
55
+ end
56
+
57
+ def step(n = 1, msg = "")
58
+ @position += n
59
+ end
60
+
61
+ def log(message)
62
+ end
63
+
64
+ def error(exception)
65
+ end
66
+
67
+ def done
68
+ end
69
+
70
+ def percentage
71
+ ((@position.to_f / @total.to_f) * 100).round(2)
72
+ end
73
+
74
+ def position
75
+ @position
76
+ end
77
+
78
+ def duration
79
+ Duration.new(Time.now - @start)
80
+ end
81
+ end
82
+
83
+ class Log < Silent
84
+ register self, :log
85
+
86
+ def initialize(io = $stdout, label = "Publish")
87
+ super()
88
+ # don't call close on stdout or stderr
89
+ @closable = !((io == STDOUT) || (io == STDERR))
90
+ @logger = Logger.new(io, File::APPEND)
91
+ @logger.formatter = proc do |severity, datetime, progname, msg|
92
+ pct = ("%03.2f" % [percentage]).rjust(6, " ")
93
+ "#{label}:#{severity}: [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%3N')}] #{duration} #{pct}% #{current_stage} #{msg}\n"
94
+ end
95
+ end
96
+
97
+ def log(message)
98
+ super
99
+ logger.info(message)
100
+ end
101
+
102
+ def step(n = 1, msg = "")
103
+ super
104
+ @logger.info("#{msg}")
105
+ end
106
+
107
+ def error(exception)
108
+ super
109
+ msg = [exception.to_s].concat(exception.backtrace).join("\n")
110
+ @logger.error(msg)
111
+ end
112
+
113
+ def done
114
+ @logger.close if @closable
115
+ end
116
+ end
117
+
118
+ class Stdout < Log
119
+ register self, :stdout
120
+
121
+ def initialize
122
+ super($stdout)
123
+ end
124
+ end
125
+
126
+ class Simultaneous < Silent
127
+ register self, :simultaneous, :browser
128
+
129
+ def stage(name)
130
+ super
131
+ send_event
132
+ end
133
+
134
+ def step(n = 1, msg = "")
135
+ super
136
+ send_event
137
+ end
138
+
139
+ def send_event(stage = current_stage, percentage = percentage)
140
+ ::Simultaneous.send_event('publish_progress', {:state => stage, :progress => percentage}.to_json)
141
+ rescue Errno::ECONNREFUSED
142
+ rescue Errno::ENOENT
143
+ end
144
+
145
+ def error(exception)
146
+ super
147
+ send_event("aborting", "*")
148
+ end
149
+
150
+ def done
151
+ super
152
+ send_event("complete", "*")
153
+ end
154
+ end
155
+
156
+ class Multi < Progress
157
+ def initialize(*outputs)
158
+ @outputs = outputs
159
+ end
160
+
161
+ def log(message)
162
+ @outputs.each { |progress| progress.log(message) }
163
+ end
164
+
165
+ def start(total_steps)
166
+ @outputs.each { |progress| progress.start(total_steps) }
167
+ end
168
+
169
+ def stage(name)
170
+ @outputs.each { |progress| progress.stage(name) }
171
+ end
172
+
173
+ def step(n = 1, msg = "")
174
+ @outputs.each { |progress| progress.step(n, msg) }
175
+ end
176
+
177
+ def error(exception)
178
+ @outputs.each { |progress| progress.error(exception) }
179
+ end
180
+
181
+ def done
182
+ @outputs.each { |progress| progress.done }
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,107 @@
1
+
2
+ module Spontaneous::Publishing
3
+ class Publish
4
+ attr_reader :site, :revision, :actions
5
+
6
+ def initialize(site, revision, actions)
7
+ @site, @revision, @actions = site, revision, actions
8
+ end
9
+
10
+ def publish_pages(modified_pages)
11
+ pages = normalise_page_list(modified_pages)
12
+ if all_pages?(pages) || all_modified_pages?(pages)
13
+ publish_all
14
+ else
15
+ pages = Spontaneous::Change.include_dependencies(pages)
16
+ publish(pages)
17
+ end
18
+ end
19
+
20
+ def publish_all
21
+ publish(nil)
22
+ end
23
+
24
+ def publish(pages)
25
+ model.database.transaction do
26
+ publish!(pages)
27
+ end
28
+ rescue Exception => e
29
+ abort_publish(e)
30
+ raise
31
+ end
32
+
33
+ def publish!(pages)
34
+ start_publish
35
+ model.publish(revision, pages) do
36
+ run_pipeline(pages)
37
+ end
38
+ finish_publish
39
+ end
40
+
41
+ def run_pipeline(pages)
42
+ model.scope(revision, true) do
43
+ run_pipeline!(pages)
44
+ end
45
+ end
46
+
47
+ def run_pipeline!(pages)
48
+ pages ||= all_unpublished_pages
49
+ pipeline.run(site, revision, pages, progress)
50
+ end
51
+
52
+ def pipeline
53
+ @pipeline ||= Pipeline.new(actions.steps)
54
+ end
55
+
56
+ def start_publish
57
+ progress.log("Publishing revision #{revision}")
58
+ # when working with multiple instances it's possible to rollback the revision number
59
+ # leaving behind old revisions > the current published_revision.
60
+ model.delete_revision(revision)
61
+ site.send(:pending_revision=, revision)
62
+ end
63
+
64
+ def finish_publish
65
+ S::PublishedRevision.create(:revision => revision, :published_at => Time.now)
66
+ site.send(:pending_revision=, nil)
67
+ site.must_publish_all!(false)
68
+ progress.done
69
+ end
70
+
71
+ def abort_publish(e)
72
+ S::PublishedRevision.filter(:revision => revision).delete
73
+ site.send(:pending_revision=, nil)
74
+ progress.error(e)
75
+ end
76
+
77
+ def model
78
+ @site.model
79
+ end
80
+
81
+ def progress
82
+ @progress ||= Progress::Multi.new(*actions.progress)
83
+ end
84
+
85
+ def normalise_page_list(pages)
86
+ pages = pages.flatten.map { |c|
87
+ c.is_a?(model::Page) ? c.reload : model::Page[c]
88
+ }
89
+ end
90
+
91
+ def all_unpublished_pages
92
+ @all_unpublished_pages ||= Spontaneous::Change.unpublished_pages(@site)
93
+ end
94
+
95
+ def all_pages
96
+ site.pages
97
+ end
98
+
99
+ def all_pages?(pages)
100
+ (all_pages - pages).empty?
101
+ end
102
+
103
+ def all_modified_pages?(pages)
104
+ (all_unpublished_pages - pages).empty?
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,17 @@
1
+ module Spontaneous::Publishing
2
+ class Rerender < Publish
3
+ def initialize(site, revision, actions)
4
+ @site, @revision, @actions = site, revision, actions
5
+ end
6
+
7
+ def rerender
8
+ model.scope(revision, true) do
9
+ pipeline.run(site, revision, [], progress)
10
+ end
11
+ end
12
+
13
+ def progress
14
+ @progress ||= Progress::Stdout.new
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,31 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Spontaneous::Publishing
4
+ def self.create_content_table(db, source_table, dest_table_name)
5
+ # sqlite doesn't like it if you create a table with no columns
6
+ # so hard-code the id column (but don't make it a pk because the
7
+ # unique constraint isn't useful at this stage)
8
+ schema = db.schema(source_table).dup.delete_if { |col, opts| col == :id }
9
+ db.create_table(dest_table_name) do
10
+ integer :id
11
+ end
12
+ db.alter_table(dest_table_name) do
13
+ schema.each do |column, column_opts|
14
+ opts = column_opts.dup
15
+ type = opts.delete(:db_type)
16
+ case column
17
+ when :id
18
+ opts.delete(:default)
19
+ end
20
+ add_column column, type#, opts
21
+ end
22
+ end
23
+ nil
24
+ rescue => e
25
+ db.drop_table(dest_table_name) rescue nil
26
+ raise
27
+ end
28
+
4
29
  class Revision
5
30
  class InvalidRevision < Spontaneous::Error; end
6
31
 
@@ -23,24 +48,24 @@ module Spontaneous::Publishing
23
48
  sync_revision
24
49
  set_revision_timestamps
25
50
  set_revision_version
51
+ set_revision_content_hash
26
52
  @revision.complete
27
53
  @revision.scope do
28
54
  yield if block_given?
29
55
  end
30
56
  set_source_timestamps
31
- rescue => e
57
+ set_source_content_hash
58
+ rescue Exception => e # Want to catch everything, including the "uncatchable"
32
59
  @revision.delete
33
- raise e
60
+ raise
34
61
  end
35
62
  end
36
63
 
37
64
  protected
38
65
 
39
66
  def create_revision
40
- db.run(<<-SQL)
41
- CREATE TABLE #{db.literal(@revision.table)}
42
- AS #{source_dataset.select_sql}
43
- SQL
67
+ Spontaneous::Publishing.create_content_table(db, source_dataset.first_source, @revision.table)
68
+ @revision.copy_dataset(source_dataset, @revision.table)
44
69
  end
45
70
 
46
71
  def source_dataset
@@ -48,6 +73,8 @@ module Spontaneous::Publishing
48
73
  end
49
74
 
50
75
  def copy_indexes
76
+ pk = @revision.model.primary_key
77
+ db.add_index(@revision.table, Array(pk), unique: true)
51
78
  indexes = db.indexes(@revision.content_table)
52
79
  indexes.each do |name, options|
53
80
  columns = options.delete(:columns)
@@ -59,6 +86,18 @@ module Spontaneous::Publishing
59
86
  # To be overwritten in Patch subclass
60
87
  end
61
88
 
89
+ def set_source_content_hash
90
+ set_content_hash(@revision.content_dataset)
91
+ end
92
+
93
+ def set_revision_content_hash
94
+ set_content_hash(@revision.dataset)
95
+ end
96
+
97
+ def set_content_hash(dataset)
98
+ filter_dataset(dataset).update(published_content_hash: :content_hash, content_hash_changed: false)
99
+ end
100
+
62
101
  def set_revision_timestamps
63
102
  set_timestamps(@revision.dataset)
64
103
  end
@@ -83,11 +122,11 @@ module Spontaneous::Publishing
83
122
  end
84
123
 
85
124
  def published_dataset(ds)
86
- ds
125
+ filter_dataset(ds)
87
126
  end
88
127
 
89
128
  def first_published_dataset(ds)
90
- ds.filter(:first_published_at => nil)
129
+ filter_dataset(ds.filter(:first_published_at => nil))
91
130
  end
92
131
 
93
132
  def set_revision_version
@@ -105,6 +144,10 @@ module Spontaneous::Publishing
105
144
  def revision
106
145
  @revision.revision
107
146
  end
147
+
148
+ def filter_dataset(ds)
149
+ ds
150
+ end
108
151
  end
109
152
 
110
153
  class Patcher < Generator
@@ -126,15 +169,7 @@ module Spontaneous::Publishing
126
169
  end
127
170
  end
128
171
 
129
- def published_dataset(ds)
130
- filter_ids(super)
131
- end
132
-
133
- def first_published_dataset(ds)
134
- filter_ids(super)
135
- end
136
-
137
- def filter_ids(ds)
172
+ def filter_dataset(ds)
138
173
  ds.filter(:id => @modified.map(&:id))
139
174
  end
140
175
  end
@@ -211,7 +246,7 @@ module Spontaneous::Publishing
211
246
  model.mapper.revision_table?(table)
212
247
  end
213
248
 
214
- attr_reader :revision
249
+ attr_reader :model, :revision
215
250
 
216
251
  def initialize(model, revision)
217
252
  @model, @revision = model, revision