Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: new rake task to invalidate broken images in post

Arpit Jalanaf20d616deee
diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake
index bc83af2e7d4..465808718f7 100644
--- a/lib/tasks/posts.rake
+++ b/lib/tasks/posts.rake
@@ -631,3 +631,21 @@ task 'posts:recover_uploads_from_index' => :environment do |_, args|
end
end
end
+
+desc 'invalidate broken images'
+task 'posts:invalidate_broken_images' => :environment do
+ puts "Invalidating broken images.."
+
+ posts = Post.where("raw like '%<img%'")
+
+ rebaked = 0
+ total = posts.count
+
+ posts.find_each do |p|
+ rebake_post(p, invalidate_broken_images: true)
+ print_status(rebaked += 1, total)
+ end
+
+ puts
+ puts "", "#{rebaked} posts rebaked!"
+end