[xiph-commits] r14915 - branches/dir.xiph.org/cronjobs

balbinus at svn.xiph.org balbinus at svn.xiph.org
Sun May 18 14:29:34 PDT 2008


Author: balbinus
Date: 2008-05-18 14:29:34 -0700 (Sun, 18 May 2008)
New Revision: 14915

Added:
   branches/dir.xiph.org/cronjobs/rotate_tables.php
Log:
Creation of a table rotation script.

Added: branches/dir.xiph.org/cronjobs/rotate_tables.php
===================================================================
--- branches/dir.xiph.org/cronjobs/rotate_tables.php	                        (rev 0)
+++ branches/dir.xiph.org/cronjobs/rotate_tables.php	2008-05-18 21:29:34 UTC (rev 14915)
@@ -0,0 +1,54 @@
+<?php
+
+// Inclusions
+include_once(dirname(__FILE__).'/../inc/prepend.php');
+
+// Database connection
+$db = DirXiphOrgLogDBC::getInstance();
+
+function makeFutureDate($format = 'Ymd', $days = 1)
+{
+    return date($format, mktime(0, 0, 0, date('m'), date('d') + $days, date('Y')));
+}
+$yesterday = makeFutureDate('Ymd', -1);
+
+/******************************************************************************/
+/**                               API LOG                                    **/
+/******************************************************************************/
+try
+{
+    $sql = 'CREATE INDEX `logged_at` ON `api_log_%s` (`logged_at`);';
+    $sql = sprintf($sql, $yesterday);
+    $db->query($sql);
+    $sql = 'CREATE INDEX `message` ON `api_log_%s` (`message`, `logged_at`);'
+    $sql = sprintf($sql, $yesterday);
+    $db->query($sql);
+}
+catch (SQLException $e)
+{
+    // Mail the error...
+    custom_exception_handler($e);
+    
+    // do nothing.
+}
+
+$sql_pattern = 'CREATE TABLE IF NOT EXISTS `api_log_%s` LIKE `api_log_template`;';
+for ($i = 0 ; $i <= 7 ; $i++)
+{
+    $date = makeFutureDate('Ymd', $i);
+    
+    $sql = sprintf($sql_pattern, $date);
+    try
+    {
+        $db->query($sql);
+    }
+    catch (SQLException $e)
+    {
+        // Mail the error...
+        custom_exception_handler($e);
+        
+        // do nothing.
+    }
+}
+
+?>



More information about the commits mailing list