Is there a query I can run or any other way to add posts and comments to a user's 'Watched Posts' that were made before the module was installed?

Comments

solipsist’s picture

A user can watch any node you have enabled Watcher for, regardless of when that post was made.

To add a node to a user's watched posts list, use the query:
INSERT INTO watcher_nodes VALUES(uid, nid);

uid being the user id, nid being the node id.

mactoph’s picture

Thank you solipsist- I already have a lot of users who have made hundreds of posts, I am wondering if there is a way to run a query that would automate the process of adding each node that a user has started or commented on into their watchlist without having to go through each node individually.

solipsist’s picture

Yeah, if you use MySQL try the following:
INSERT IGNORE INTO watcher_nodes (uid, nid) SELECT uid, nid FROM node;

The IGNORE keyword prevents MySQL from halting in case of a duplicate key conflict (i.e. the user is already watching the node) and treats it as a warning and goes on.

solipsist’s picture

BTW, the above works for nodes, not comments. For comments, use:
INSERT IGNORE INTO watcher_nodes (uid, nid) SELECT uid, nid FROM comments;

Combining these two queries should be possible using a JOIN.

mactoph’s picture

Status: Active » Closed (fixed)

Excellent- worked perfectly, thanks so much!

mr.j’s picture

In case anyone else finds this, this will insert the records and switch on email notifications, as well as setting the timestamp the record was added (mysql).

INSERT IGNORE INTO watcher_nodes (uid, nid, send_email, added) SELECT uid, nid, 1, UNIX_TIMESTAMP() FROM node;
INSERT IGNORE INTO watcher_nodes (uid, nid, send_email, added) SELECT uid, nid, 1, UNIX_TIMESTAMP() FROM comments;
wwwoliondorcom’s picture

Hi,

I just installed this great module and I'm also looking for this function to notify all users of comments on their previously created pages/nodes or commented pages, but is it safe to do that in the database?

I just need to run this in mysql ?

INSERT IGNORE INTO watcher_nodes (uid, nid, send_email, added) SELECT uid, nid, 1, UNIX_TIMESTAMP() FROM node;
INSERT IGNORE INTO watcher_nodes (uid, nid, send_email, added) SELECT uid, nid, 1, UNIX_TIMESTAMP() FROM comments;

Thanks a lot.

solipsist’s picture

Sorry I haven't replied until now. I'm at Drupalcon so I haven't had much time to spare.

The above should work. Just make a database backup copy first just in case.