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?
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
Comment #1
solipsist commentedA 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.
Comment #2
mactoph commentedThank 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.
Comment #3
solipsist commentedYeah, 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.
Comment #4
solipsist commentedBTW, 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.
Comment #5
mactoph commentedExcellent- worked perfectly, thanks so much!
Comment #6
mr.j commentedIn 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).
Comment #7
wwwoliondorcom commentedHi,
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.
Comment #8
solipsist commentedSorry 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.