[pLog-svn] r5564 - plog/branches/lifetype-1.2/class/dao

oscar at devel.lifetype.net oscar at devel.lifetype.net
Fri Jun 22 17:35:12 EDT 2007


Author: oscar
Date: 2007-06-22 17:35:12 -0400 (Fri, 22 Jun 2007)
New Revision: 5564

Modified:
   plog/branches/lifetype-1.2/class/dao/articles.class.php
   plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
Log:
This implements support for deleting the comments when deleting an article, which was also missing.


Modified: plog/branches/lifetype-1.2/class/dao/articles.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/articles.class.php	2007-06-22 20:55:25 UTC (rev 5563)
+++ plog/branches/lifetype-1.2/class/dao/articles.class.php	2007-06-22 21:35:12 UTC (rev 5564)
@@ -1100,9 +1100,6 @@
             	return false;
 
             if( $forever ) {
-            	if( !$this->delete( "id", $artId ))
-            		return false;
-            		
 				// delete the text
 				$this->deleteArticleText( $artId );
 				
@@ -1119,7 +1116,15 @@
 	        	    $blogInfo->setTotalPosts( $blogInfo->getTotalPosts() - 1 );
 	            	$blogs->updateBlog( $blogInfo );
 	            }
+				
+				// delete the article comments
+				$comments = new ArticleComments();
+				$comments->deleteArticleComments( $article->getId());
 
+				// and finally, delete the article data
+            	if( !$this->delete( "id", $artId ))
+            		return false;        
+
 	            // remove all related cache
 				lt_include( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
 				RecentArticles::resetRecentArticlesCache( $blogId );                

Modified: plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/commentscommon.class.php	2007-06-22 20:55:25 UTC (rev 5563)
+++ plog/branches/lifetype-1.2/class/dao/commentscommon.class.php	2007-06-22 21:35:12 UTC (rev 5564)
@@ -524,5 +524,40 @@
 			// when deleting a blog, which means that everything is deleted anyway			
 			return( $this->delete( "blog_id", $blogId ));
 		}
+		
+		/**
+		 * Delete all the article comments
+		 *
+		 * @param blogId
+		 */
+		function deleteArticleComments( $articleId )
+		{
+			lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+			
+			$articles = new Articles();
+			$art = $articles->getArticle( $articleId );
+			
+			// there is no article 
+			if( !$art )
+				return( false );				
+			
+			if(( $res = $this->delete( "article_id", $articleId ))) {
+				// comments deleted successfully, we can update all the counters out there...
+				$blog = $art->getBlogInfo();
+				// update the counter to reflect the number of comments
+				$blog->setTotalComments( $this->getNumItems( $this->getPrefix()."articles_comments", 
+				                                             "blog_id = '".Db::qstr($blog->getId())."'".
+				                                             " AND type = ".COMMENT_TYPE_COMMENT ));
+				// and the one to reflect the number of trackbacks
+				$blog->setTotalTrackbacks( $this->getNumItems( $this->getPrefix()."articles_comments", 
+				                                             "blog_id = '".Db::qstr($blog->getId())."'".
+				                                             " AND type = ".COMMENT_TYPE_TRACKBACK ));				                                              
+				
+				$blogs = new Blogs();
+				$blogs->updateBlog( $blog );
+			}
+			
+			return( $res );
+		}		
 	}
-?>
+?>
\ No newline at end of file



More information about the pLog-svn mailing list