From c448e014fe31d4ed787ff15983da6471d1d3a055 Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <vinothkannan@vinkas.com>
Date: Mon, 29 Apr 2019 11:33:57 +0530
Subject: [PATCH] Recover missing old scheme uploads from tombstone directory
 too.

---
 lib/tasks/posts.rake | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake
index fe24d90e4b2..3d1509c96fc 100644
--- a/lib/tasks/posts.rake
+++ b/lib/tasks/posts.rake
@@ -443,9 +443,18 @@ task 'posts:missing_uploads' => :environment do
               # recovering old scheme upload.
               local_store = FileStore::LocalStore.new
               public_path = "#{local_store.public_dir}#{path}"
+              file_path = nil
+
               if File.exists?(public_path)
+                file_path = public_path
+              else
+                tombstone_path = public_path.sub("/uploads/", "/uploads/tombstone/")
+                file_path = tombstone_path if File.exists?(tombstone_path)
+              end
+
+              if file_path.present?
                 tmp = Tempfile.new
-                tmp.write(File.read(public_path))
+                tmp.write(File.read(file_path))
                 tmp.rewind
 
                 if upload = UploadCreator.new(tmp, File.basename(path)).create_for(Discourse.system_user.id)