[pLog-svn] r2883 - plog/trunk/class/dao
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Wed Feb 1 18:15:26 GMT 2006
Author: oscar
Date: 2006-02-01 18:15:25 +0000 (Wed, 01 Feb 2006)
New Revision: 2883
Modified:
plog/trunk/class/dao/articles.class.php
Log:
now article category counters should be correct when updating posts
Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php 2006-02-01 17:53:34 UTC (rev 2882)
+++ plog/trunk/class/dao/articles.class.php 2006-02-01 18:15:25 UTC (rev 2883)
@@ -725,8 +725,7 @@
// updated the category counters
$articleCategories = new ArticleCategories();
foreach( $article->getCategories() as $category ) {
- print("deleting link between art = ".$article->getId()." and category = ".$category->getId()."<br/>");
- $category->setNumArticles( $category->getNumArticles() - 1 );
+ $category->setNumArticles( $category->getNumArticles( POST_STATUS_ALL ) - 1 );
if( $article->getStatus() == POST_STATUS_PUBLISHED ) {
$category->setNumPublishedArticles( $category->getNumPublishedArticles() - 1 );
}
@@ -743,11 +742,15 @@
* update the links between a post and its categories
* (basically, we use brute force here: first remove them and then recreate them again...
* It takes less time than going through all of them and checking if they exist or not.
+ *
+ * @private
*/
- function updatePostCategoriesLink( $article )
+ function updatePostCategoriesLink( $article, $oldArticle = null )
{
- if( !$this->deletePostCategoriesLink( $article ))
- return false;
+ if( $oldArticle != null ) {
+ if( !$this->deletePostCategoriesLink( $oldArticle ))
+ return false;
+ }
return $this->addPostCategoriesLink( $article );
}
@@ -893,6 +896,10 @@
*/
function updateArticle( $article )
{
+ // keep the old version, since we're going to need it to udpate the category counters
+ $oldArticle = $this->getArticle( $article->getId());
+
+ // and now update the new version
$result = $this->update( $article );
// we don't bother doing anything else if the query above failed...
@@ -907,7 +914,7 @@
$article->getFields()) )
return false;*/
- if( !$this->updatePostCategoriesLink( $article )) {
+ if( !$this->updatePostCategoriesLink( $article, $oldArticle )) {
return false;
}
More information about the pLog-svn
mailing list