Add dry run option to UploadRecovery.

This commit is contained in:
Guo Xiang Tan 2018-09-12 21:53:01 +08:00
parent 38668818a5
commit 24c55bd613
2 changed files with 13 additions and 3 deletions

View File

@ -719,11 +719,13 @@ end
task "uploads:recover" => :environment do
require_dependency "upload_recovery"
dry_run = ENV["DRY_RUN"].present?
if ENV["RAILS_DB"]
UploadRecovery.new.recover
UploadRecovery.new(dry_run: dry_run).recover
else
RailsMultisite::ConnectionManagement.each_connection do |db|
UploadRecovery.new.recover
UploadRecovery.new(dry_run: dry_run).recover
end
end
end

View File

@ -1,4 +1,8 @@
class UploadRecovery
def initialize(dry_run: false)
@dry_run = dry_run
end
def recover
Post.where("raw LIKE '%upload:\/\/%'").find_each do |post|
analyzer = PostAnalyzer.new(post.raw, post.topic_id)
@ -12,11 +16,15 @@ class UploadRecovery
end
if img["data-orig-src"]
if @dry_run
puts "#{post.full_url} #{img["data-orig-src"]}"
else
recover_post_upload(post, img["data-orig-src"])
end
end
end
end
end
private