• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Query to make a specific User Group watch specific forum

Chris D

XenForo developer
Staff member
#2
This will probably do it (usual rules about running on a test install, backups etc. apply):
SQL:
INSERT INTO xf_forum_watch
(user_id, node_id, notify_on, send_alert, send_email)
SELECT user_id, 123, 'thread', 1, 0
FROM xf_user
WHERE FIND_IN_SET(4, secondary_group_ids)
You'd need to run it for each node_id and user group ID. 123 represents the node_id and 4 represents the user group. This will only check the usergroup against the secondary_group_ids field.
 

Mr Lucky

Well-known member
#3
Thanks first test didn't work though.

using forum id 33 and secondary user group id 18

SQL:
INSERT INTO xf_forum_watch
(user_id, node_id, notify_on, send_alert, send_email)
SELECT user_id, 33, 'thread', 1, 0
FROM xf_user
WHERE FIND_IN_SET(18, secondary_group_ids)
SQL:
Error

MySQL said: Documentation
#1062 - Duplicate entry '4650-33' for key 'PRIMARY'
 

Chris D

XenForo developer
Staff member
#4
Just means that one user is already watching that forum. Try changing INSERT INTO to INSERT IGNORE INTO.