Fix for custom long poll service

  1. $counter = 0;
  2.   global $user;
  3.   while(!$response) {
  4.     $query = db_query("SELECT node.nid AS nid,
  5.  users.name AS users_name,
  6.  users.uid AS users_uid,
  7.  node.title AS node_title,
  8.  node_revisions.body AS node_revisions_body,
  9.  node_revisions.format AS node_revisions_format,
  10.  node.created AS node_created
  11.  FROM node node
  12.  LEFT JOIN history history_user ON node.nid = history_user.nid AND history_user.uid = %d
  13.  LEFT JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid
  14.  LEFT JOIN og_ancestry og_ancestry ON node.nid = og_ancestry.nid
  15.  INNER JOIN users users ON node.uid = users.uid
  16.  LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
  17.  WHERE (node.type in ('chat'))
  18.  AND ((history_user.timestamp IS NULL
  19.  AND (node.changed > (%d - 2592001)
  20.  OR node_comment_statistics.last_comment_timestamp > (%d - 2592001)))
  21.  OR history_user.timestamp < node.changed
  22.  OR history_user.timestamp < node_comment_statistics.last_comment_timestamp)
  23.  AND (og_ancestry.group_nid = %d) ORDER BY node_created DESC", $user->uid, time(), time(), $args[0]);
  24.      $resultcounter = 0;
  25.      while ($result = db_fetch_object($query)) {
  26.        $response->chat[] = $result;
  27.        node_tag_new($result->nid);
  28.        $resultcounter++;
  29.      }
  30.     $query = db_query("SELECT node.nid AS nid,
  31.  users.name AS users_name,
  32.  node.title AS node_title,
  33.  node_revisions.body AS node_revisions_body,
  34.  node_revisions.format AS node_revisions_format,
  35.  node.created AS node_created
  36.  FROM node node
  37.  LEFT JOIN history history_user ON node.nid = history_user.nid AND history_user.uid = %d
  38.  LEFT JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid
  39.  LEFT JOIN og_ancestry og_ancestry ON node.nid = og_ancestry.nid
  40.  INNER JOIN users users ON node.uid = users.uid
  41.  LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
  42.  WHERE (node.type in ('command'))
  43.  AND ((history_user.timestamp IS NULL
  44.  AND (node.changed > (%d - 2592001)
  45.  OR node_comment_statistics.last_comment_timestamp > (%d - 2592001)))
  46.  OR history_user.timestamp < node.changed
  47.  OR history_user.timestamp < node_comment_statistics.last_comment_timestamp)
  48.  AND (og_ancestry.group_nid = %d) ORDER BY node_created DESC", $user->uid, time(), time(), $args[0]);
  49.      $resultcounter = 0;
  50.      while ($result = db_fetch_object($query)) {
  51.        $response->command[] = $result;
  52.        node_tag_new($result->nid);
  53.        $resultcounter++;
  54.      }
  55.      $query = db_query("SELECT node.nid AS nid,
  56.   users.name AS users_name,
  57.   node.title AS node_title,
  58.   node_revisions.body AS node_revisions_body,
  59.   node_revisions.format AS node_revisions_format,
  60.   node_data_field_author.field_author_value AS node_data_field_author_field_author_value,
  61.   node_data_field_author.nid AS node_data_field_author_nid,
  62.   node.type AS node_type,
  63.   node_data_field_author.field_dots_value AS node_data_field_author_field_dots_value,
  64.   node_data_field_author.field_type_value AS node_data_field_author_field_type_value,
  65.   node_data_field_author.field_xpos_value AS node_data_field_author_field_xpos_value,
  66.   node_data_field_author.field_ypos_value AS node_data_field_author_field_ypos_value,
  67.   node_data_field_author.field_deleted_value AS node_data_field_author_field_deleted_value,
  68.   node_data_field_author.field_cluster_value AS node_data_field_author_field_cluster_value,
  69.   node.created AS node_created
  70.  FROM node node
  71.  LEFT JOIN history history_user ON node.nid = history_user.nid AND history_user.uid = %d
  72.  LEFT JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid
  73.  LEFT JOIN og_ancestry og_ancestry ON node.nid = og_ancestry.nid
  74.  INNER JOIN users users ON node.uid = users.uid
  75.  LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
  76.  LEFT JOIN content_type_memo node_data_field_author ON node.vid = node_data_field_author.vid
  77.  WHERE (node.type in ('memo'))
  78.  AND ((history_user.timestamp IS NULL
  79.  AND (node.changed > (%d - 2592001)
  80.  OR node_comment_statistics.last_comment_timestamp > (%d - 2592001)))
  81.  OR history_user.timestamp < node.changed
  82.  OR history_user.timestamp < node_comment_statistics.last_comment_timestamp)
  83.  AND (og_ancestry.group_nid = %d) ORDER BY node_created DESC", $user->uid, time(), time(), $args[0]);
  84.      $resultcounter = 0;
  85.      while ($result = db_fetch_object($query)) {
  86.        $response->memo[] = $result;
  87.        node_tag_new($result->nid);
  88.        $resultcounter++;
  89.      }
  90.      $counter++;
  91.      if ($counter > 20) {
  92.        return array();
  93.      }
  94.     sleep(1);
  95.   }
  96.   if ($response) {
  97.     return $response;
  98.   }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.