Here’s what I came up with:
- User creates topic
- User deletes topic post, scheduling deletion (I changed the
delete_removed_posts_after
site setting to1
) - Topic is deleted after specified time
- Staff undeletes topic and reverts to the original version of the post (only restoring will bring the post back with the “topic withdrawn by author, will be automatically deleted in 1 hour unless flagged” message)
- Topic will re-delete after some time
What’s happening: When a user deletes there own topic post, there is a property called user_deleted
that gets set to true
. There is a background job called DestroyOldDeletionStubs
that runs every 30 minutes. This job runs the PostDestroyer.destroy_stubs
function which will search the database and delete any posts that have user_deleted
set to true
along with an expired “deletion timer.”
The problem: When staff restores the post, user_deleted
never gets set to false
, so the next time DestroyOldDeletionStubs
runs, the post will be re-deleted.
The solution: I’m pretty sure we will need to add some logic to the staff_recovered
function that will set user_deleted
to false
(user_recovered
already does this) See https://github.com/discourse/discourse/blob/master/lib/post_destroyer.rb
The quick fix: Restore the topic post and get its post ID, then go to your rails console and run:
Post.find_by_id(POST_ID).update(user_deleted: false)
The post ID can be found easily by appending .json
to the end of a topic URL. So using this topic as an example: https://meta.discourse.org/t/topic-keeps-getting-deleted/128013.json. The topic post ID is 632362
.