XF 2.1 Is there a way to make all users watch a forum.. not as they sign up, but the ones that are already signed up?

entelechy

Active member
Is there a way to make all users watch a forum.. not as they sign up, but the ones that are already signed up?
 
You can do this via SQL;

SQL:
insert ignore into xf_forum_watch (node_id, user_id, notify_on, send_alert, send_email)
select 1, user_id, 'thread', 1, 0
from xf_user
where is_banned = 0;
Change node_id value in the select as required, the insert ignore means existing forum watches are preserved.
 
Can I confirm that the node_id is the number after the period at the end of the url of the node?

The node I'm trying to use this for has a node ID 92, I've tried adding 92 and "92" as a replacement for node_id, both cases I get:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"92", user_id, notify_on, send_alert, send_email)
select 1, user_id, 'thread', 1' at line 1

Any ideas on this Xon?
 
Can I confirm that the node_id is the number after the period at the end of the url of the node?
Yes.

For the node_id of 92, this sql should do it (get alerts but not emails for new threads);
SQL:
insert ignore into xf_forum_watch (node_id, user_id, notify_on, send_alert, send_email)
select 92, user_id, 'thread', 1, 0
from xf_user
where is_banned = 0;
 
For the node_id of 92, this sql should do it (get alerts but not emails for new threads);

@Xon I am getting a problem with this.
For node id_20 I am wanting to make all users watch thread with alerts and emails

Many users are already watching with alerts but not emails, e.g. user 5

Screenshot 2020-01-15 at 15.58.45.webp
:

So I use this based on your query above

Code:
insert ignore into xf_forum_watch (node_id, user_id, notify_on, send_alert, send_email)
select 20, user_id, 'thread', 1, 1
from xf_user
where is_banned = 0;

But the users are not updated, I get these messages after running the query

Code:
Warning: #1062 Duplicate entry '5-20' for key 'PRIMARY'

And nothing changes, e.g. user 5 still has 1, 0
 
You'd need to update those values. You can use this query to either insert or update if the record already exists:

SQL:
INSERT INTO xf_forum_watch (node_id, user_id, notify_on, send_alert, send_email)
SELECT 20, user_id, 'thread', 1, 1
FROM xf_user
WHERE is_banned = 0
ON DUPLICATE KEY UPDATE send_alert=VALUES(send_alert), send_email=VALUES(send_email);
 
Back
Top Bottom