Posted by Ashford on August 16, 2008 at 3:53pm
Jump to:
| Project: | Subscriptions |
| Version: | 6.x-1.x-dev |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
With my Drupal upgrade from 4.7 to 5, I noted the Notify.module was deprecated and replaced by the Subscription.module. Our organization's members are low-tech computer users. They depend on the volunteer webmaster, me, to automate most of their settings.
Is there a mySQL query I could run in phpMyAdmin to automatically subscribe all current Users to send Interval of daily? Would the query statement need to include the CCK content_types A,B,C for each uid?
Comments
#1
The exact query would depend on who you want subscribed and how (to all posts, to posts of certain node types, etc.).
What follows is not what you requested, but could equally be documented somewhere. The following script ensures that every one is subscribed to nodes they have posted, and to nodes where they have commented:
update subscriptions by node authors:
<?php
$result = db_query('SELECT * FROM {node} WHERE uid != 1');
while (
$node = db_fetch_object($result)) {
$result2 = db_query("SELECT * FROM {subscriptions} WHERE module = 'node' AND field = 'nid' AND value = %d AND recipient_uid = %d", $node->nid, $node->uid);
if (!mysql_num_rows($result2)) {
db_query("INSERT INTO {subscriptions} (module, field, value, recipient_uid, send_interval, author_uid, send_updates, send_comments)
VALUES ('node', 'nid', %d, %d, 1, -1, 1, 1)", $node->nid, $node->uid);
}
}
?>
Update subscription by comments:
<?php
$result = db_query('SELECT * FROM {comments} WHERE uid != 1');
while (
$comment = db_fetch_object($result)) {
$result2 = db_query("SELECT * FROM {subscriptions} WHERE module = 'node' AND field = 'nid' AND value = %d AND recipient_uid = %d", $comment->nid, $comment->uid);
if (!mysql_num_rows($result2)) {
db_query("INSERT INTO {subscriptions} (module, field, value, recipient_uid, send_interval, author_uid, send_updates, send_comments)
VALUES ('node', 'nid', %d, %d, 1, -1, 1, 1)", $comment->nid, $comment->uid);
}
}
?>
#2
@Ashford: Go to admin/settings/subscriptions/userdefaults to set your preferred default interval.
Create a subscription and then look inside the {subscriptions} table to see what the corresponding entry looks like. Create more of those for your users.
@beginner: Iterating over all nodes or comments has the potential to time out, leaving the database in an indetermined state. An operation as you suggest should use a single SELECT with a JOIN, so that it can be restarted and will pick up where it left off.
#3
I am looking to subscribe all users of a certain role to a Category (specific Forums) defined on the User defaults settings. With the Custom subscriptions module, this is possible for the Notifications, but not for the Subscriptions module. Is there a way to do it?
#4
No, see above.
#5
I don't understand. It *is* possible using Notifications, so why it isn't with your module?
#6
No such functionality is implemented. If you want to implement it, you're welcome to do so, in a separate add-on module. I will help by answering specific questions and reviewing your code.
You might want to look through the issues queue for previous issues where this has been discussed.
#7
I had a pretty empty subscriptions table and rand the following two queries to set it up for all my users - mine is a pretty unique case but this worked for me:
INSERT INTO subscriptions (recipient_uid)SELECT users.uid
FROM users
UPDATE subscriptionsSET module='node', field='type', value='announcement', send_interval=86400, author_uid=-1, send_updates=1, send_comments=0
This seems like it would be trivial to add to the plugin. I am not a mysql guru, it just seems like it would be pretty basic to just apply a basic setting to all users of a role.
#8
We have a patch in #1249502: Bulk subscribe/unsubscribe operations that would let you do this easily through the GUI, but no one cares enough to test it...
#9
Developer reports a patch is ready for the users to test. See Duplicate Issue http://drupal.org/node/1249502
Don't understand how to do a patch? Look up the Patch Manager module. All you have to do is download the patch file and click a button. Even though Patch Manager also has an Undo Patch button, the experts always recommend that you run updates and patches on a test site first.
#10
I wish I found that sooner, I would have been glad to test it.
#11
There will be a D7 version of the patch, so it's not too late...