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

balbinus at svn.xiph.org balbinus at svn.xiph.org
Sat May 10 12:56:15 PDT 2008


Author: balbinus
Date: 2008-05-10 12:56:15 -0700 (Sat, 10 May 2008)
New Revision: 14859

Modified:
   branches/dir.xiph.org/cronjobs/check_servers.php
   branches/dir.xiph.org/cronjobs/prune_mountpoints.php
Log:
Clean more 'cleanly', using objects. Should make the last part of prune_mountpoints useless.

Modified: branches/dir.xiph.org/cronjobs/check_servers.php
===================================================================
--- branches/dir.xiph.org/cronjobs/check_servers.php	2008-05-10 19:37:01 UTC (rev 14858)
+++ branches/dir.xiph.org/cronjobs/check_servers.php	2008-05-10 19:56:15 UTC (rev 14859)
@@ -114,9 +114,17 @@
             // TODO: remove the stream
             echo("Delete it! ".$res->current('listen_url')."\n");
             
-            $sql = 'UPDATE `server` SET `checked` = 2, `checked_at` = NOW() WHERE `id` = %d;';
+/*            $sql = 'UPDATE `server` SET `checked` = 2, `checked_at` = NOW() WHERE `id` = %d;';
             $sql = sprintf($sql, $res->current('id'));
-            $db->noReturnQuery($sql);
+            $db->noReturnQuery($sql);*/
+            $server = Server::retrieveByPk($res->current('id'));
+            $mp_id = $server->getMountpointId();
+            $mountpoint = Mountpoint::retrieveByPk($mp_id);
+            $server->remove();
+            if (!$mountpoint->hasLinkedServers())
+            {
+            	$mountpoint->remove();
+            }
         }
         
         $res->next();

Modified: branches/dir.xiph.org/cronjobs/prune_mountpoints.php
===================================================================
--- branches/dir.xiph.org/cronjobs/prune_mountpoints.php	2008-05-10 19:37:01 UTC (rev 14858)
+++ branches/dir.xiph.org/cronjobs/prune_mountpoints.php	2008-05-10 19:56:15 UTC (rev 14859)
@@ -10,10 +10,32 @@
 $memcache = DirXiphOrgMCC::getInstance();
 
 // Old stuff that "timeouted"
-$db->noReturnQuery('DELETE FROM `server` WHERE `last_touched_at` <= DATE_SUB(NOW(), INTERVAL 10 MINUTE);');
+try
+{
+	$toDelete = $db->selectQuery('SELECT `id` FROM `server` WHERE `last_touched_at` <= DATE_SUB(NOW(), INTERVAL 10 MINUTE);');
+	
+	while (!$toDelete->endOf())
+	{
+        $server = Server::retrieveByPk($res->current('id'));
+        $mp_id = $server->getMountpointId();
+        $mountpoint = Mountpoint::retrieveByPk($mp_id);
+        $server->remove();
+        if (!$mountpoint->hasLinkedServers())
+        {
+        	$mountpoint->remove();
+        }
+		
+		// Next!
+		$toDelete->next();
+	}
+}
+catch (SQLNoResultException $e)
+{
+	// it's ok, everything's clean.
+}
 
 // Useless mountpoint
-try
+/*try
 {
     $toDelete = $db->selectQuery('SELECT m.`id` AS `mountpoint_id`, s.`id` FROM `mountpoint` AS m LEFT OUTER JOIN `server` AS s ON m.`id` = s.`mountpoint_id` HAVING s.`id` IS NULL;');
     while (!$toDelete->endOf())
@@ -37,12 +59,12 @@
 }
 catch (SQLNoResultException $e)
 {
-}
+}*/
 
 // Now prune the tags
-$sql = 'DELETE FROM `tag` WHERE `id` IN (SELECT `tag_id` FROM `tag_cloud` WHERE `tag_usage` <= 0);';
+/*$sql = 'DELETE FROM `tag` WHERE `id` IN (SELECT `tag_id` FROM `tag_cloud` WHERE `tag_usage` <= 0);';
 $db->noReturnQuery($sql);
-$sql = 'DELETE FROM `tag_cloud` WHERE `tag_usage` <= 0;';
+$sql = 'DELETE FROM `tag_cloud` WHERE `tag_usage` <= 0;'; // impossible since the field is UNSIGNED :(
 $db->noReturnQuery($sql);
 try
 {
@@ -60,6 +82,6 @@
 }
 catch (SQLNoResultException $e)
 {
-}
+}*/
 
 ?>



More information about the commits mailing list