Sha256: b5a7bf35d3a681f4f3719fe5e3dcff0f2ee01c6c58f1f3582f28a1cea7f3c56e
Contents?: true
Size: 992 Bytes
Versions: 14
Compression:
Stored size: 992 Bytes
Contents
module Alchemy module Upgrader::TwoPointSix private def convert_attachment_storage desc "Convert the attachment storage" converted_files = [] files = Dir.glob Rails.root.join 'uploads/attachments/**/*.*' if files.blank? log "No attachments found", :skip else files.each do |file| file_uid = file.gsub(/#{Rails.root.to_s}\/uploads\/attachments\//, '') file_id = file_uid.split('/')[1].to_i attachment = Alchemy::Attachment.find_by_id(file_id) if attachment && attachment.file_uid.blank? attachment.file_uid = file_uid attachment.file_size = File.new(file).size attachment.file_name = attachment.sanitized_filename if attachment.save! log "Converted #{file_uid}" end else log "Attachment with id #{file_id} not found or already converted.", :skip end end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems