mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
added 'uploads:backfill_shas' rake task
This commit is contained in:
parent
6c4554b941
commit
f94e4ffdcb
1 changed files with 20 additions and 0 deletions
20
lib/tasks/uploads.rake
Normal file
20
lib/tasks/uploads.rake
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
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?
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "done"
|
||||||
|
end
|
Loading…
Reference in a new issue