Skip uploading images for users that have a new style avatar
[rails.git] / lib / tasks / upgrade_avatars.rake
1 namespace "storage" do
2   task :upgrade_avatars => :environment do
3     User.active.where.not(:image_file_name => nil).in_batches.each_record do |user|
4       unless user.avatar.attached?
5         io = File.open(user.image.path)
6         filename = user.image.original_filename
7         content_type = if user.image.content_type.nil?
8                          MimeMagic.by_magic(io)&.type
9                        else
10                          user.image.content_type
11                        end
12
13         user.avatar.attach(:io => io, :filename => filename, :content_type => content_type)
14       end
15     end
16   end
17 end