[pLog-svn] r4308 - in plog/branches/lifetype-1.1.3/class: dao test/tests/dao

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Thu Nov 16 05:19:45 GMT 2006


Author: jondaley
Date: 2006-11-16 05:19:44 +0000 (Thu, 16 Nov 2006)
New Revision: 4308

Added:
   plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php
Modified:
   plog/branches/lifetype-1.1.3/class/dao/commentscommon.class.php
   plog/branches/lifetype-1.1.3/class/dao/daocacheconstants.properties.php
Log:
fixed comment ordering bug from a while ago.  Thanks for the suggestion Mark - I wouldn't have known how to fix it.  Oscar - here is a start on the test case - I don't really get how to do it.

Modified: plog/branches/lifetype-1.1.3/class/dao/commentscommon.class.php
===================================================================
--- plog/branches/lifetype-1.1.3/class/dao/commentscommon.class.php	2006-11-16 04:29:28 UTC (rev 4307)
+++ plog/branches/lifetype-1.1.3/class/dao/commentscommon.class.php	2006-11-16 05:19:44 UTC (rev 4308)
@@ -56,7 +56,8 @@
         {
         	if(( $result = $this->add( $comment ))) {
         		include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-				$this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE );
+				$this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
+				$this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
 				// update the article comments
 				$article = $comment->getArticle();
 				$blog = $article->getBlogInfo();
@@ -106,14 +107,18 @@
 		                          $page = -1, 
 		                          $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
 		{
-			if( $order == COMMENT_ORDER_NEWEST_FIRST )
+			if( $order == COMMENT_ORDER_NEWEST_FIRST ){
 				$order = Array( "date" => "DESC" );
-			else
+                $cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST;
+            }
+			else{
 				$order = Array( "date" => "ASC" );
+                $cache_item = CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST;
+            }
 		
 			$comments = $this->getMany( "article_id",
 			                            $artid,
-			                            CACHE_ARTICLE_COMMENTS_BYARTICLE,
+                                        $cache_item,
 			                            Array(),
 			                            $order,
 										"",
@@ -279,7 +284,8 @@
 				         Db::qstr($commentid)."' AND article_id = '".
 						 Db::qstr( $comment->getArticleId())."'";
         	    $result = $this->Execute( $query );
-        	    $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE );
+                $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
+                $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
         	    $this->_cache->removeData( $comment->getId(), CACHE_ARTICLE_COMMENTS );
         	    
         	    // update the blog and the article counters
@@ -330,7 +336,8 @@
         {    
         	if(($result = $this->update( $comment ))) {
 	        	// reset the cache
-        		$this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE );
+                $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
+                $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
         		$this->_cache->removeData( $comment->getId(), CACHE_ARTICLE_COMMENTS );
         		// update counters in the articles table according to the status
         		include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
@@ -421,7 +428,8 @@
 					$articles->updateArticle( $article );
 					$blogs->updateBlog( $blog );
 					// and clean the cache data
-					$this->_cache->removeData( $articleId, CACHE_ARTICLE_COMMENTS_BYARTICLE );					
+                    $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST );
+                    $this->_cache->removeData( $comment->getArticleId(), CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
 				}
 			}
 			

Modified: plog/branches/lifetype-1.1.3/class/dao/daocacheconstants.properties.php
===================================================================
--- plog/branches/lifetype-1.1.3/class/dao/daocacheconstants.properties.php	2006-11-16 04:29:28 UTC (rev 4307)
+++ plog/branches/lifetype-1.1.3/class/dao/daocacheconstants.properties.php	2006-11-16 05:19:44 UTC (rev 4308)
@@ -38,7 +38,8 @@
 	 * article comments
 	 */
 	define( "CACHE_ARTICLE_COMMENTS", "article_comments" );
-	define( "CACHE_ARTICLE_COMMENTS_BYARTICLE", "article_comments_byarticle" );
+	define( "CACHE_ARTICLE_COMMENTS_BYARTICLE_NEWEST_TO_OLDEST", "article_comments_byarticle_newest_to_oldest" );
+	define( "CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST", "article_comments_byarticle_oldest_to_newest" );
 	 
 	/**
 	 * custom fields

Added: plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php	2006-11-16 04:29:28 UTC (rev 4307)
+++ plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php	2006-11-16 05:19:44 UTC (rev 4308)
@@ -0,0 +1,66 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/article.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+
+	/**
+	 * \ingroup Test
+	 *
+	 * Test cases for the CommentsCommon class
+	 */
+	class CommentsCommon_Test extends LifeTypeTestCase
+	{
+		function setUp()
+		{
+
+            $this->articles = new Articles();
+
+                // build a dummy Article object			
+			$this->article = new Article(
+				"dummy topic",
+				"dummy text",
+				Array( 1 ),   // a dummy category
+				Array( 1 ),   // a dummy user
+				1,  // a dummy blog
+				POST_STATUS_PUBLISHED,  // published status
+				0   // not read yet
+                );
+            
+            $timestamp = new Timestamp();
+            $this->comment1 = new UserComment($this->article->getId(),
+                                              $this->article->getBlogId(),
+                                              0, // dummy parent
+                                              "dummy topic",
+                                              "dummy text",
+                                              $timestamp->getTimestamp());
+            $timestamp = new Timestamp();
+            $this->comment2 = new UserComment($this->article->getId(),
+                                              $this->article->getBlogId(),
+                                              0, // dummy parent
+                                              "dummy topic 2",
+                                              "dummy text 2",
+                                              $timestamp->getTimestamp());
+
+            $this->comments = new ArticleComments();
+
+        }
+
+
+
+        function testAddComment(){
+            $this->assertTrue($this->articles->addArticle($this->article), "Couldn't add article");
+            $this->assertTrue($this->article->getId() != null, "Article ID is null");
+            $this->assertTrue($this->comment1->getArticleId() != null, "Can't find articleId from comment"); 
+            $this->assertTrue($this->comment2->getArticleId() != null, "Can't find articleId from comment"); 
+
+            
+//            $this->assertTrue($this->comments->addComment( $this->comment1 ), "Couldn't add comment1");
+//			$this->assertTrue($this->comments->addComment( $this->comment2 ), "Couldn't add comment2");
+        }
+	}
+?>
\ No newline at end of file



More information about the pLog-svn mailing list