diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index ea6e2357067..559136dd22a 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -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 diff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rb index 90b21a36d80..176ba6ca142 100644 --- a/lib/upload_recovery.rb +++ b/lib/upload_recovery.rb @@ -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,7 +16,11 @@ class UploadRecovery end if img["data-orig-src"] - recover_post_upload(post, 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