function subscriptions_queue in Subscriptions 6
Same name and namespace in other branches
- 5.2 subscriptions.module \subscriptions_queue()
- 7 subscriptions.module \subscriptions_queue()
- 2.0.x subscriptions.module.old.php \subscriptions_queue()
Queue events for notifications.
Parameters
$event: Event array.
2 calls to subscriptions_queue()
- subscriptions_content_comment in ./
subscriptions_content.module - Implementation of hook_comment().
- subscriptions_content_nodeapi in ./
subscriptions_content.module - Implementation of hook_nodeapi().
5 string references to 'subscriptions_queue'
- subscriptions_update_3 in ./
subscriptions.install - Database update function 3 for 5.x-2.0 rewrite.
- subscriptions_update_5 in ./
subscriptions.install - Database update function 5 for 5.x-2.0 rewrite.
- subscriptions_update_6101 in ./
subscriptions.install - Database update function 6101: Add the {subscriptions_last_sent} table.
- subscriptions_update_6103 in ./
subscriptions.install - Database update function 6103: Add the new {subscriptions_queue}.suspended and {subscriptions_user}.suspended columns.
- subscriptions_update_6104 in ./
subscriptions.install - Database update function 6104: Remove the 'mail' column.
File
- ./
subscriptions.module, line 308 - Subscriptions module.
Code
function subscriptions_queue($event) {
global $user;
if (isset($event['node']->nid) && strpos(' ' . variable_get('subscriptions_blocked_nodes', '') . ' ', ' ' . $event['node']->nid . ' ')) {
return;
}
$event += array(
'uid' => $user->uid,
'load_args' => '',
);
foreach (module_implements('subscriptions_queue_alter') as $module) {
$function = $module . '_subscriptions_queue_alter';
$function($event);
if (empty($event)) {
return;
// $event was cleared, forget it
}
}
if (is_array($event['load_args'])) {
$event['load_args'] = serialize($event['load_args']);
}
if (!empty($event['noqueue_uids'])) {
// Allow hook_subscriptions_queue_alter() modules to set uids that won't get any notifications queued:
$noqueue_uids_where = "s.recipient_uid NOT IN (" . implode(', ', array_fill(0, count($event['noqueue_uids']), '%d')) . ")";
}
foreach (module_implements('subscriptions') as $subs_module) {
$subs_module_query = module_invoke($subs_module, 'subscriptions', 'queue', $event);
// Allow other modules to alter the data.
drupal_alter('subscriptions_queue_guery', $subs_module_query);
if (!isset($subs_module_query)) {
continue;
}
foreach ($subs_module_query as $module => $module_query) {
foreach ($module_query as $field => $query) {
$join = empty($query['join']) ? '' : $query['join'];
$where = empty($query['where']) ? array() : array(
$query['where'],
);
$args = array(
$event['load_function'],
$event['load_args'],
$event['is_new'],
$module,
$field,
);
$groupby = empty($query['groupby']) ? '' : $query['groupby'];
// author-specific subscriptions trigger on comments, when the node author is subscribed to:
$args[] = $module == 'node' && $event['type'] == 'comment' && isset($event['node']->uid) ? $event['node']->uid : $event['uid'];
if (!empty($query['value'])) {
$where[] = "s.value = '%s'";
$args[] = $query['value'];
}
if (!empty($query['args'])) {
$args = array_merge($args, $query['args']);
}
if ($user->uid && !_subscriptions_get_setting('send_self', $user)) {
$where[] = "s.recipient_uid != %d";
$args[] = $user->uid;
}
if (!empty($event['noqueue_uids'])) {
$where[] = $noqueue_uids_where;
$args = array_merge($args, $event['noqueue_uids']);
}
$conditions = implode(' AND ', $where);
$sql = "\n INSERT INTO {subscriptions_queue} (uid, name, language, module, field, value, author_uid, send_interval, digest, last_sent, load_function, load_args, is_new, suspended)\n SELECT u.uid, u.name, u.language, s.module, s.field, s.value, s.author_uid, s.send_interval, su.digest, COALESCE(sls.last_sent, 0) last_sent, '%s', '%s', '%d', su.suspended\n FROM {subscriptions} s\n INNER JOIN {subscriptions_user} su ON s.recipient_uid = su.uid\n INNER JOIN {users} u ON su.uid = u.uid\n {$join}\n LEFT JOIN {subscriptions_last_sent} sls ON su.uid = sls.uid AND s.send_interval = sls.send_interval\n WHERE\n s.module = '%s' AND\n s.field = '%s' AND\n s.author_uid IN (%d, -1) AND {$conditions}\n {$groupby}";
$result = db_query($sql, $args);
$affected_rows = db_affected_rows();
/* for debugging:
$sql = db_prefix_tables($sql);
_db_query_callback($args, TRUE);
$sql = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $sql);
drupal_set_message("$sql<br />". $affected_rows .' row(s) inserted.');
/**/
}
}
}
}