From 11c4aa7d73f212d1dfba920e3853b9b6d6cbd197 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 15 Jul 2019 19:17:01 +0100 Subject: [PATCH] Skip uploading images for users that have a new style avatar --- lib/tasks/upgrade_avatars.rake | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/tasks/upgrade_avatars.rake b/lib/tasks/upgrade_avatars.rake index 03939dad8..3316f7e56 100644 --- a/lib/tasks/upgrade_avatars.rake +++ b/lib/tasks/upgrade_avatars.rake @@ -1,15 +1,17 @@ namespace "storage" do task :upgrade_avatars => :environment do User.active.where.not(:image_file_name => nil).in_batches.each_record do |user| - 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 + 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 - user.avatar.attach(:io => io, :filename => filename, :content_type => content_type) + user.avatar.attach(:io => io, :filename => filename, :content_type => content_type) + end end end end -- 2.39.5