Hi @muppeth, apologies for bumping this thread but I’ve been doing some Rails Console Discourse Hacking recently on a similar topic and thought I might be able to offer a solution.
Your tried command User.all.each do |user| CategoryUser.batch_set(user, :muted, [7]) end will overwrite any existing CategoryUsers. This is not what you want. The CategoryUser object creates a link between a User and a Category, setting the relationship between the two. If a user wants to mute (or watch, etc) 2 categories, then there will be 2 CategoryUsers with that user_id. The above command will overwrite every single one of them to mute the same Category, whatever they were set to before.
Here is some Ruby which checks to see if a CategoryUser exists for that user_id and category_id (leaving it alone in that case, allowing the user’s existing preference to be honoured)
In this case I wanted a list of users from a group, but you could do Users.all
# get a list of users
users = User.joins(:groups).where(groups: {name: "MyGroupName"})
# where category_id is the ID of the category you want to mute
users.each { |u| unless CategoryUser.exists?(user_id: u.id, category_id: 8) then CategoryUser.create(user_id: u.id, category_id: 8, CategoryUser.notification_levels[:muted]) end }
You would need to do this for each new Category you create whch you want to have muted
If you need this to be applied for all new users as they join, then there is a plugin which sets up a scheduled job to do this, which you could adapt to set muting daily for all new users, using similar commands.
https://github.com/discourse/discourse-watch-category-mcneel