? project_168009_1.patch
Index: release/project-release-serve-history.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/release/project-release-serve-history.php,v
retrieving revision 1.8
diff -u -p -r1.8 project-release-serve-history.php
--- release/project-release-serve-history.php	14 Sep 2007 16:17:55 -0000	1.8
+++ release/project-release-serve-history.php	21 Mar 2008 18:59:49 -0000
@@ -99,6 +99,19 @@ if (isset($_GET['site_key'])) {
     $site_key = $_GET['site_key'];
     $project_version = isset($_GET['version']) ? $_GET['version'] : '';
 
+    // In D6, we added support for Drupal to run behind a proxy, including a
+    // new proxy-aware function to get the IP address of the incoming
+    // request. Although this code is not in D5, drupal.org itself is running
+    // a patched version of core and is behind a proxy. So, even though this
+    // is the D5 version of the script, we check for this function and use it
+    // if it exists, to get proper results on drupal.org itself.
+    if (function_exists('ip_address')) {
+      $ip_addr = ip_address();
+    }
+    else {
+      $ip_addr = $_SERVER['REMOTE_ADDR'];
+    }
+
     // Compute a GMT timestamp for begining of the day. getdate() is
     // affected by the server's timezone so we need to cancel it out.
     $now = time();
@@ -106,10 +119,10 @@ if (isset($_GET['site_key'])) {
     $timestamp = gmmktime(0, 0, 0, $time_parts['mon'], $time_parts['mday'], $time_parts['year']);
 
     if (db_result(db_query("SELECT COUNT(*) FROM {project_usage_raw} WHERE project_uri = '%s' AND timestamp = %d AND site_key = '%s'", $project_name, $timestamp, $site_key))) {
-      db_query("UPDATE {project_usage_raw} SET api_version = '%s', project_version = '%s' WHERE project_uri = '%s' AND timestamp = %d AND site_key = '%s'", $api_version, $project_version, $project_name, $timestamp, $site_key);
+      db_query("UPDATE {project_usage_raw} SET api_version = '%s', project_version = '%s', ip_addr = '%s' WHERE project_uri = '%s' AND timestamp = %d AND site_key = '%s'", $api_version, $project_version, $ip_addr, $project_name, $timestamp, $site_key);
     }
     else {
-      db_query("INSERT INTO {project_usage_raw} (project_uri, timestamp, site_key, api_version, project_version) VALUES ('%s', %d, '%s', '%s', '%s')", $project_name, $timestamp, $site_key, $api_version, $project_version);
+      db_query("INSERT INTO {project_usage_raw} (project_uri, timestamp, site_key, api_version, project_version, ip_addr) VALUES ('%s', %d, '%s', '%s', '%s', '%s')", $project_name, $timestamp, $site_key, $api_version, $project_version, $ip_addr);
     }
   }
 }
Index: usage/project_usage.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/usage/project_usage.install,v
retrieving revision 1.3
diff -u -p -r1.3 project_usage.install
--- usage/project_usage.install	14 Sep 2007 16:17:55 -0000	1.3
+++ usage/project_usage.install	21 Mar 2008 18:59:49 -0000
@@ -15,6 +15,7 @@ function project_usage_install() {
           pid int unsigned NOT NULL default '0',
           nid int unsigned NOT NULL default '0',
           tid int unsigned NOT NULL default '0',
+          ip_addr varchar(16) NOT NULL default '',
           PRIMARY KEY (timestamp, project_uri, site_key)
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
       db_query("CREATE TABLE IF NOT EXISTS {project_usage_day} (
@@ -23,6 +24,7 @@ function project_usage_install() {
           pid int unsigned NOT NULL default '0',
           nid int unsigned NOT NULL default '0',
           tid int unsigned NOT NULL default '0',
+          ip_addr varchar(16) NOT NULL default '',
           PRIMARY KEY (timestamp, site_key, pid)
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
       db_query("CREATE TABLE IF NOT EXISTS {project_usage_week_project} (
@@ -99,3 +101,18 @@ function project_usage_update_5000() {
 
   return $ret;
 }
+
+/**
+ * Add a ip_addr field to {project_usage_raw} and {project_usage_day}.
+ */
+function project_usage_update_5001() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {project_usage_raw} ADD COLUMN ip_addr varchar(16) NOT NULL default '' AFTER tid");
+      $ret[] = update_sql("ALTER TABLE {project_usage_day} ADD COLUMN ip_addr varchar(16) NOT NULL default '' AFTER tid");
+      break;
+  }
+  return $ret;
+}
Index: usage/project_usage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/usage/project_usage.module,v
retrieving revision 1.6
diff -u -p -r1.6 project_usage.module
--- usage/project_usage.module	14 Sep 2007 16:17:55 -0000	1.6
+++ usage/project_usage.module	21 Mar 2008 18:59:49 -0000
@@ -147,7 +147,7 @@ function project_usage_process_daily() {
 
   // Move usage records with project node IDs into the daily table and remove
   // the rest.
-  db_query("INSERT INTO {project_usage_day} (timestamp, site_key, pid, nid, tid) SELECT timestamp, site_key, pid, nid, tid FROM {project_usage_raw} WHERE timestamp < %d AND pid <> 0", $timestamp);
+  db_query("INSERT INTO {project_usage_day} (timestamp, site_key, pid, nid, tid, ip_addr) SELECT timestamp, site_key, pid, nid, tid, ip_addr FROM {project_usage_raw} WHERE timestamp < %d AND pid <> 0", $timestamp);
   db_query("DELETE FROM {project_usage_raw} WHERE timestamp < %d", $timestamp);
   watchdog('project_usage', t('Moved usage from raw to daily.'));
 
