إلغاء تفعيل جماعي للمستخدمين غير النشطين

I migrated about 250 users that I’d now like to mark as inactive because they haven’t visited the forum in quite some time. Is there a way to bulk deactivate users with a ‘last seen’ date prior to some date?

My goal is to prevent emails from sending to these users. I think deactivation is the correct status because it would allow those users to re-activate if they want - correct?

A simpler solution might be to adjust suppress digest email after days. They’d still be “active” but they’d stop getting notices.

But, if you want, it’s something like this:

cd /var/discourse
./launcher enter app
rails c
User.where("last_seen_at < '2016-01-01'").update_all(active: false)
exit
exit

That setting seems to only impact digest emails. Many of the categories are setup as “watch” by default, so users are getting per-post emails - not digest. Do I understand that correctly?

EDIT: I see emails going out to users that have been inactive for more than 365 days.

I think you’re right. The code I provided, though untested, should do what you want. You should backup your database before trying it.

Quick follow up. This script worked perfectly! I tested it in a demo environment first.

Two minor suggestions:

  1. I added “and active = true” to the where criteria because I wasn’t sure if there’d be side effects to deactivating an inactive user.
  2. People that come across this post is the future may want to consider adding “and id > 0” to prevent updating the system and discobot users (though I didn’t do this myself because they were within my last_seen_at window.) It doesn’t appear that their last_seen_at is updated after the accounts are created.

نظرًا لأن هذا موضوع قديم، فهل أصبح إلغاء تنشيط المستخدمين غير النشطين بشكل جماعي ميزة في Discourse أم لا يزال يتعين عليك تشغيل كود @pfaffman كحل وحيد؟

أعتقد أن هناك إضافة متاحة الآن قد تجدها مفيدة: