# 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
+++ /dev/null
-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
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