Sha256: 0b089b772a10fd8bc6e12cb8903350b8c8ffd7fdc1982aff14415aebe2d72c1d
Contents?: true
Size: 1.22 KB
Versions: 11
Compression:
Stored size: 1.22 KB
Contents
class MigrateDragonflyImages < ActiveRecord::Migration def change if Refile.store.is_a? Refile::S3 prefix = Refile.store.instance_variable_get(:@prefix) bucket = Refile.store.instance_variable_get(:@bucket) Smithy::Asset.where('file_id LIKE ? OR file_id ~ ?', 'uploads/%', '\d{4}\/\d{2}\/\d{2}\/').each do |asset| new_file_id = asset.file_id.gsub(/([^a-z0-9]|(uploads\/)|(assets\/))/i, '') s3_object = bucket.object(asset.file_id) new_s3_object = bucket.object([*prefix, new_file_id].join('/')) if !s3_object.exists? && !new_s3_object.exists? say "[WARNING] Asset Not Found in S3, please find and move it manually, or remove the asset: ID=#{asset.id}, PATH=#{asset.file_id}"; say "Refile expects it to be here: #{[*prefix, new_file_id].join('/')}", true elsif new_s3_object.exists? # File may have already been moved in S3 s3_object.delete if s3_object.exists? else s3_object.move_to(new_s3_object) end asset.update_column(:file_id, new_file_id) end end Smithy::Asset.where(file_content_type: nil).each do |asset| asset.update_column(:file_content_type, asset.content_type) end end end
Version data entries
11 entries across 11 versions & 1 rubygems