[pLog-svn] r3623 - plog/trunk/class/dao

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Jun 19 19:35:10 GMT 2006


Author: oscar
Date: 2006-06-19 19:35:09 +0000 (Mon, 19 Jun 2006)
New Revision: 3623

Modified:
   plog/trunk/class/dao/commentscommon.class.php
Log:
some fixes for the fix regarding purging spam comments


Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php	2006-06-19 11:36:51 UTC (rev 3622)
+++ plog/trunk/class/dao/commentscommon.class.php	2006-06-19 19:35:09 UTC (rev 3623)
@@ -62,7 +62,8 @@
 				$blog = $article->getBlogInfo();
 				if( $comment->getType() == COMMENT_TYPE_COMMENT ) {
         			$article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments', 
-        		    	                                          'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
+        		    	                                          'article_id = '.$article->getId().
+                                                                  ' AND status = '.COMMENT_STATUS_NONSPAM.
         		        	                                      ' AND type = '.$comment->getType()));
         			$article->setTotalComments($this->getNumItems( $this->getPrefix().'articles_comments', 
         		    	                                 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
@@ -71,7 +72,8 @@
 				}
 				else {
         			$article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments', 
-        		    	                                          'article_id = '.$article->getId().' AND status = '.COMMENT_STATUS_NONSPAM.
+        		    	                                          'article_id = '.$article->getId().
+                                                                  ' AND status = '.COMMENT_STATUS_NONSPAM.
         		        	                                      ' AND type = '.$comment->getType()));
         			$article->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments', 
         		    	                                 'article_id = '.$article->getId().' AND type = '.$comment->getType()));
@@ -357,11 +359,8 @@
 			if( $type != COMMENT_TYPE_ANY )
 				$query .= " AND type = '".Db::qstr($type)."'";
 			$query .= " GROUP BY article_id, type";
+			$resultArticles = $this->Execute( $query );				
 			
-//			print($query);
-			
-			$resultArticles = $this->Execute( $query );	
-			
 			// delete the spam comments
         	$query = "DELETE FROM ".$this->getPrefix()."articles_comments 
 			          WHERE status = ".COMMENT_STATUS_SPAM;
@@ -372,27 +371,50 @@
 				
 			// and update article counters of comments
 			include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+			include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );			
 			$articles = new Articles();
+			$blogs = new Blogs();
 			while( $row = $resultArticles->FetchRow()) {
 				$articleId = $row["article_id"];
 				$type = $row["type"];
 				$spam = $row["total_spam"];
 				
-				// build and execute the query to update counters
-				$query = "UPDATE ".$this->getPrefix()."articles SET";
+				// update article counters
 				$article = $articles->getArticle( $articleId );
 				if( $article ) {
-					if( $type == COMMENT_TYPE_COMMENT )
-						$article->setTotalComments( $article->getTotalComments() - $spam );
-					else
-						$article->setTotalTrackbacks( $article->getTotalComments() - $spam );
+					$blog = $article->getBlogInfo();
+					if( $type == COMMENT_TYPE_COMMENT ) {
+		    			$article->setNumComments( $this->getNumItems( $this->getPrefix().'articles_comments', 
+		    		    	                                          'article_id = '.$article->getId().
+		                                                              ' AND status = '.COMMENT_STATUS_NONSPAM.
+		    		        	                                      ' AND type = '.$type ));
+		    			$article->setTotalComments($this->getNumItems( $this->getPrefix().'articles_comments', 
+		    		    	                                           'article_id = '.$article->getId().
+		                                                               ' AND type = '.$type ));
+						$blog->setTotalComments($this->getNumItems( $this->getPrefix().'articles_comments', 
+						                                            'blog_id = '.$blog->getId().' AND type = '.$type ));
+					}
+					else {
+	        			$article->setNumTrackbacks( $this->getNumItems( $this->getPrefix().'articles_comments', 
+	        		    	                                          'article_id = '.$article->getId().
+	                                                                  ' AND status ='.COMMENT_STATUS_NONSPAM.
+	        		        	                                      ' AND type = '.$type ));
+	        			$article->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments', 
+	        		    	                                          'article_id = '.$article->getId().
+	                                                                  ' AND type = '.$type ));
+						$blog->setTotalTrackbacks($this->getNumItems( $this->getPrefix().'articles_comments',
+	   					                                              'blog_id = '.$blog->getId().' AND type = '.$type ));
+					}
 						
 					// update the article
 					$articles->updateArticle( $article );
+					$blogs->updateBlog( $blog );
 					// and clean the cache data
 					$this->_cache->removeData( $articleId, CACHE_ARTICLE_COMMENTS_BYARTICLE );					
 				}
 			}
+			
+			return( true );			
         }		
 		
 		/**



More information about the pLog-svn mailing list