From a3b3b0810d90abf9c49a6f04589f59aa25cc8719 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 13 Sep 2018 11:57:51 +0800 Subject: [PATCH] Rescue errors when running dry run for `UploadRecovery`. --- lib/upload_recovery.rb | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rb index d9044c33b77..0bc6d10b334 100644 --- a/lib/upload_recovery.rb +++ b/lib/upload_recovery.rb @@ -5,23 +5,28 @@ class UploadRecovery def recover Post.where("raw LIKE '%upload:\/\/%'").find_each do |post| - analyzer = PostAnalyzer.new(post.raw, post.topic_id) - cooked_stripped = analyzer.send(:cooked_stripped) + begin + analyzer = PostAnalyzer.new(post.raw, post.topic_id) + cooked_stripped = analyzer.send(:cooked_stripped) - cooked_stripped.css("img").each do |img| - if dom_class = img["class"] - if (Post.white_listed_image_classes & dom_class.split).count > 0 - next - end - 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"]) + cooked_stripped.css("img").each do |img| + if dom_class = img["class"] + if (Post.white_listed_image_classes & dom_class.split).count > 0 + next + end + 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 + rescue => e + raise e unless @dry_run + puts "#{post.full_url} #{e.class}: #{e.message}" end end end