alchemy_cms 3.6.1 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8743fb03c7e20c7e5843e13f70a7a15b0b6d3c0
4
- data.tar.gz: 5edc6d41f2f0931328f8d1f62d9391f1f0096a33
3
+ metadata.gz: aa89fac8ccee2fe3971a90fa2674a8f6e25f81df
4
+ data.tar.gz: a8179705ad6aedbaafb0910ddb22cfee157025c7
5
5
  SHA512:
6
- metadata.gz: c9edf891ac572e4114b897991df000622ba4703119bc01b9752859ffb8c4ef31130c9c84930605b5bbc8eacc4fdc60d0fd2d155233a3036e081a9a013744db10
7
- data.tar.gz: a850e8c5eee3b9f8def3d21201477eaef9217b54937fa3717e8750310c86fe99aade5ed7f72ce9998a08af7c2b1b4b4666d620387bb579a27744859b58a19aa7
6
+ metadata.gz: df863653927ec799671903857aea93c53ab3ebd2194eebf1f0cc045c4c64a1acb64715339c6a5e8a416bad84af6f4e3328fb097265737975a4c9d00bac5e6209
7
+ data.tar.gz: 04b9ec7edeafae429eeb55c40059870e84f36e711e5fbe9d3470875b21374f1c65135ec82ccb25be9b2680ebe366bda5c039df758d58494ff397695472e813a3
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.6.2 (2017-09-01)
4
+
5
+ * Handle custom errors in `Alchemy::Picture#url` [#1305](https://github.com/AlchemyCMS/alchemy_cms/pull/1305) by [tvdeyen](https://github.com/tvdeyen)
6
+ * Do not move elements in tidy cells task [#1303](https://github.com/AlchemyCMS/alchemy_cms/pull/1303) by [tvdeyen](https://github.com/tvdeyen)
7
+ * Add a store image file format rake task [#1302](https://github.com/AlchemyCMS/alchemy_cms/pull/1302) by [tvdeyen](https://github.com/tvdeyen)
8
+
3
9
  ## 3.6.1 (2017-08-16)
4
10
 
5
11
  * Do not ask `systempage?` everytime we load the page definition [#1239](https://github.com/AlchemyCMS/alchemy_cms/pull/1283) by [tvdeyen](https://github.com/tvdeyen)
@@ -1,5 +1,7 @@
1
1
  module Alchemy
2
2
  module Picture::Url
3
+ include Alchemy::Logger
4
+
3
5
  TRANSFORMATION_OPTIONS = [
4
6
  :crop,
5
7
  :crop_from,
@@ -28,6 +30,9 @@ module Alchemy
28
30
  image = encoded_image(image, options)
29
31
 
30
32
  image.url(options.except(*TRANSFORMATION_OPTIONS).merge(name: name))
33
+ rescue MissingImageFileError, WrongImageFormatError => e
34
+ log_warning e.message
35
+ nil
31
36
  end
32
37
 
33
38
  private
@@ -53,7 +58,10 @@ module Alchemy
53
58
  #
54
59
  def encoded_image(image, options = {})
55
60
  target_format = options[:format] || default_render_format
56
- raise WrongImageFormatError if !target_format.in?(Alchemy::Picture.allowed_filetypes)
61
+
62
+ unless target_format.in?(Alchemy::Picture.allowed_filetypes)
63
+ raise WrongImageFormatError.new(self, target_format)
64
+ end
57
65
 
58
66
  options = {
59
67
  flatten: target_format != 'gif' && image_file_format == 'gif'
@@ -1,18 +1,6 @@
1
1
  class AddImageFileFormatToAlchemyPictures < ActiveRecord::Migration
2
2
  def up
3
3
  add_column :alchemy_pictures, :image_file_format, :string
4
-
5
- say_with_time "Storing file format of existing pictures" do
6
- Alchemy::Picture.all.each do |pic|
7
- begin
8
- format = pic.image_file.identify('-ping -format "%m"')
9
- pic.update_column('image_file_format', format.to_s.chomp.downcase)
10
- rescue Dragonfly::Job::Fetch::NotFound => e
11
- say(e.message, true)
12
- end
13
- end
14
- Alchemy::Picture.count
15
- end
16
4
  end
17
5
 
18
6
  def down
@@ -55,9 +55,14 @@ module Alchemy
55
55
 
56
56
  # Raised if calling +image_file+ on a Picture object returns nil.
57
57
  class WrongImageFormatError < StandardError
58
+ def initialize(image, requested_format)
59
+ @image = image
60
+ @requested_format = requested_format
61
+ end
62
+
58
63
  def message
59
64
  allowed_filetypes = Alchemy::Picture.allowed_filetypes.map(&:upcase).to_sentence
60
- "Requested image format is not one of allowed filetypes (#{allowed_filetypes})."
65
+ "Requested image format (#{@requested_format.inspect}) for #{@image.inspect} is not one of allowed filetypes (#{allowed_filetypes})."
61
66
  end
62
67
  end
63
68
 
@@ -7,7 +7,7 @@ module Alchemy
7
7
  end
8
8
 
9
9
  def log_warning(message)
10
- Alchemy::Logger.warn(message, caller(0..0))
10
+ Alchemy::Logger.warn(message, caller(1..1))
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,130 @@
1
+ require 'alchemy/shell'
2
+
3
+ module Alchemy
4
+ class Tidy
5
+ extend Shell
6
+
7
+ class << self
8
+ def create_missing_cells(page_layouts, cells)
9
+ page_layouts.each do |layout|
10
+ next if layout['cells'].blank?
11
+ cells_for_layout = cells.select { |cell| layout['cells'].include? cell['name'] }
12
+ Alchemy::Page.where(page_layout: layout['name']).each do |page|
13
+ cells_for_layout.each do |cell_for_layout|
14
+ cell = Alchemy::Cell.find_or_initialize_by(name: cell_for_layout['name'], page_id: page.id)
15
+ if cell.new_record?
16
+ log "Creating cell #{cell.name} for page #{page.name}"
17
+ else
18
+ log "Cell #{cell.name} for page #{page.name} already present", :skip
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def update_element_positions
26
+ Alchemy::Page.all.each do |page|
27
+ if page.elements.any?
28
+ puts "\n## Updating element positions of page `#{page.name}`"
29
+ end
30
+ page.elements.group_by(&:cell_id).each do |_cell_id, elements|
31
+ elements.each_with_index do |element, idx|
32
+ position = idx + 1
33
+ if element.position != position
34
+ log "Updating position for element ##{element.id} to #{position}"
35
+ element.update_column(:position, position)
36
+ else
37
+ log "Position for element ##{element.id} is already correct (#{position})", :skip
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ def update_content_positions
45
+ Alchemy::Element.all.each do |element|
46
+ if element.contents.any?
47
+ puts "\n## Updating content positions of element `#{element.name}`"
48
+ end
49
+ element.contents.group_by(&:essence_type).each do |essence_type, contents|
50
+ puts "-> Contents of type `#{essence_type}`"
51
+ contents.each_with_index do |content, idx|
52
+ position = idx + 1
53
+ if content.position != position
54
+ log "Updating position for content ##{content.id} to #{position}"
55
+ content.update_column(:position, position)
56
+ else
57
+ log "Position for content ##{content.id} is already correct (#{position})", :skip
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def remove_orphaned_cells
65
+ puts "\n## Removing orphaned cells"
66
+ cells = Alchemy::Cell.unscoped.all
67
+ if cells.any?
68
+ orphaned_cells = cells.select do |cell|
69
+ cell.page.nil? && cell.page_id.present?
70
+ end
71
+ if orphaned_cells.any?
72
+ log "Found #{orphaned_cells.size} orphaned cells"
73
+ destroy_orphaned_records(orphaned_cells, 'cell')
74
+ else
75
+ log "No orphaned cells found", :skip
76
+ end
77
+ else
78
+ log "No cells found", :skip
79
+ end
80
+ end
81
+
82
+ def remove_orphaned_elements
83
+ puts "\n## Removing orphaned elements"
84
+ elements = Alchemy::Element.unscoped.all
85
+ if elements.any?
86
+ orphaned_elements = elements.select do |element|
87
+ element.page.nil? && element.page_id.present? ||
88
+ element.cell.nil? && element.cell_id.present?
89
+ end
90
+ if orphaned_elements.any?
91
+ log "Found #{orphaned_elements.size} orphaned elements"
92
+ destroy_orphaned_records(orphaned_elements, 'element')
93
+ else
94
+ log "No orphaned elements found", :skip
95
+ end
96
+ else
97
+ log "No elements found", :skip
98
+ end
99
+ end
100
+
101
+ def remove_orphaned_contents
102
+ puts "\n## Removing orphaned contents"
103
+ contents = Alchemy::Content.unscoped.all
104
+ if contents.any?
105
+ orphaned_contents = contents.select do |content|
106
+ content.essence.nil? && content.essence_id.present? ||
107
+ content.element.nil? && content.element_id.present?
108
+ end
109
+ if orphaned_contents.any?
110
+ log "Found #{orphaned_contents.size} orphaned contents"
111
+ destroy_orphaned_records(orphaned_contents, 'content')
112
+ else
113
+ log "No orphaned contents found", :skip
114
+ end
115
+ else
116
+ log "No contents found", :skip
117
+ end
118
+ end
119
+
120
+ private
121
+
122
+ def destroy_orphaned_records(records, class_name)
123
+ records.each do |record|
124
+ log "Destroy orphaned #{class_name}: #{record.inspect}"
125
+ record.destroy
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -6,5 +6,30 @@ module Alchemy
6
6
  desc 'Install asset manifests into `vendor/assets`'
7
7
  Alchemy::Upgrader::Tasks::InstallAssetManifests.new.install
8
8
  end
9
+
10
+ def self.store_image_file_format
11
+ desc 'Store image file format'
12
+ pictures = Alchemy::Picture.where(image_file_format: nil)
13
+ count = pictures.size
14
+ converted_pics = 0
15
+ errored_pics = 0
16
+ puts "-- Storing file format of #{count} pictures"
17
+ pictures.find_each(batch_size: 100).with_index do |pic, i|
18
+ begin
19
+ puts " -> Reading file format of #{pic.image_file_name} (#{i + 1}/#{count})"
20
+ format = pic.image_file.identify('-ping -format "%m"')
21
+ pic.update_column('image_file_format', format.to_s.chomp.downcase)
22
+ converted_pics += 1
23
+ rescue Dragonfly::Job::Fetch::NotFound => e
24
+ puts " -> #{e.message}"
25
+ errored_pics += 1
26
+ end
27
+ end
28
+ puts "-- Done! Converted #{converted_pics} images."
29
+ unless errored_pics.zero?
30
+ puts " !! But #{errored_pics} images caused errors."
31
+ puts " Please check errors above and re-run `rake alchemy:upgrade:3.4:store_image_file_format`"
32
+ end
33
+ end
9
34
  end
10
35
  end
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
- VERSION = "3.6.1"
2
+ VERSION = "3.6.2"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -1,4 +1,4 @@
1
- require 'alchemy/shell'
1
+ require 'alchemy/tasks/tidy'
2
2
 
3
3
  namespace :alchemy do
4
4
  namespace :tidy do
@@ -58,131 +58,3 @@ namespace :alchemy do
58
58
  end
59
59
  end
60
60
  end
61
-
62
- module Alchemy
63
- class Tidy
64
- extend Shell
65
-
66
- class << self
67
- def create_missing_cells(page_layouts, cells)
68
- page_layouts.each do |layout|
69
- next if layout['cells'].blank?
70
- cells_for_layout = cells.select { |cell| layout['cells'].include? cell['name'] }
71
- Alchemy::Page.where(page_layout: layout['name']).each do |page|
72
- cells_for_layout.each do |cell_for_layout|
73
- cell = Alchemy::Cell.find_or_initialize_by(name: cell_for_layout['name'], page_id: page.id)
74
- cell.elements << page.elements.select { |element| cell_for_layout['elements'].include?(element.name) }
75
- if cell.new_record?
76
- cell.save
77
- log "Creating cell #{cell.name} for page #{page.name}"
78
- else
79
- log "Cell #{cell.name} for page #{page.name} already present", :skip
80
- end
81
- end
82
- end
83
- end
84
- end
85
-
86
- def update_element_positions
87
- Alchemy::Page.all.each do |page|
88
- if page.elements.any?
89
- puts "\n## Updating element positions of page `#{page.name}`"
90
- end
91
- page.elements.group_by(&:cell_id).each do |_cell_id, elements|
92
- elements.each_with_index do |element, idx|
93
- position = idx + 1
94
- if element.position != position
95
- log "Updating position for element ##{element.id} to #{position}"
96
- element.update_column(:position, position)
97
- else
98
- log "Position for element ##{element.id} is already correct (#{position})", :skip
99
- end
100
- end
101
- end
102
- end
103
- end
104
-
105
- def update_content_positions
106
- Alchemy::Element.all.each do |element|
107
- if element.contents.any?
108
- puts "\n## Updating content positions of element `#{element.name}`"
109
- end
110
- element.contents.group_by(&:essence_type).each do |essence_type, contents|
111
- puts "-> Contents of type `#{essence_type}`"
112
- contents.each_with_index do |content, idx|
113
- position = idx + 1
114
- if content.position != position
115
- log "Updating position for content ##{content.id} to #{position}"
116
- content.update_column(:position, position)
117
- else
118
- log "Position for content ##{content.id} is already correct (#{position})", :skip
119
- end
120
- end
121
- end
122
- end
123
- end
124
-
125
- def remove_orphaned_cells
126
- puts "\n## Removing orphaned cells"
127
- cells = Alchemy::Cell.unscoped.all
128
- if cells.any?
129
- orphaned_cells = cells.select do |cell|
130
- cell.page.nil? && cell.page_id.present?
131
- end
132
- if orphaned_cells.any?
133
- destroy_orphaned_records(orphaned_cells, 'cell')
134
- else
135
- log "No orphaned cells found", :skip
136
- end
137
- else
138
- log "No cells found", :skip
139
- end
140
- end
141
-
142
- def remove_orphaned_elements
143
- puts "\n## Removing orphaned elements"
144
- elements = Alchemy::Element.unscoped.all
145
- if elements.any?
146
- orphaned_elements = elements.select do |element|
147
- element.page.nil? && element.page_id.present? ||
148
- element.cell.nil? && element.cell_id.present?
149
- end
150
- if orphaned_elements.any?
151
- destroy_orphaned_records(orphaned_elements, 'element')
152
- else
153
- log "No orphaned elements found", :skip
154
- end
155
- else
156
- log "No elements found", :skip
157
- end
158
- end
159
-
160
- def remove_orphaned_contents
161
- puts "\n## Removing orphaned contents"
162
- contents = Alchemy::Content.unscoped.all
163
- if contents.any?
164
- orphaned_contents = contents.select do |content|
165
- content.essence.nil? && content.essence_id.present? ||
166
- content.element.nil? && content.element_id.present?
167
- end
168
- if orphaned_contents.any?
169
- destroy_orphaned_records(orphaned_contents, 'content')
170
- else
171
- log "No orphaned contents found", :skip
172
- end
173
- else
174
- log "No contents found", :skip
175
- end
176
- end
177
-
178
- private
179
-
180
- def destroy_orphaned_records(records, class_name)
181
- records.each do |record|
182
- log "Destroy orphaned #{class_name}: #{record.id}"
183
- record.destroy
184
- end
185
- end
186
- end
187
- end
188
- end
@@ -148,12 +148,20 @@ namespace :alchemy do
148
148
  task '3.4' => ['alchemy:upgrade:prepare', 'alchemy:upgrade:3.4:run']
149
149
 
150
150
  namespace '3.4' do
151
- task run: ['alchemy:upgrade:3.4:install_asset_manifests']
151
+ task run: [
152
+ 'alchemy:upgrade:3.4:install_asset_manifests',
153
+ 'alchemy:upgrade:3.4:store_image_file_format'
154
+ ]
152
155
 
153
156
  desc 'Install asset manifests into `vendor/assets`'
154
157
  task install_asset_manifests: [:environment] do
155
158
  Alchemy::Upgrader::ThreePointFour.install_asset_manifests
156
159
  end
160
+
161
+ desc 'Store image file format on Alchemy pictures.'
162
+ task store_image_file_format: [:environment] do
163
+ Alchemy::Upgrader::ThreePointFour.store_image_file_format
164
+ end
157
165
  end
158
166
 
159
167
  desc 'Upgrade Alchemy to v3.5'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.1
4
+ version: 3.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas von Deyen
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-08-16 00:00:00.000000000 Z
16
+ date: 2017-09-01 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: active_model_serializers
@@ -847,6 +847,7 @@ files:
847
847
  - lib/alchemy/shell.rb
848
848
  - lib/alchemy/ssl_protection.rb
849
849
  - lib/alchemy/tasks/helpers.rb
850
+ - lib/alchemy/tasks/tidy.rb
850
851
  - lib/alchemy/test_support/config_stubbing.rb
851
852
  - lib/alchemy/test_support/controller_requests.rb
852
853
  - lib/alchemy/test_support/essence_shared_examples.rb