[pLog-svn] r4669 - in plog/branches/lifetype-1.2/class: bayesian dao

oscar at devel.lifetype.net oscar at devel.lifetype.net
Fri Feb 2 07:36:58 EST 2007


Author: oscar
Date: 2007-02-02 07:36:57 -0500 (Fri, 02 Feb 2007)
New Revision: 4669

Modified:
   plog/branches/lifetype-1.2/class/bayesian/bayesianfiltercore.class.php
   plog/branches/lifetype-1.2/class/dao/bayesianfilterinfos.class.php
Log:
Fixed an issue with the bayesian filter, caused by some blogs that don't have a row in the lt_bayesian_filter_info table for some reason... I can't explain why those blogs are missing their row in there but this fix should generate a new one with the right values. Some of you might have noticed an abnormally big tmp/sql_error.log with plenty of errors related to the bayesians ilter, if so, this is the fix.

I'm taking my chances and fixing this in 1.2 instead of 1.1.6, hopefully there won't be a need for a 1.1.6 :)


Modified: plog/branches/lifetype-1.2/class/bayesian/bayesianfiltercore.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/bayesian/bayesianfiltercore.class.php	2007-02-02 10:17:18 UTC (rev 4668)
+++ plog/branches/lifetype-1.2/class/bayesian/bayesianfiltercore.class.php	2007-02-02 12:36:57 UTC (rev 4669)
@@ -81,7 +81,7 @@
                 $bayesianTokens->incSpamOccurrencesFromTokensArray($blogId, $tokens, $totalSpam, $totalNonSpam);
             }
             else
-            {
+            {	
                 $totalNonSpam++;
                 $bayesianFilterInfos->incTotalNonSpam($bayesianFilterInfo->getId());
                 $bayesianTokens->incNonSpamOccurrencesFromTokensArray($blogId, $tokens, $totalSpam, $totalNonSpam);

Modified: plog/branches/lifetype-1.2/class/dao/bayesianfilterinfos.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/bayesianfilterinfos.class.php	2007-02-02 10:17:18 UTC (rev 4668)
+++ plog/branches/lifetype-1.2/class/dao/bayesianfilterinfos.class.php	2007-02-02 12:36:57 UTC (rev 4669)
@@ -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);
         }
 
         /**
@@ -72,7 +88,7 @@
         * -- Add function info here --
         */
         function _incTotal($id, $field)
-        {
+        {	
         	$query = "UPDATE " . $this->getPrefix() . "bayesian_filter_info SET " .
                      "$field = $field + 1 WHERE id=$id;";
             
@@ -136,6 +152,30 @@
         /**
         * -- 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";



More information about the pLog-svn mailing list