Skip to content

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

DEV: Verbose mode for `posts:inline_uploads` rake task.

Guo Xiang Tan29259b46ae63
diff --git a/Gemfile b/Gemfile
index d0878a8873e..19deecf88fb 100644
--- a/Gemfile
+++ b/Gemfile
@@ -144,6 +144,7 @@ group :test, :development do
gem 'byebug', require: ENV['RM_INFO'].nil?
gem 'rubocop', require: false
gem 'parallel_tests'
+ gem 'diffy', require: false
end
group :development do
diff --git a/Gemfile.lock b/Gemfile.lock
index db8907d12f5..0fa35801f0d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -90,6 +90,7 @@ GEM
crass (1.0.4)
debug_inspector (0.0.3)
diff-lcs (1.3)
+ diffy (3.3.0)
discourse-ember-source (3.8.0.1)
discourse_image_optim (0.26.2)
exifr (~> 1.2, >= 1.2.2)
@@ -435,6 +436,7 @@ DEPENDENCIES
certified
colored2
cppjieba_rb
+ diffy
discourse-ember-source (~> 3.8.0)
discourse_image_optim
email_reply_trimmer (~> 0.1)
diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake
index 5f827995988..aa4b87abcaf 100644
--- a/lib/tasks/posts.rake
+++ b/lib/tasks/posts.rake
@@ -661,6 +661,7 @@ end
desc "Coverts full upload URLs in `Post#raw` to short upload url"
task 'posts:inline_uploads' => :environment do |_, args|
dry_run = (ENV["DRY_RUN"].nil? ? true : ENV["DRY_RUN"] != "false")
+ verbose = ENV["VERBOSE"]
scope = Post.joins(:post_uploads)
.distinct("posts.id")
@@ -681,9 +682,7 @@ task 'posts:inline_uploads' => :environment do |_, args|
new_raw = InlineUploads.process(post.raw)
if post.raw != new_raw
- if dry_run
- putc "πŸƒβ€"
- else
+ if !dry_run
post.revise!(Discourse.system_user,
{
raw: new_raw
@@ -691,10 +690,21 @@ task 'posts:inline_uploads' => :environment do |_, args|
skip_validations: true,
force_new_version: true
)
+ end
+ if verbose
+ require 'diffy'
+ Diffy::Diff.default_format = :color
+ puts "Cooked diff for Post #{post.id}"
+ puts Diffy::Diff.new(PrettyText.cook(post.raw), PrettyText.cook(new_raw), context: 1)
+ puts
+ elsif dry_run
+ putc "πŸƒ"
+ else
putc "."
end
+
fixed_count += 1
else
not_corrected_post_ids << post.id