A recent migration has caused us to scrap the D6 Notifications module family and install the D7 Subscriptions module family instead. Now we have to recreate the custom subscriptions for a couple hundred users. Is there an easy button for either of these situations:

  1. Set all users as subscribed to their own nodes?
  2. Set all users as subscribed to their comments (or to the original post of their comment)?

I have already recreated the old subscriptions based on taxonomy terms and content types. That part was dreamy, thanks for thr feature BTW.

Comments

salvis’s picture

No, sorry, there's no such feature, but this shouldn't be too hard to do in SQL.

seaneffel’s picture

Ok, fair enough. I guess I would have to set some value for each node and/or comment?

Last question, is there a feature for users to unsubscribe themselves from all nodes, rather than hit each of their own nodes one by one?

salvis’s picture

Yes, exactly. Create a Thread subscription as you want to have them, look it up in the {subscriptions} table (they are of the node/nid/NID type), and create one of those for each thread (NID).

Would you please post the query here that you'll end up using, as an example for others?

(Please use new issues for new questions in order to keep the issues focused.)
The Thread Subscriptions page has checkboxes (including an all-checkbox) for unsubscribing.

seaneffel’s picture

I am not a MySQL genius but if I do get a query together then I'll post it here. Maybe, just maybe, it can be the start of a feature for the module. On one hand, I know it's rude to sign user up for emails they didn't explicitly say they wanted. On the other hand, this feature would be nice to return subscriptions to users who lost them in a migration (such as me).

mrded’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Issue summary: View changes

Can be done with similar update:

/**
 * Subscribe users to forum posts.
 */
function HOOK_update_7010(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['max'] = db_query("SELECT COUNT(DISTINCT nid) FROM {node}  WHERE type='forum'")->fetchField();
  }

  $nids = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('type', 'forum')
    ->range($sandbox['progress'], 10)->execute()->fetchCol();

  foreach ($nids as $nid) {
    $uids = db_select('comment', 'c')
      ->fields('c', array('uid'))
      ->condition('c.nid', $nid)
      ->distinct()->execute()->fetchCol();

    foreach (user_load_multiple($uids) as $user) {
      subscriptions_write_subscription('node', 'nid', $nid, -1, $user->uid, _subscriptions_get_setting('send_interval', $user), 1, 1);
    }

    $sandbox['progress']++;
  }

  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);

  return t('The update did what it was supposed to do.');
}
salvis’s picture

Status: Active » Closed (outdated)