Support deleting a user but keeping their posts

This sounds like a real edge case to me. I’d personally prefer the way that “disabling” vs. “deleting” is supposed to work. And as you say yourself:

Therefore I’d be against adding it. There is simply no way to anticipate everything that goes wrong and have a feature for every edge in this. It is more work to do that than fix manually the few times it happens. I’ll just quote xkcd on that:

That said, I’m happy to help you out. Here is a little script that you can copy paste into the rails console (start with bundle exec rails c from within your discourse install directory) to re-assign all posts of the soon-to-be-deleted-user to the new_user:

USERNAME_TO_BE_DELETED = "jessamyn"
NEW_USERNAME = "clay_7"
new_user = User.find_by_username(NEW_USERNAME)
old_user = User.find_by_username(USERNAME_TO_BE_DELETED)
posts = old_user.posts
topics = old_user.topics

posts.each do |post|
  post.user = new_user
  post.save()
end

topics.each do |topic|
  topic.user = new_user
  topic.save()
end

And you are safe to delete the old user. Be aware, some caches will still show the old data. Also: never copy-paste code into a production systems console that you’ve found on a forum :wink: – Code comes without any warranty.

7 Mi Piace