[xiph-commits] r14852 - branches/dir.xiph.org/inc

balbinus at svn.xiph.org balbinus at svn.xiph.org
Sat May 10 10:16:37 PDT 2008


Author: balbinus
Date: 2008-05-10 10:16:37 -0700 (Sat, 10 May 2008)
New Revision: 14852

Modified:
   branches/dir.xiph.org/inc/lib.apilog.php
Log:
Let's do some rotating logs on refused adds too.

Modified: branches/dir.xiph.org/inc/lib.apilog.php
===================================================================
--- branches/dir.xiph.org/inc/lib.apilog.php	2008-05-10 14:53:27 UTC (rev 14851)
+++ branches/dir.xiph.org/inc/lib.apilog.php	2008-05-10 17:16:37 UTC (rev 14852)
@@ -80,14 +80,28 @@
     public static function serverRefused($reason, $listen_url = false)
     {
         $db = DirXiphOrgDBC::getInstance();
-        $sql = 'INSERT INTO `refused_log` (`reason`, `remote_ip`, `listen_url`, `listen_url_hash`) '
-              .'VALUES (%d, INET_ATON("%s"), "%s", %u);';
-        $sql = sprintf($sql, intval($reason),
-                             array_key_exists('REMOTE_ADDR', $_SERVER)
-                                ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',
-                             $listen_url != false ? mysql_real_escape_string($listen_url) : '',
-                             $listen_url != false ? sprintf('%u', crc32($listen_url)) : 0);
-        $db->noReturnQuery($sql);
+        
+        try
+        {
+            $db->noReturnQuery('SELECT 0 INTO @prev_id;');
+            $db->noReturnQuery('UPDATE refused_log_cpt SET `id_log` = ((`id_log` MOD 5000) + 1) WHERE @prev_id := `id_log`;');
+            $res = $db->singleQuery('SELECT @prev_id AS id;');
+            $id = $res->current('id');
+            
+            $sql = 'REPLACE INTO `refused_log`  (`id`, `reason`, `remote_ip`, `listen_url`, `listen_url_hash`) '
+              .'VALUES (%d, %d, INET_ATON("%s"), "%s", %u);';
+             $sql = sprintf($sql, $id,
+                                  intval($reason),
+                                  array_key_exists('REMOTE_ADDR', $_SERVER)
+                                   ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',
+                                 $listen_url != false ? mysql_real_escape_string($listen_url) : '',
+                                 $listen_url != false ? sprintf('%u', crc32($listen_url)) : 0);
+            $db->noReturnQuery($sql);
+        }
+        catch (SQLNoResultException $e)
+        {
+            throw new APIException("Unable to get a new api_log id.");
+        }
     }
 }
 



More information about the commits mailing list