mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:52:45 +08:00
FIX: uploads:backfill_shas rake task
This commit is contained in:
parent
7bc3a6fff0
commit
c1cf602de2
|
@ -6,21 +6,19 @@ require "digest/sha1"
|
||||||
|
|
||||||
task "uploads:backfill_shas" => :environment do
|
task "uploads:backfill_shas" => :environment do
|
||||||
RailsMultisite::ConnectionManagement.each_connection do |db|
|
RailsMultisite::ConnectionManagement.each_connection do |db|
|
||||||
puts "Backfilling #{db}"
|
puts "Backfilling #{db}..."
|
||||||
Upload.select([:id, :sha, :url]).find_each do |u|
|
Upload.where(sha1: nil).find_each do |u|
|
||||||
if u.sha.nil?
|
begin
|
||||||
|
path = Discourse.store.path_for(u)
|
||||||
|
u.sha1 = Digest::SHA1.file(path).hexdigest
|
||||||
|
u.save!
|
||||||
putc "."
|
putc "."
|
||||||
path = "#{Rails.root}/public/#{u.url}"
|
rescue Errno::ENOENT
|
||||||
sha = Digest::SHA1.file(path).hexdigest
|
putc "X"
|
||||||
begin
|
|
||||||
Upload.update_all ["sha = ?", sha], ["id = ?", u.id]
|
|
||||||
rescue ActiveRecord::RecordNotUnique
|
|
||||||
# not a big deal if we've got a few duplicates
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "done"
|
puts "", "Done"
|
||||||
end
|
end
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
Loading…
Reference in New Issue
Block a user