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

Version Path
alchemy_cms-2.9.1 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.9.0 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.8.3 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.7.5 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.6.3 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.7.4 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.8.2 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.8.1 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.7.3 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.7.2 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.7.1 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.7.0 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.6.2.1 lib/alchemy/upgrader/two_point_six.rb
alchemy_cms-2.6.2 lib/alchemy/upgrader/two_point_six.rb