]> git.openstreetmap.org Git - rails.git/blob - lib/tasks/upgrade_avatars.rake
Fix rubocop warning
[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       next if user.avatar.attached?
5
6       io = File.open(user.image.path)
7       filename = user.image.original_filename
8       content_type = if user.image.content_type.nil?
9                        MimeMagic.by_magic(io)&.type
10                      else
11                        user.image.content_type
12                      end
13
14       user.avatar.attach(:io => io, :filename => filename, :content_type => content_type)
15     end
16   end
17 end