]> git.openstreetmap.org Git - rails.git/commitdiff
Fix rubocop warning
authorTom Hughes <tom@compton.nu>
Mon, 15 Jul 2019 20:18:13 +0000 (21:18 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 15 Jul 2019 20:18:13 +0000 (21:18 +0100)
lib/tasks/upgrade_avatars.rake

index 3316f7e56bf82dde7a7e3d0f462fcf2db9555942..0466609ffb3c3573989387e59f8b5fe566cd26f3 100644 (file)
@@ -1,17 +1,17 @@
 namespace "storage" do
   task :upgrade_avatars => :environment do
     User.active.where.not(:image_file_name => nil).in_batches.each_record do |user|
-      unless user.avatar.attached?
-        io = File.open(user.image.path)
-        filename = user.image.original_filename
-        content_type = if user.image.content_type.nil?
-                         MimeMagic.by_magic(io)&.type
-                       else
-                         user.image.content_type
-                       end
+      next if user.avatar.attached?
 
-        user.avatar.attach(:io => io, :filename => filename, :content_type => content_type)
-      end
+      io = File.open(user.image.path)
+      filename = user.image.original_filename
+      content_type = if user.image.content_type.nil?
+                       MimeMagic.by_magic(io)&.type
+                     else
+                       user.image.content_type
+                     end
+
+      user.avatar.attach(:io => io, :filename => filename, :content_type => content_type)
     end
   end
 end