forum: delete posts when topic is deleted.

Fix it so that when a forum topic is deleted, all posts in the topic are
deleted too. Also make it so that when a forum topic is undeleted, all
posts in it are undeleted too.

Before when a topic was deleted, only the topic itself was marked as
deleted, not the posts inside the topic. This meant that when a spam
topic was deleted, the OP wouldn't be marked as deleted, so any
modreports against it wouldn't be marked as handled.

Also change it so that it's not possible to undelete a post in a deleted
topic, or to delete the OP of a topic without deleting the topic itself.

Finally, add a fix script to delete all active posts in deleted topics,
and to undelete all deleted OPs in active topics.
This commit is contained in:
evazion
2022-01-21 20:16:32 -06:00
parent befdb87bd5
commit 56722df753
9 changed files with 104 additions and 39 deletions

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
require_relative "base"
with_confirmation do
CurrentUser.scoped(User.system) do
# delete all posts in deleted topics
ForumPost.undeleted.where(topic: ForumTopic.deleted).update_all(is_deleted: true, updated_at: Time.zone.now, updater_id: User.system.id)
# undelete all deleted OPs in active topics
ForumPost.deleted.where(topic: ForumTopic.undeleted).find_each do |forum_post|
if forum_post.is_original_post?
forum_post.update_columns(is_deleted: false, updated_at: Time.zone.now, updater_id: User.system.id)
end
end
end
end