The discussion revolves around wiping all posts from a Discourse forum while keeping users, site settings, and categories intact. SBrodie initiated the discussion, seeking an easy way to delete all topics and categories. codinghorror suggested creating a rake task to achieve this.
zogstrip provided a rails command line solution to delete all posts, but noted that this method only marks posts as deleted, not removing them from the database. schungx emphasized the need for a script that actually deletes all topics and posts.
techAPJ mentioned that thanks to blake, there are now rake tasks available for cleanup. However, these tasks may not remove custom field data. zogstrip provided additional code to remove custom field data.
Cozdabuch sought clarification on whether the rake tasks can reset logs and remove all post data, making the site start fresh. The discussion highlights the need for a more comprehensive solution to wipe all content while preserving site structure and settings.
One of the Discourse sites that I operate is preparing to undergo a re-launch, and due to the large amount of inactivity on the forum, and the type of posts that have been made in the last year or so, I’d like to remove/delete all topics and start over fresh on the forums.
The easiest way is to use rails command line, ssh into your server and then
cd /var/discourse
./launcher enter app
rails c
Post.where("user_id > 0").where(post_number: 1).find_each do |post|
PostDestroyer.new(Discourse.system_user, post).destroy
putc "."
end
be sure to make a backup before running this destructive code.
Does running PostDestroyer.destroy actually remove the record from the database or does it merely mark the post as deleted, keeping it in the database?
There will be a lot of uses for a script that actually DELETES all the topics and posts, leaving everything (like site settings and users) there. Categories are yes/no.
Keep all site structure, (categories, groups, users, and settings), but wipe all threads, and PMS, and logs, basically to take a demo site that served as a sandbox, and transition it to a live site, similar to the OP, without having to setup a new instance and re-register all my users. But everything content wise, as well as logged actions all starts fresh.
Does this rake task posted above do this, or can the added reset logs as well be done, so all post data, and all log data is wiped fresh?
Isso é realmente útil, muito obrigado. Parece que isso não remove nenhum Campo Personalizado dos posts. No meu caso, estou tentando importar posts, então os campos personalizados “import_id” permanecem, fazendo com que o importador ache que os posts ainda estão presentes, mesmo que não estejam. Há alguma maneira de remover também os dados dos campos personalizados?