Skip to content

Instantly share code, notes, and snippets.

@mchail
Created December 12, 2014 19:19
Show Gist options
  • Save mchail/3ad3d9eda2843ae8ca67 to your computer and use it in GitHub Desktop.
Save mchail/3ad3d9eda2843ae8ca67 to your computer and use it in GitHub Desktop.
recover ad images
a = Ad.find "53c354433486db904c000010"
s = a.site
ads = []
s.ads.each{|a| begin; open a.image.url; rescue; ads << a; end}
def move(a)
source_key = Paperclip::Interpolations.interpolate "ads/:attachment/:id_partition/:style/:filename", a.image, :original
target_key = Paperclip::Interpolations.interpolate "images/:hash/:style.:extension", a.image, :original
m = MigrateAds.new
moved = m.instance_variable_get(:@s3).buckets[m.instance_variable_get(:@bucket_name)].objects[source_key].copy_to(target_key, :acl => :public_read)
end
load 'script/tools/migrate_ads.rb'
ads.each{|a| move a}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment