A platform for community discussion. Free, open, simple.
DEV: Remove checklist syntax migrator (#22942)
Jarek Radosz7405aae85a39
diff --git a/plugins/checklist/lib/checklist_syntax_migrator.rb b/plugins/checklist/lib/checklist_syntax_migrator.rbdeleted file mode 100644index a815bcccd3e..00000000000--- a/plugins/checklist/lib/checklist_syntax_migrator.rb+++ /dev/null@@ -1,36 +0,0 @@-# frozen_string_literal: true--class ChecklistSyntaxMigrator- CHECKBOX_REGEX = /^( {0,3})\[(_|-|\*|\\\*)\]/- CODE_BLOCK_REGEX = /^ {0,3}```/- QUOTE_START_REGEX = /^ {0,3}\[quote/- QUOTE_END_REGEX = /^ {0,3}\[\/quote\]/-- def initialize(post)- @post = post- end-- def update_syntax!- lines = @post.raw.split("\n")- in_code = false- in_quote = false- lines.each_with_index do |line, index|- if line.match(CODE_BLOCK_REGEX)- in_code = !in_code- elsif line.match(QUOTE_START_REGEX)- in_quote = true- elsif line.match(QUOTE_END_REGEX)- in_quote = false- else- next if in_code || in_quote-- lines[index] = line.gsub(CHECKBOX_REGEX) { "#{$1}[x]" }- end- end- new_raw = lines.join("\n")-- return if new_raw == @post.raw- @post.raw = new_raw- @post.save!- end-enddiff --git a/plugins/checklist/lib/tasks/checklist.rake b/plugins/checklist/lib/tasks/checklist.rakedeleted file mode 100644index e48bdce312d..00000000000--- a/plugins/checklist/lib/tasks/checklist.rake+++ /dev/null@@ -1,12 +0,0 @@-# frozen_string_literal: true--desc "Convert old style checkbox markdown to new style"-task "discourse_checklist:migrate_old_syntax" => :environment do |t|- puts "Updating checklist syntax on all posts..."-- Post- .raw_match("[")- .find_each(batch_size: 50) { |post| ChecklistSyntaxMigrator.new(post).update_syntax! }-- puts "", "Done!"-enddiff --git a/plugins/checklist/plugin.rb b/plugins/checklist/plugin.rbindex d3b2f626a93..6fff328e765 100644--- a/plugins/checklist/plugin.rb+++ b/plugins/checklist/plugin.rb@@ -9,9 +9,4 @@enabled_site_setting :checklist_enabledregister_asset "stylesheets/checklist.scss"-register_svg_icon "spinner"--after_initialize do- ["../lib/checklist_syntax_migrator.rb"].each { |path| load File.expand_path(path, __FILE__) }-enddiff --git a/plugins/checklist/spec/lib/checklist_syntax_migrator_spec.rb b/plugins/checklist/spec/lib/checklist_syntax_migrator_spec.rbdeleted file mode 100644index 6d25632d2f8..00000000000--- a/plugins/checklist/spec/lib/checklist_syntax_migrator_spec.rb+++ /dev/null@@ -1,114 +0,0 @@-# frozen_string_literal: true--require "rails_helper"--describe ChecklistSyntaxMigrator do- before { SiteSetting.allow_uncategorized_topics = true }- let(:topic) { Fabricate(:topic) }- let(:post_args) { { user: topic.user, topic: topic } }-- def post_with_body(body)- args = post_args.merge(raw: body)- Fabricate.build(:post, args)- end-- it "replaces instances of the old checkbox instance, with the new syntax" do- body = "[-] 1\n[_] 2\n[*] 3\n[\\*] 4"- post = post_with_body(body)-- ChecklistSyntaxMigrator.new(post).update_syntax!-- expected = "[x] 1\n[x] 2\n[x] 3\n[x] 4"- expect(post.reload.raw).to eq(expected)- end-- it "does not replace if more than 3 spaces are before a checkbox" do- body = " [\*]\n [-]"- post = post_with_body(body)- post.save-- ChecklistSyntaxMigrator.new(post).update_syntax!- expect(post.reload.raw).to eq(body)- end-- it "does not replace checkboxes after text" do- body = "what about this? [\*]"- post = post_with_body(body)- post.save-- ChecklistSyntaxMigrator.new(post).update_syntax!- expect(post.reload.raw).to eq(body)- end-- it "handles each line independently" do- body = "[-] replace that, \n this wont be changed! [\*]"- post = post_with_body(body)-- ChecklistSyntaxMigrator.new(post).update_syntax!-- expected = "[x] replace that, \n this wont be changed! [\*]"- expect(post.reload.raw).to eq(expected)- end-- it "allows spaces 0,1,2 and 3 spaces before" do- body = "[-] 0 spaces\n [-] 1 space\n [-] 2 spaces\n [-] 3 spaces\n [-] 4 spaces"- post = post_with_body(body)-- ChecklistSyntaxMigrator.new(post).update_syntax!-- expected = "[x] 0 spaces\n [x] 1 space\n [x] 2 spaces\n [x] 3 spaces\n [-] 4 spaces"- expect(post.reload.raw).to eq(expected)- end-- it "does not convert checkboxes in code blocks" do- body = [- "```",- "[\*] This won't be converted",- "```",- "[\*] That will",- "```",- "[\*] Again this won't",- "```",- ].join("\n")- post = post_with_body(body)-- ChecklistSyntaxMigrator.new(post).update_syntax!-- expected = [- "```",- "[\*] This won't be converted",- "```",- "[x] That will",- "```",- "[\*] Again this won't",- "```",- ].join("\n")- expect(post.reload.raw).to eq(expected)- end-- it "does not convert checkboxes in block quotes" do- body = [- '[quote="markvanlan, post:10, topic:10"]',- "[\*] This won't be converted",- "[/quote]",- "[\*] That will",- '[quote="markvanlan, post:11, topic:10"]',- "[\*] Again this won't",- "[/quote]",- ].join("\n")- post = post_with_body(body)-- ChecklistSyntaxMigrator.new(post).update_syntax!-- expected = [- '[quote="markvanlan, post:10, topic:10"]',- "[\*] This won't be converted",- "[/quote]",- "[x] That will",- '[quote="markvanlan, post:11, topic:10"]',- "[\*] Again this won't",- "[/quote]",- ].join("\n")- expect(post.reload.raw).to eq(expected)- end-end