From c1cf602de2def238e6008c63e269147354bd97dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 10 Jun 2015 17:19:58 +0200 Subject: [PATCH] FIX: uploads:backfill_shas rake task --- lib/tasks/uploads.rake | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index 8ff0c70e0c6..3a1f178c7a4 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -6,21 +6,19 @@ require "digest/sha1" task "uploads:backfill_shas" => :environment do RailsMultisite::ConnectionManagement.each_connection do |db| - puts "Backfilling #{db}" - Upload.select([:id, :sha, :url]).find_each do |u| - if u.sha.nil? + puts "Backfilling #{db}..." + Upload.where(sha1: nil).find_each do |u| + begin + path = Discourse.store.path_for(u) + u.sha1 = Digest::SHA1.file(path).hexdigest + u.save! putc "." - path = "#{Rails.root}/public/#{u.url}" - sha = Digest::SHA1.file(path).hexdigest - begin - Upload.update_all ["sha = ?", sha], ["id = ?", u.id] - rescue ActiveRecord::RecordNotUnique - # not a big deal if we've got a few duplicates - end + rescue Errno::ENOENT + putc "X" end end end - puts "done" + puts "", "Done" end ################################################################################