From: Tom Hughes Date: Tue, 16 Jul 2019 17:34:50 +0000 (+0100) Subject: Update gravatar methods to check for Active Storage images X-Git-Tag: live~2451 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/3cfffc2258621558e1147ceaf63980a7f6ed414b?ds=sidebyside Update gravatar methods to check for Active Storage images --- diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9c918fee7..a3c21cd3d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -779,7 +779,7 @@ class UsersController < ApplicationController # check if this user has a gravatar and set the user pref is true def gravatar_enable(user) # code from example https://en.gravatar.com/site/implement/images/ruby/ - return false if user.image.present? + return false if user.avatar.attached? hash = Digest::MD5.hexdigest(user.email.downcase) url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back diff --git a/lib/tasks/upgrade_avatars.rake b/lib/tasks/upgrade_avatars.rake deleted file mode 100644 index 0466609ff..000000000 --- a/lib/tasks/upgrade_avatars.rake +++ /dev/null @@ -1,17 +0,0 @@ -namespace "storage" do - task :upgrade_avatars => :environment do - User.active.where.not(:image_file_name => nil).in_batches.each_record do |user| - next if 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) - end - end -end diff --git a/script/gravatar b/script/gravatar index 59ecff4f8..2c2c2bd4b 100755 --- a/script/gravatar +++ b/script/gravatar @@ -5,7 +5,7 @@ start = 0 User.where("image_use_gravatar AND id >=" + start.to_s).order("id").find_each do |user| p "checked up to id " + user.id.to_s if (user.id % 1000).zero? # just give a rough indication where we are for restarting - next if user.image.present? + next if user.avatar.attached? hash = Digest::MD5.hexdigest(user.email.downcase) url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back