Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
maybe this way can slove the
KNOWN ISSUE: Any users not available to the UI will be unsubscribed from
* content they may subscribe to using some other method.
After send messages, re-subscribe deleted subscribes, unsubscribe added subscribes.
/**
* Implements hook_action_info().
*/
function druedu_notifications_team_action_info() {
return array(
'druedu_notifications_team_resubscribe_action' => array(
'type' => 'notifications',
'label' => t('After send messages, re-subscribe deleted subscribes, unsubscribe added subscribes.'),
'configurable' => FALSE,
'behavior' => array('sends_notification'),
'triggers' => array('node_update'),
),
);
}
/**
* After send messages, re-subscribe deleted subscribes, unsubscribe added subscribes.
*/
function druedu_notifications_team_resubscribe_action($node, $context = array()) {
if(isset($context['node'])){
$node = $context['node'];
$changed_subscribes = $node->notifications_team_all;
$default_subscribes = druedu_notifications_team_get_subscriptions($node->nid, $reset = FALSE);
$deleted_subs = array_diff($default_subscribes,$changed_subscribes);
$added_subs = array_filter(array_diff($changed_subscribes,$default_subscribes));
foreach ($deleted_subs as $key => $uid) {
# resubscribe
// dpm($deleted_subs,'re-subscribe-$deleted_subs');
$subscription = notifications_subscription('content_thread')
->instance()
->set_user(user_load($uid))
->set_node($node);
notifications_save_subscription($subscription);
}
foreach ($added_subs as $key => $uid) {
# unsubscribe
// dpm($added_subs,'unsubscribe-$added_subs');
Notifications_Subscription::delete_multiple(array('uid' => $uid), array('node:nid' => $node->nid), FALSE);
}
}
}