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

This commit is contained in:
Guo Xiang Tan 2019-06-07 16:21:37 +08:00
parent d74ee9dbce
commit 29259b46ae
3 changed files with 16 additions and 3 deletions

View File

@ -144,6 +144,7 @@ group :test, :development do
gem 'byebug', require: ENV['RM_INFO'].nil? gem 'byebug', require: ENV['RM_INFO'].nil?
gem 'rubocop', require: false gem 'rubocop', require: false
gem 'parallel_tests' gem 'parallel_tests'
gem 'diffy', require: false
end end
group :development do group :development do

View File

@ -90,6 +90,7 @@ GEM
crass (1.0.4) crass (1.0.4)
debug_inspector (0.0.3) debug_inspector (0.0.3)
diff-lcs (1.3) diff-lcs (1.3)
diffy (3.3.0)
discourse-ember-source (3.8.0.1) discourse-ember-source (3.8.0.1)
discourse_image_optim (0.26.2) discourse_image_optim (0.26.2)
exifr (~> 1.2, >= 1.2.2) exifr (~> 1.2, >= 1.2.2)
@ -435,6 +436,7 @@ DEPENDENCIES
certified certified
colored2 colored2
cppjieba_rb cppjieba_rb
diffy
discourse-ember-source (~> 3.8.0) discourse-ember-source (~> 3.8.0)
discourse_image_optim discourse_image_optim
email_reply_trimmer (~> 0.1) email_reply_trimmer (~> 0.1)

View File

@ -661,6 +661,7 @@ end
desc "Coverts full upload URLs in `Post#raw` to short upload url" desc "Coverts full upload URLs in `Post#raw` to short upload url"
task 'posts:inline_uploads' => :environment do |_, args| task 'posts:inline_uploads' => :environment do |_, args|
dry_run = (ENV["DRY_RUN"].nil? ? true : ENV["DRY_RUN"] != "false") dry_run = (ENV["DRY_RUN"].nil? ? true : ENV["DRY_RUN"] != "false")
verbose = ENV["VERBOSE"]
scope = Post.joins(:post_uploads) scope = Post.joins(:post_uploads)
.distinct("posts.id") .distinct("posts.id")
@ -681,9 +682,7 @@ task 'posts:inline_uploads' => :environment do |_, args|
new_raw = InlineUploads.process(post.raw) new_raw = InlineUploads.process(post.raw)
if post.raw != new_raw if post.raw != new_raw
if dry_run if !dry_run
putc "🏃‍"
else
post.revise!(Discourse.system_user, post.revise!(Discourse.system_user,
{ {
raw: new_raw raw: new_raw
@ -691,10 +690,21 @@ task 'posts:inline_uploads' => :environment do |_, args|
skip_validations: true, skip_validations: true,
force_new_version: 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 "." putc "."
end end
fixed_count += 1 fixed_count += 1
else else
not_corrected_post_ids << post.id not_corrected_post_ids << post.id