لدى مجتمعنا عدة آلاف من الرسائل الخاصة التي تم إرسالها بين المستخدمين. هل هناك طريقة لإزالة الرسائل الخاصة التي تحتوي على أكثر من 100 رد نهائيًا من قاعدة البيانات (بدون إمكانية الاستعادة)؟
Well, I think that this will do what you asked. It will delete any private messages that were not created by a system user or discobot. It will still delete any other private messages, including those from admins.
It’s not tested. I’m not saying that it’s a good idea. I won’t promise that it won’t do something bad.
cd /var/discourse
discourse backup
./launcher enter app
rails s
Topic.where(archetype: 'private_message').where("user_id > 0").destroy_all
exit
discourse enable_restore
discourse restore
If something bad does not happen, you can omit the last two steps. If something bad does happen, you’ll want to copy/paste the most recent backup printed by the discourse restore command to restore the backup.
You can remove all message at once.
rake destroy:private_messages
Reference:
Nice work, @IAmGav! I swear i looked there and didn’t see.
Thanks Jay,
Running batch delete query directly on the database is so Scary ![]()
I took a brief look at how this function works. As it turns out, after running it, all private messages will be deleted.
def destroy_private_messages
Topic.where(archetype: "private_message").find_each do |pm|
@io.puts "Destroying #{pm.slug} pm"
first_post = pm.ordered_posts.first
@io.puts PostDestroyer.new(Discourse.system_user, first_post).destroy
end
end
I think I have to choose the scary way that @pfaffman pointed out to filter messages. or try to define custom rake function and use PostDestroyer.new(Discourse.system_user, first_post).destroy
إعادة النظر في هذا الموضوع القديم، حيث أن أياً من الإجابات ليست صحيحة بنسبة 100٪.
مهمة rake rake destroy:private_messages لا تقوم بحذف الرسائل الخاصة بشكل دائم، بل تقوم بحذفها بشكل ناعم. لا يزال بإمكان المسؤول رؤيتها ويمكن استعادتها.
الكود Rails Topic.where(archetype: 'private_message').where("user_id > 0").destroy_all يقوم بحذف المواضيع، ولكن ليس الرسائل الفعلية. لا تزال موجودة في قاعدة البيانات ويمكن عرضها باستخدام، على سبيل المثال، المكون الإضافي لاستكشاف البيانات.
هذا الكود سيقوم بحذف جميع مشاركات ومواضيع الرسائل الخاصة بشكل دائم:
تحذير: سكين حاد هنا!
Post.where(topic_id: Topic.where(archetype: 'private_message').where("user_id > 0")).destroy_all
Topic.where(archetype: 'private_message').where("user_id > 0").destroy_all
(وللتصفية على المواضيع التي تحتوي على 100 رد أو أكثر، تحتاج إلى توسيع Topic.where باستخدام where("posts_count > 100") في كلا السطرين)