[pLog-svn] r3614 - in plog/trunk/class: action/admin dao
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Sun Jun 18 19:19:22 GMT 2006
Author: oscar
Date: 2006-06-18 19:19:21 +0000 (Sun, 18 Jun 2006)
New Revision: 3614
Modified:
plog/trunk/class/action/admin/admincleanupaction.class.php
plog/trunk/class/dao/commentscommon.class.php
Log:
purging spam comments now also updates article counters. Additionally, when purging spam we will not only purge comments but also trackbacks
Modified: plog/trunk/class/action/admin/admincleanupaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincleanupaction.class.php 2006-06-18 17:56:15 UTC (rev 3613)
+++ plog/trunk/class/action/admin/admincleanupaction.class.php 2006-06-18 19:19:21 UTC (rev 3614)
@@ -3,7 +3,7 @@
include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.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/dao/commentscommon.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
/**
@@ -82,7 +82,7 @@
*/
function cleanupComments()
{
- $comments = new ArticleComments();
+ $comments = new CommentsCommon();
$comments->purgeSpamComments();
$this->_message = $this->_locale->tr("spam_comments_purged_ok");
Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php 2006-06-18 17:56:15 UTC (rev 3613)
+++ plog/trunk/class/dao/commentscommon.class.php 2006-06-18 19:19:21 UTC (rev 3614)
@@ -351,18 +351,48 @@
*/
function purgeSpamComments( $type = COMMENT_TYPE_ANY )
{
+ // load the ids of the articles whose spam comments we're going to purge
+ $query = "SELECT article_id, type, COUNT(*) AS total_spam FROM ".$this->getPrefix()."articles_comments
+ WHERE status = ".COMMENT_STATUS_SPAM;
+ if( $type != COMMENT_TYPE_ANY )
+ $query .= " AND type = '".Db::qstr($type)."'";
+ $query .= " GROUP BY article_id, type";
+
+ print($query);
+
+ $resultArticles = $this->Execute( $query );
+
+ // delete the spam comments
$query = "DELETE FROM ".$this->getPrefix()."articles_comments
WHERE status = ".COMMENT_STATUS_SPAM;
if( $type != COMMENT_TYPE_ANY )
- $query .= " AND type = '".Db::qstr($type)."'";
-
- /**
- * :TODO:
- *
- * - clean the whole cache of comments!
- */
-
- return $this->Execute( $query );
+ $query .= " AND type = '".Db::qstr($type)."'";
+ if( !$this->Execute( $query ))
+ return false;
+
+ // and update article counters of comments
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ $articles = new Articles();
+ 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";
+ $article = $articles->getArticle( $articleId );
+ if( $article ) {
+ if( $type == COMMENT_TYPE_COMMENT )
+ $article->setTotalComments( $article->getTotalComments() - $spam );
+ else
+ $article->setTotalTrackbacks( $article->getTotalComments() - $spam );
+
+ // update the article
+ $articles->updateArticle( $article );
+ // and clean the cache data
+ $this->_cache->removeData( $articleId, CACHE_ARTICLE_COMMENTS_BYARTICLE );
+ }
+ }
}
/**
More information about the pLog-svn
mailing list