Bulk deactivation of inactive users

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의 코드를 실행해야 하나요?

아마도 유용할 수 있는 플러그인이 하나 나온 것 같습니다: