[pLog-svn] r4734 - plog/branches/lifetype-1.1.6/class/dao

oscar at devel.lifetype.net oscar at devel.lifetype.net
Wed Feb 14 03:56:17 EST 2007


Author: oscar
Date: 2007-02-14 03:56:17 -0500 (Wed, 14 Feb 2007)
New Revision: 4734

Modified:
   plog/branches/lifetype-1.1.6/class/dao/bayesianfilterinfos.class.php
Log:
Fix backported from LT 1.2.

Modified: plog/branches/lifetype-1.1.6/class/dao/bayesianfilterinfos.class.php
===================================================================
--- plog/branches/lifetype-1.1.6/class/dao/bayesianfilterinfos.class.php	2007-02-14 03:20:50 UTC (rev 4733)
+++ plog/branches/lifetype-1.1.6/class/dao/bayesianfilterinfos.class.php	2007-02-14 08:56:17 UTC (rev 4734)
@@ -26,7 +26,23 @@
         {
         	$query = "SELECT * FROM ". $this->getPrefix() . "bayesian_filter_info WHERE blog_id = $blogId";
 
-            return $this->getBayesianFilterInfoFromQuery($query);
+            $result = $this->Execute($query);
+
+            if( !$result )
+            	return false;
+
+			if( $result->RowCount() == 0 ) {
+				// this is a bit of an special case... for whatever reason there is no spam information
+				// for this blog so we have to calculate it now...
+				$this->insertLate( $blogId );
+
+				// and then we call ourselves again
+				return( $this->getBlogBayesianFilterInfo( $blogId ));				
+			}
+
+            $row = $result->FetchRow();
+            $result->Close();			
+            return $this->_mapRowToObject($row);
         }
 
         /**
@@ -51,7 +67,7 @@
         {
         	return new BayesianFilterInfo($row["blog_id"], $row["total_spam"], $row["total_nonspam"], $row["id"]);
         }
-        
+
         /**
         * -- Add function info here --
         */
@@ -59,7 +75,7 @@
         {
             return $this->_incTotal($id, "total_spam");
         }
-        
+
         /**
         * -- Add function info here --
         */
@@ -67,18 +83,18 @@
         {
             return $this->_incTotal($id, "total_nonspam");
         }
-        
+
         /**
         * -- Add function info here --
         */
         function _incTotal($id, $field)
-        {
+        {	
         	$query = "UPDATE " . $this->getPrefix() . "bayesian_filter_info SET " .
                      "$field = $field + 1 WHERE id=$id;";
-            
+
             return $this->updateFromQuery($query);
         }
-        
+
         /**
         * -- Add function info here --
         */
@@ -86,7 +102,7 @@
         {
             return $this->_decTotal($id, "total_spam");
         }
-        
+
         /**
         * -- Add function info here --
         */
@@ -94,7 +110,7 @@
         {
             return $this->_decTotal($id, "total_nonspam");
         }
-        
+
         /**
         * -- Add function info here --
         */
@@ -102,10 +118,10 @@
         {
         	$query = "UPDATE " . $this->getPrefix() . "bayesian_filter_info SET " .
                      "$field = $field - 1 WHERE id=$id;";
-            
+
             return $this->updateFromQuery($query);
         }
-        
+
         /**
         * -- Add function info here --
         */
@@ -118,7 +134,7 @@
 
             return true;
         }
-        
+
         /**
         * -- Add function info here --
         */
@@ -136,10 +152,34 @@
         /**
         * -- Add function info here --
         */
+        function insertLate($blogId )
+        {
+			$currentStats = "SELECT SUM(spam_occurrences) AS total_spam, 
+			                        SUM(nonspam_occurrences) AS total_nonspam 
+			                 FROM ".$this->getPrefix()."bayesian_tokens 
+			                 WHERE blog_id = $blogId";
+			$result = $this->Execute( $currentStats );
+
+			if( $result ) {
+				$row = $result->FetchRow();
+				isset( $row["total_spam"]) ? $totalSpam = $row["total_spam"] : $totalSpam = 0;
+				isset( $row["total_nonspam"]) ? $totalNonSpam = $row["total_nonspam"] : $totalNonSpam = 0;
+			}
+			else {
+				$totalSpam = 0;
+				$totalNonSpam = 0;
+			}
+
+			return( $this->insert( $blogId, $totalSpam, $totalNonspam ));
+        }
+
+        /**
+        * -- Add function info here --
+        */
         function deleteBayesianFilterInfoByBlogId( $blogId )
         {
             $query = "DELETE FROM " . $this->getPrefix() . "bayesian_filter_info WHERE blog_id=$blogId";
-            
+
             $result = $this->Execute($query);
 
             if(!$result)



More information about the pLog-svn mailing list