Comment supprimer en masse les anciens murmures

Suite à la discussion issue de Opérations de masse administratives :

Je cherche un moyen de supprimer les messages privés (whispers) dépassant un certain âge dans tous les sujets.

Généralement, nous utilisons les messages privés pour discuter d’actions potentielles de modération, mais une fois l’action entreprise, ces messages deviennent moins utiles et finissent par créer du bruit au fil du temps.

Je pourrais supprimer les publications dépassant un certain âge avec post_type=4 (whisper), mais cela semble pouvoir laisser des éléments en suspens ou incohérents dans la base de données, ou être interdit en raison des clés du forum.

Existe-t-il une méthode sûre pour procéder ainsi ?

2 « J'aime »

This would be the cleanest way to delete the posts:

whispers = Post.where(post_type: 4).where("created_at < ?", 1.year.ago)

whispers.find_each do |w|
  PostDestroyer.new(Discourse.system_user, w, skip_staff_log: true).destroy
  putc "."
end

This will essentially act as if the System user deleted each post by hand using the delete button on the post. I included skip_staff_log so you don’t pollute your staff logs, but you can remove that if you’d prefer to have the action logged.

Do you think that will meet your needs?

4 « J'aime »

I think that looks perfect - thank you!

I’ll give it a go on a test instance, and see how long it takes as we probably have a few thousand whispers!!!

2 « J'aime »

So this task works well, thank you… but the whispers are simply collapsed and still viewable by Admins and moderators when expanded.

This does tidy up topics, but I was hoping they could be completely removed in their entirety. I wondered if the whispers could all be moved to a new topic, and that then deleted or hidden from mods at least, but then I found this: Is there a way to remove all the deleted/hidden posts? And more recently: Why is it not possible to permanently delete topics or posts?

Unfortunately the above suggest there is no way to permanently remove the data :frowning: