You are here

function notifications_queue in Notifications 5

Same name and namespace in other branches
  1. 6.4 notifications.module \notifications_queue()
  2. 6 notifications.module \notifications_queue()
  3. 6.2 notifications.module \notifications_queue()
  4. 6.3 notifications.module \notifications_queue()

Queue events for notifications

Parameters

$event: Event array.

1 call to notifications_queue()
notifications_event in ./notifications.module
Process subscriptions events
2 string references to 'notifications_queue'
notifications_delete_subscription in ./notifications.module
Delete subscription and clean up related data.
notifications_delete_subscriptions in ./notifications.module
Delete multiple subscriptions and clean up related data (pending notifications, fields).

File

./notifications.module, line 282
Notifications module

Code

function notifications_queue($event) {
  global $notifications_send_inmediate;

  // Build query fields for this event type. If no arguments retrieved, skip this step
  if ($query_args = notifications_module_information('query', 'event', $event->type, $event)) {
    $query['args'] = array(
      $event->eid,
      $event->created,
      $event->type,
    );
    foreach ($query_args as $query_params) {
      $query = notifications_query_build($query_params, $query);
    }

    // We throw in all the conditions and check the number of matching conditions
    // that must be equal to the subscription conditions number
    $sql = 'INSERT INTO {notifications_queue} (uid, sid, module, eid, send_interval, send_method, cron, created, conditions) ' . 'SELECT DISTINCT s.uid, s.sid, s.module, %d, s.send_interval, s.send_method, s.cron, %d, s.conditions ' . 'FROM {notifications} s INNER JOIN {notifications_fields} f ON s.sid = f.sid ' . implode(' ', $query['join']);
    $sql .= " WHERE s.status = 1 AND s.event_type = '%s' AND s.send_interval >= 0 AND ((" . implode(') OR (', $query['where']) . ')) ';

    // Add one more condition if we don't send notifications on own posts
    if (!variable_get('notifications_sendself', 0)) {
      $sql .= 'AND s.uid != %d ';
      $query['args'][] = $event->uid;
    }

    // Some group by fields are not really needed but added for pgsql compatibility
    $sql .= 'GROUP BY s.uid, s.sid, s.module, s.send_interval, s.send_method, s.cron, s.conditions HAVING s.conditions = count(f.sid)';
    db_query($sql, $query['args']);
  }

  // Modules can do cleanup operations or modify the queue
  notifications_module_invoke('event queued', $event);

  // If immediate sending enabled, store eid for sending on page exit.
  if (variable_get('notifications_send_immediate', 0)) {
    $notifications_send_inmediate[] = $event->eid;
  }
}