You are here

function notifications_process_pull in Notifications 5

Support of pull messaging

Return value

Array of pending messages

See also

messaging_pull_pending()

1 call to notifications_process_pull()
Notifications_Content_Tests::testNotificationsContent in tests/notifications_content.test
Play with creating, retrieving, deleting a pair subscriptions

File

./notifications.cron.inc, line 62

Code

function notifications_process_pull($method, $users, $limit = 0, $delete = FALSE) {
  $messages = array();
  $maxsqid = 0;

  // Just fetches row in creation order de-duping same events on the step
  $sql = "SELECT uid, eid, module, MIN(sid) AS sid, MAX(sqid) AS sqid FROM {notifications_queue} ";
  $sql .= "WHERE send_method = '%s' AND uid IN (%s) GROUP BY uid, eid, module ORDER BY sqid";
  $str_uids = implode(',', $users);
  if ($limit) {
    $result = db_query_range($sql, $method, $str_uids, 0, $limit);
  }
  else {
    $result = db_query($sql, $method, $str_uids);
  }

  // Fetch and prepare messages
  while ($queue = db_fetch_object($result)) {
    $maxsqid = $queue->squid;
    $account = notifications_callback($queue->module, 'load_user', $queue->uid);
    $event = notifications_load_event($queue->eid);

    // Access control for event objects
    if (notifications_callback($queue->module, 'user_allowed', 'event', $account, $event)) {
      $subscriptions = array(
        $queue->sid,
      );
      $message = notifications_callback($queue->module, 'process_message', $account, $event, $subscriptions, $method);
      $message['uid'] = $queue->uid;
      $message['from'] = $event->uid;
      $messages[] = $message;
    }
  }

  // Delete returned rows
  if ($messages && $delete) {
    db_query("DELETE FROM {notifications_queue} WHERE sqid < %d AND send_method = '%s' AND uid IN (%s)", $maxsqid, $method, $str_uids);
  }

  // Return collected messages;
  return $messages;
}