@@ -92,13 +92,7 @@ module FileStorageUpdates
9292 # @return [String] path to location where an attachment should be (based on id)
9393 def path_for_attachment ( attachment )
9494 new_id_dir = "#{ Paperclip ::Interpolations . id_partition ( AttachmentWrapper . new ( attachment ) , nil ) } /original"
95- "#{ new_id_dir } /#{ attachment . data_fingerprint } "
96- end
97-
98- # @return [String] Path to where an attachment should be
99- def path_to_attachment ( attachment )
100- loc = path_for_attachment ( attachment )
101- file_in_attachments_dir ( loc )
95+ File . join ( attachments_dir , new_id_dir , fingerprint_for_file_location ( attachment ) )
10296 end
10397
10498 # For a given class with an Attachment association (pre-3.5.0), migrate its attachment data to match the new
@@ -182,18 +176,19 @@ def cleanup_attachment_file_storage
182176 def migrate_attachments_file_location ( model_class )
183177 model_class . unscoped . each do |attachment |
184178 from = File . join ( attachments_dir , attachment . file_location )
185- to = path_to_attachment ( attachment )
179+ to = path_for_attachment ( attachment )
186180 move_attachment_file ( from , to )
187181
188- new_fingerprint = attachment . file_location . split ( "/" ) . last
182+ new_fingerprint = fingerprint_for_file_location ( attachment )
189183 model_class . unscoped . update_all ( { :data_fingerprint => new_fingerprint } , :id => attachment . id )
190184 end
191185 end
192186
193- def file_in_attachments_dir ( file_name )
194- File . join ( Cms ::Attachment . configuration . attachments_root , file_name )
187+ # Given a CMS <3.5 file_location, figure out the fingerprint, which should just be the file name.
188+ def fingerprint_for_file_location ( attachment )
189+ attachment . file_location . split ( "/" ) . last
195190 end
196-
191+
197192 def move_attachment_file ( old_location , new_location )
198193 if File . exists? ( old_location )
199194 FileUtils . mkdir_p ( File . dirname ( new_location ) , :verbose => false )
@@ -203,10 +198,15 @@ def move_attachment_file(old_location, new_location)
203198 end
204199 end
205200
201+ # Return the location of the attachment's upload directory.
206202 def attachments_dir
207- Cms ::Attachment . configuration . attachments_root
203+ Cms ::Attachments :: Serving . send_attachments_with . attachments_storage_location
208204 end
209-
205+
206+ # def attachments_dir
207+ # Cms::Attachment.configuration.attachments_root
208+ # end
209+
210210 # Allows us to use the Paperclip interpolations logic directly
211211 class AttachmentWrapper
212212 def initialize ( attachment )
0 commit comments