FIX: When destroying a topic, destroy its associated published page. (#12358)

Destroying a topic should remove the associated published page so another topic could re-use the slug.
This commit is contained in:
Roman Rizzi 2021-03-11 11:34:54 -03:00 committed by GitHub
parent 8fcad73b36
commit 56262349a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -165,6 +165,7 @@ class PostDestroyer
if @post.topic && @post.is_first_post?
permanent? ? @post.topic.destroy! : @post.topic.trash!(@user)
PublishedPage.unpublish!(@user, @post.topic) if @post.topic.published_page
end
update_associated_category_latest_topic
update_user_counts

View File

@ -439,6 +439,17 @@ describe PostDestroyer do
expect(user2.user_stat.post_count).to eq(0)
end
it 'deletes the published page associated with the topic' do
slug = 'my-published-page'
publish_result = PublishedPage.publish!(admin, post.topic, slug)
pp = publish_result.last
expect(publish_result.first).to eq(true)
PostDestroyer.new(admin, post).destroy
expect(PublishedPage.find_by(id: pp.id)).to be_nil
end
it "accepts a delete_removed_posts_after option" do
SiteSetting.delete_removed_posts_after = 0