From fef5f238a5468cd8501d8d357e12d6654782c731 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 27 Jun 2021 17:56:10 -0500 Subject: [PATCH] Fix #4829: DanbooruBot not properly handling BUR aliases when target tag has a wiki. --- app/logical/tag_mover.rb | 5 ++++- test/unit/tag_alias_test.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/logical/tag_mover.rb b/app/logical/tag_mover.rb index 7bd10ff8a..ae143e8e4 100644 --- a/app/logical/tag_mover.rb +++ b/app/logical/tag_mover.rb @@ -151,13 +151,16 @@ class TagMover old_artist.save! end - # Merge the other names from both wikis, then mark the old wiki as deleted. + # Merge the other names from both wikis. Transfer the body from the old wiki + # to the new wiki if the new wiki has an empty body. Then mark the old wiki + # as deleted. def merge_wikis! old_wiki.lock! new_wiki.lock! new_wiki.other_names += old_wiki.other_names new_wiki.is_deleted = false + new_wiki.body = old_wiki.body if new_wiki.body.blank? && old_wiki.body.present? new_wiki.save! old_wiki.body = "This tag has been moved to [[#{new_wiki.title}]]." diff --git a/test/unit/tag_alias_test.rb b/test/unit/tag_alias_test.rb index c4d557fde..8f614be00 100644 --- a/test/unit/tag_alias_test.rb +++ b/test/unit/tag_alias_test.rb @@ -180,6 +180,17 @@ class TagAliasTest < ActiveSupport::TestCase assert_equal("second", @wiki2.body) end + should "move the old wiki body to the new wiki if the new wiki has a blank body" do + @wiki1 = create(:wiki_page, title: "aaa", other_names: "111 222", body: "first") + @wiki2 = create(:wiki_page, title: "bbb", other_names: "111 333", body: "") + + TagAlias.approve!(antecedent_name: "aaa", consequent_name: "bbb", approver: @admin) + perform_enqueued_jobs + + assert_equal("This tag has been moved to [[#{@wiki2.title}]].", @wiki1.reload.body) + assert_equal("first", @wiki2.reload.body) + end + should "ignore the old wiki if it has been deleted" do @wiki1 = create(:wiki_page, title: "aaa", other_names: "111 222", body: "first", is_deleted: true) @wiki2 = create(:wiki_page, title: "bbb", other_names: "111 333", body: "second")