[pLog-svn] r4581 - in plog/trunk: class/action/admin class/dao class/dao/userdata class/gallery/dao locale templates/admin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Fri Jan 26 10:05:13 EST 2007


Author: oscar
Date: 2007-01-26 15:05:12 +0000 (Fri, 26 Jan 2007)
New Revision: 4581

Added:
   plog/trunk/class/dao/purgedata.class.php
Modified:
   plog/trunk/class/action/admin/admincleanupaction.class.php
   plog/trunk/class/dao/articlenotifications.class.php
   plog/trunk/class/dao/articles.class.php
   plog/trunk/class/dao/blogs.class.php
   plog/trunk/class/dao/commentscommon.class.php
   plog/trunk/class/dao/model.class.php
   plog/trunk/class/dao/mylinkscategories.class.php
   plog/trunk/class/dao/referers.class.php
   plog/trunk/class/dao/userdata/simplepostnukeuserdataprovider.class.php
   plog/trunk/class/dao/userpermissions.class.php
   plog/trunk/class/dao/users.class.php
   plog/trunk/class/gallery/dao/galleryalbums.class.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/cleanup.template
Log:
Purging data in LT 1.1.x was causing too many troubles (timeouts, bugs, etc) and fixing it in 1.1.x would have been too complicated so I've revamped the feature so that it hopefully works better now.

All the code related to purging has been moved to its own class PurgeData (class/dao/purgedata.class.php) and includes all methods needed to purge users, blogs, spam comments, etc in addition to all related data (so that when deleting a blog all its data is deleted)

When clicking the "purge xxx" button, the purging is performed in smaller steps (in increments of 5) and the page is automatically refreshed until there is no more data to purge. This should hopefully solve the timeout issues when purging too much data and the consequent problems with data integrity. 


Modified: plog/trunk/class/action/admin/admincleanupaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincleanupaction.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/action/admin/admincleanupaction.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -16,6 +16,8 @@
 	{
 		var $_message;
 		var $_op;
+		var $_continue;
+		var $_url;
 
 		function AdminCleanupAction( $actionInfo, $request )
 		{
@@ -35,6 +37,7 @@
 				$this->_op = "cleanupTemp";
 
 			$this->_message = "";
+			$this->_continue = false;
 			
 			$this->requireAdminPermission( "purge_data" );
 		}
@@ -44,12 +47,21 @@
 		 */
 		function cleanupPosts()
 		{
-        	$articles = new Articles();
-			$articles->purgePosts();
-
-			$this->_message = $this->_locale->tr("posts_purged_ok");
-
-			return true;
+			include_once( PLOG_CLASS_PATH."class/dao/purgedata.class.php" );
+			
+			$purge = new PurgeData();
+			if( $purge->purgePosts() > 0 ) {				
+				$this->_message = $this->_locale->tr( "purging_please_wait" );
+				// flags to indicate that we show refresh the page and continue at the given URL
+				$this->_continue = true;				
+				$this->_url = "?op=doCleanUp&purgePosts=Purge";
+			}
+			else {
+				$this->_continue = false;
+				$this->_message = $this->_locale->tr( "posts_purged_ok" );
+			}
+			
+			return( true );
 		}
 
 		/**
@@ -57,28 +69,43 @@
 		 */		
 		function cleanupUsers()
 		{
-	    	$users = new Users();
-			$users->purgeUsers();
-
-			$this->_message = $this->_locale->tr("users_purged_ok");
-
-			return true;
+			include_once( PLOG_CLASS_PATH."class/dao/purgedata.class.php" );
+			
+			$purge = new PurgeData();
+			if( $purge->purgeUsers() > 0 ) {				
+				$this->_message = $this->_locale->tr( "purging_please_wait" );
+				// flags to indicate that we show refresh the page and continue at the given URL
+				$this->_continue = true;				
+				$this->_url = "?op=doCleanUp&purgePosts=Purge";
+			}
+			else {
+				$this->_continue = false;
+				$this->_message = $this->_locale->tr( "users_purged_ok" );
+			}
+			
+			return( true );
 		}		
-		//-- End: Conan 20-05-2005 Add option to remove user permanently -->
 
-		//-- Start: Conan 25-05-2005 Add option to remove Blog marked as disabled -->
 		/**
 		 * cleans up blogs. Returns true if successful or false otherwise
-		 */
-		
+		 */		
 		function cleanupBlogs()
 		{
-	    	$blogs = new Blogs();
-			$blogs->purgeBlogs();
-
-			$this->_message = $this->_locale->tr("blogs_purged_ok");
-
-			return true;
+			include_once( PLOG_CLASS_PATH."class/dao/purgedata.class.php" );
+			
+			$purge = new PurgeData();
+			if( $purge->purgeBlogs() > 0 ) {				
+				$this->_message = $this->_locale->tr( "purging_please_wait" );
+				// flags to indicate that we show refresh the page and continue at the given URL
+				$this->_continue = true;				
+				$this->_url = "?op=doCleanUp&purgeBlogs=Purge";
+			}
+			else {
+				$this->_continue = false;
+				$this->_message = $this->_locale->tr( "blogs_purged_ok" );
+			}
+			
+			return( true );
 		}
 
 		/**
@@ -86,12 +113,21 @@
 		 */
 		function cleanupComments()
 		{
-			$comments = new CommentsCommon();
-			$comments->purgeSpamComments();
-
-            $this->_message = $this->_locale->tr("spam_comments_purged_ok");
-
-			return true;
+			include_once( PLOG_CLASS_PATH."class/dao/purgedata.class.php" );
+			
+			$purge = new PurgeData();
+			if( $purge->purgeSpamComments() > 0 ) {				
+				$this->_message = $this->_locale->tr( "purging_please_wait" );
+				// flags to indicate that we show refresh the page and continue at the given URL
+				$this->_continue = true;				
+				$this->_url = "?op=doCleanUp&purgeSpam=Purge";
+			}
+			else {
+				$this->_continue = false;
+				$this->_message = $this->_locale->tr( "spam_comments_purged_ok" );
+			}
+			
+			return( true );
 		}
 		
 		function cleanupTemp()
@@ -135,6 +171,8 @@
 			$this->_view = new AdminTemplatedView( $this->_blogInfo, "cleanup" );
 			if( $result ) 
 				$this->_view->setSuccessMessage( $this->_message );
+			$this->_view->setValue( "continue", $this->_continue );
+			$this->_view->setValue( "dest", $this->_url );
 
 			$this->setCommonData();
 

Modified: plog/trunk/class/dao/articlenotifications.class.php
===================================================================
--- plog/trunk/class/dao/articlenotifications.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/articlenotifications.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -20,7 +20,7 @@
         {
         	$this->Model();
 
-			$this->table = $this->getPrefix()."article_notifications";
+			$this->table = $this->getPrefix()."articles_notifications";
         }
 
         /**
@@ -250,5 +250,15 @@
 
             return $notification;
          }
+
+		/**
+		 * Deletes all notifications from the given blog
+		 *
+		 * @param blogId
+		 */
+		function deleteBlogNotifications( $blogId )
+		{			
+			return( $this->delete( "blog_id", $blogId ));
+		}
      }
 ?>

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/articles.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -1110,28 +1110,8 @@
             	if( !$this->delete( "id", $artId ))
             		return false;
             		
-				// -- text --
+				// delete the text
 				$this->deleteArticleText( $artId );
-                // we also have to remove its comments and trackbacks if the article is being deleted forever
-                // -- comments --
-                $articleComments = new ArticleComments();
-                foreach( $article->getComments() as $comment )
-                	$articleComments->deleteComment( $comment->getId());
-                	
-                // -- trackbacks --
-                $trackbacks = new Trackbacks();
-                foreach( $article->getTrackbacks() as $trackback )
-                	$trackbacks->deleteTrackback( $trackback->getId());
-
-                // -- post-to-categories mappings --
-                $this->deletePostCategoriesLink( $article );
-                // -- custom fields --
-                $customFields = new CustomFieldsValues();
-                $customFields->removeArticleCustomFields( $artId );
-                
-                // -- article notifications --
-                $articleNotification = new ArticleNotifications();
-                $articleNotification->deleteNotification( $artId, $blogId, $userId );
 				
 				// update global article categories
 				$this->updateGlobalArticleCategoriesLink( $article );
@@ -1180,40 +1160,17 @@
          * @param blogId The blog identifier
          */
         function deleteBlogPosts( $blogId )
-        {
-            $blogArticles = $this->getBlogArticles( $blogId );
+        {	
+			$query = "SELECT id, user_id, blog_id FROM ".$this->getPrefix()."articles WHERE blog_id = '".Db::qstr( $blogId )."'";
+			$result = $this->Execute( $query );
+			
+			if( !$result )
+				return false;
 
-            foreach( $blogArticles as $article ) {
-                // the deleteArticle method will also take care of removing comments and
-                // trackbacks
-                $this->deleteArticle( $article->getId(), $article->getUser(), 
-                                      $article->getBlog(), true );
-            }
-
-            return true;
-        }
-
-        /**
-         * removes all posts that have 'deleted' status
-         *
-         * @return Returns true if all posts were deleted or false otherwise.
-         */
-        function purgePosts()
-        {
-            $query = Db::buildSelectQuery( ARTICLES_TABLENAME,
-                                           array('id', 'user_id', 'blog_id'),
-                                           'status',
-                                           POST_STATUS_DELETED );
-
-            $result = $this->Execute( $query );
-
-            if( !$result )
-                return false;
-
             while( $row = $result->FetchRow()) {
                 $this->deleteArticle( $row["id"], $row["user_id"], $row["blog_id"], true );
             }
-            $result->Close();
+
             return true;
         }
 
@@ -1228,7 +1185,7 @@
             lt_include( PLOG_CLASS_PATH.'class/dao/blogs.class.php' );
 
 			$id = $query_result['id'];
-
+			
             // this is a little dirty trick or otherwise the old
             // that don't have the 'properties' field will not work
             // as they will appear to have comments disabled
@@ -1240,7 +1197,8 @@
 			$blogs         = new Blogs();
             $blogId        = $query_result['blog_id'];
             $blogInfo      = $blogs->getBlogInfo( $blogId );
-			$blogSettings  = $blogInfo->getSettings();
+
+			$blogSettings  = $blogInfo->getSettings();			
 			
 			if( $blogSettings )
 				$timeDiff = $blogSettings->getValue( 'time_offset' );

Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/blogs.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -311,55 +311,10 @@
          */
         function deleteBlog( $blogId )
         {
-            // source classes
-            require_once( PLOG_CLASS_PATH . 'class/dao/articles.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/dao/mylinks.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/dao/mylinkscategories.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/dao/userpermissions.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/database/db.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/dao/articlecategories.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/gallery/dao/galleryresources.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/gallery/dao/galleryalbums.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/dao/bayesiantokens.class.php' );
- 			require_once( PLOG_CLASS_PATH . 'class/dao/bayesianfilterinfos.class.php' );
-			require_once( PLOG_CLASS_PATH . 'class/template/templatesets/templatesets.class.php' );
-			require_once( PLOG_CLASS_PATH . 'class/template/templatesets/templatesetstorage.class.php' );
-			require_once( PLOG_CLASS_PATH . 'class/file/file.class.php' );		
-            
-            // first of all, delete the posts
-            $articles = new Articles();
-            $articles->deleteBlogPosts( $blogId );
-
-            // next is to remove the article categories
-            $articleCategories = new ArticleCategories();
-            $articleCategories->deleteBlogCategories( $blogId );
-
-            // next, all the links and links categories
-            $myLinks = new MyLinks();
-            $myLinks->deleteBlogMyLinks( $blogId );
-            $myLinksCategories = new MyLinksCategories();
-            $myLinksCategories->deleteBlogMyLinksCategories( $blogId );
-            
-            // next, all the resources & albums
-            $resources = new GalleryResources();
-            $resources->deleteUserResources( $blogId );
-            $albums = new GalleryAlbums();
-            $albums->deleteUserAlbums( $blogId );
-            
-            // next, all bayesian tokens and filter infos
-            $tokens = new BayesianTokens();
-            $tokens->deleteBayesianTokensByBlogId( $blogId );
-            $filterInfos = new BayesianFilterInfos();
-            $filterInfos->deleteBayesianFilterInfoByBlogId( $blogId );
-
-            // the permissions for the blog
-            $perms = new UserPermissions();
-            $perms->revokeBlogPermissions( $blogId );
-            
-            // update blog categories
-            $blog = $this->getBlogInfo( $blogId );
-			$this->updateBlogCategoriesLink( $blog );
-			
+			// update blog categories
+			$blog = $this->getBlogInfo( $blogId );
+			$this->updateBlogCategoriesLink( $blog );	
+	
 			// delete the blog template sets
 			$templateSets = new TemplateSets();
 			$tsStorage = new TemplateSetStorage();
@@ -377,26 +332,6 @@
             return( $this->delete( "id", $blogId ));
         }
 
-        /**
-         * removes all blogs that have 'deleted' status
-         *
-         * @return Returns true if all blogs were deleted or false otherwise.
-         */        
-        function purgeBlogs()
-        {                                  
-        	// return( $this->delete( "status", BLOG_STATUS_DISABLED ));
-        	$disabledBlogs = $this->getAllBlogs( BLOG_STATUS_DISABLED );
-        	foreach( $disabledBlogs as $blog ) {
-        		$blogId = $blog->getId();
-        		$this->deleteBlog( $blogId );
-        		// This is a ugly hack, or there is no place the clean these deleted blogs' cache
-        		lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
-        		CacheControl::resetBlogCache( $blogId, false );
-        	}
-        	
-        	return true;
-        }
-
 		/**
          * @private
          */

Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/commentscommon.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -137,11 +137,6 @@
 				lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 				foreach( $comments as $comment ) {
 					if( $this->check( $comment, $type, $status )) {
-						// WARNING (oscar 20070101)
-						// This isn't necessary as CommentsCommon::mapRow() is already applying the offset...
-						// otherwise what we're getting here is the same offset applied twice!
-						//$date = Timestamp::getDateWithOffset( $comment->getDate(), $timeDiff );
-						//$comment->setDate( $date );
 						$result[] = $comment;
 					}
 				}
@@ -385,78 +380,6 @@
         	return( $result );
         }
 
-        /**
-         * removes all comments marked as spam from the database
-		 *
-		 * @param type
-         */
-        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";
-			$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)."'";
-            if( !$this->Execute( $query ))
-				return false;
-				
-			// and update article counters of comments
-			lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-			lt_include( 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"];
-				
-				// update article counters
-				$article = $articles->getArticle( $articleId );
-				if( $article ) {
-					$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_NEWEST_TO_OLDEST );
-                    $this->_cache->removeData( $articleId, CACHE_ARTICLE_COMMENTS_BYARTICLE_OLDEST_TO_NEWEST );
-				}
-			}
-			
-			return( true );			
-        }		
-		
 		/**
 		 * returns a single comment, identified by its identifier
 		 *
@@ -613,5 +536,15 @@
 
 			return( $where_string );		
 		}
+		
+		/**
+		 * Delete all the blog comments
+		 */
+		function deleteBlogComments( $blogId )
+		{
+			// we really don't bother about caches or comment, as this method is only being called
+			// when deleting a blog, which means that everything is deleted anyway			
+			return( $this->delete( "blog_id", $blogId ));
+		}
 	}
 ?>

Modified: plog/trunk/class/dao/model.class.php
===================================================================
--- plog/trunk/class/dao/model.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/model.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -523,6 +523,6 @@
 
                 $this->_dbInitialized = true;
             }
-        }        
+        }
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/dao/mylinkscategories.class.php
===================================================================
--- plog/trunk/class/dao/mylinkscategories.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/mylinkscategories.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -126,7 +126,7 @@
          * @param blogId The blog identifier
          */
         function deleteBlogMyLinksCategories( $blogId )
-        {
+        {	
 			$res = false;
 			$categories = $this->getMyLinksCategories( $blogId );
         	if(( $res = $this->delete( "blog_id", $blogId ))) {

Added: plog/trunk/class/dao/purgedata.class.php
===================================================================
--- plog/trunk/class/dao/purgedata.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/purgedata.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -0,0 +1,174 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+	
+	define( "DEFAULT_PURGE_AMOUNT", 5 );
+
+	/**
+	 * This class takes care of purging data, since it's a very complex process anyway
+	 */
+	class PurgeData extends Blogs
+	{
+		/**
+		 * Deletes a blog and all its data
+		 *
+		 * @param blogId The id of the blog whose data we'd like to delete
+		 */
+		function deleteBlogData( $blogId )
+		{
+			lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+			
+			// delete the article categories
+			include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+			$cats = new ArticleCategories();
+			$cats->deleteBlogCategories( $blogId );
+			// article notifications
+			include_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
+			$notifications = new ArticleNotifications();
+			$notifications->deleteBlogNotifications( $blogId );			
+			// comments
+			include_once( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
+			$comments = new CommentsCommon();
+			$comments->deleteBlogComments( $blogId );
+			// links
+			include_once( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );			
+			$links = new MyLinks();
+			$links->deleteBlogMyLinks( $blogId );
+			// link categories
+			include_once( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
+			$links = new MyLinksCategories();
+			$links->deleteBlogMyLinksCategories( $blogId );
+			// referers
+			include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );			
+			$referers = new Referers();
+			$referers->deleteBlogReferers( $blogId );
+			// permissions
+			include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );			
+			$perms = new UserPermissions();
+			$perms->revokeBlogPermissions( $blogId );
+			// resources
+			include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
+			$albums = new GalleryResources();
+			$albums->deleteUserResources( $blogId );
+			// albums
+			include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );			
+			$albums = new GalleryAlbums();
+			$albums->deleteUserAlbums( $blogId );						
+			// articles
+			include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+			$articles = new Articles();
+			$articles->deleteBlogPosts( $blogId );
+			// the blog itself
+			include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+			$blogs = new Blogs();
+			$blogs->deleteBlog( $blogId );
+
+			// reset the template cache
+			CacheControl::resetBlogCache( $blogId, false );
+		}
+		
+        /**
+         * removes all blogs that have 'deleted' status
+         *
+         * @return Returns 	how many we purged, and when this method returns '0', it means that there is nothing else
+	     * left to be purged
+         */        
+        function purgeBlogs( $amount = DEFAULT_PURGE_AMOUNT)
+        {                                  
+        	$disabledBlogs = $this->getAllBlogs( BLOG_STATUS_DISABLED, ALL_BLOG_CATEGORIES, "", 1, $amount );
+        	foreach( $disabledBlogs as $blog ) {
+        		$blogId = $blog->getId();
+        		$this->deleteBlogData( $blogId );
+        	}
+        	
+			// return how many we purged, and when this method returns '0', it means that there is nothing else
+			// left to be purged
+        	return( count( $disabledBlogs ));
+        }
+
+		/**
+		 * Purge spam comments
+		 *
+		 * @param amount
+         * @return Returns 	how many we purged, and when this method returns '0', it means that there is nothing else
+	     * left to be purged
+	     */
+		function purgeSpamComments( $amount = DEFAULT_PURGE_AMOUNT )
+		{
+			lt_include( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
+			
+			$query = "SELECT id FROM ".$this->getPrefix()."articles_comments WHERE status = ".COMMENT_STATUS_SPAM." LIMIT 0, $amount";
+			$result = $this->Execute( $query );
+			
+			if( !$result )
+				return false;
+				
+			$deleted = 0;
+			$comments = new CommentsCommon();
+			
+			while( $row = $result->FetchRow()) {
+				// the CommentsCommon::deleteComment() method should take care of updating the articles,
+				// resettings caches and updating comment counters in articles and blogs
+				$comments->deleteComment( $row["id"] );
+				$deleted++;
+			}
+			
+			return( $deleted );
+		}
+		
+		/**
+		 * Purge articles that have been marked as deleted
+		 *
+		 * @param amount
+		 */
+		function purgePosts( $amount = DEFAULT_PURGE_AMOUNT ) 
+		{
+			lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+			
+			$query = "SELECT id, user_id, blog_id  FROM ".$this->getPrefix()."articles WHERE status = ".POST_STATUS_DELETED." LIMIT 0, $amount";
+			
+			$result = $this->Execute( $query );
+			
+			if( !$result )
+				return false;
+				
+			$deleted = 0;
+			$comments = new Articles();
+			
+			while( $row = $result->FetchRow()) {
+				// calling the method in the Articles class will take care of everything else
+				$comments->deleteArticle( $row["id"], $row["user_id"], $row["blog_id"], true );
+				$deleted++;
+			}
+			
+			return( $deleted );			
+		}
+		
+		/**
+		 * Purge users that have been marked as disabled. If these users own a blog, then the blog will also be removed
+		 *
+		 * @param amount
+		 */
+		function purgeUsers( $amount = DEFAULT_PURGE_AMOUNT )
+		{
+			lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
+			
+			$users = new Users();
+			$deleted = 0;
+			// get $amount more users...
+			$disabledUsers = $users->getAllUsers( USER_STATUS_DISABLED, "", 1, $amount );
+			
+			// and process them
+	        foreach( $disabledUsers as $user ) {
+	        	foreach( $user->getOwnBlogs() as $userBlog ) {					
+	        		$this->deleteBlogData( $userBlog->getId());
+	        	}
+	        	
+	        	$users->deleteUser( $user->getId());
+				$deleted++;
+	        }
+	        
+	        return( $deleted );			
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/class/dao/referers.class.php
===================================================================
--- plog/trunk/class/dao/referers.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/referers.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -22,8 +22,7 @@
         {
         	$this->Model();
 
-            $config =& Config::getConfig();
-            $this->_enabled = $config->getValue( "referer_tracker_enabled" );
+			$this->table = $this->getPrefix()."referers";
         }
 
         /**
@@ -37,10 +36,6 @@
         {
             require_once( PLOG_CLASS_PATH."class/net/url.class.php" );
 
-        	// quit inmediately if this is not enabled...
-        	if( !$this->_enabled )
-            	return;
-
         	// we only add a new referer if we come from somewhere else than our own server
             $ourHost = $_SERVER["HTTP_HOST"];
 
@@ -234,5 +229,13 @@
 			
 			return( $this->getNumItems( $table, $cond ));
 		}
+		
+		/**
+		 * Delete all the data that depends on a given blog
+		 */
+		function deleteBlogReferers( $blogId )
+		{			
+			return( $this->delete( "blog_id", $blogId ));
+		}
     }
 ?>

Modified: plog/trunk/class/dao/userdata/simplepostnukeuserdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/simplepostnukeuserdataprovider.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/userdata/simplepostnukeuserdataprovider.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -367,109 +367,8 @@
             }
             else
             	return( false );
-        }  
-        
-        /**
-        * removes all users that have 'deleted' status
-        *
-        * @return Returns true if all users were deleted or false otherwise.
-        */        
-        function purgeUsers()
-        {
-            // we first need to delete all resources/album belong to the blog, 
-            // we don't need to care if the ablum has sub album, resource, we
-            // just delete all albums, resources that belong the blog which is
-            // being deleted as a result of deleting the blog's owner
-            
-            // first delete all resources
-    		lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );              
-            $galleryresources = new GalleryResources();
-            $r_query = "SELECT gr.id AS id, gr.owner_id as owner_id 
-            					  FROM ".$this->getPrefix()."gallery_resources AS gr, ".$this->getPrefix()."blogs AS b, ".$this->getPrefix()."users AS u
-            					  WHERE gr.owner_id=b.id AND b.owner_id=u.id AND u.status = 2";            					 
-            				
-            $r_result = $this->Execute( $r_query );     
-            if( !$r_result )
-                return false;
-                
-            while( $r_row = $r_result->FetchRow()) {
-            	$galleryresources->deleteResource( $r_row["id"], $r_row["owner_id"] );
-            }
-            $r_result->Close();
-                        
-            // now delete album
-            $galleryalbums = new GalleryAlbums();
-            $al_query = "SELECT ga.id AS id, ga.owner_id as owner_id 
-            					  FROM ".$this->getPrefix()."gallery_albums AS ga, ".$this->getPrefix()."blogs AS b, ".$this->getPrefix()."users AS u
-            					  WHERE ga.owner_id=b.id AND b.owner_id=u.id AND u.status = 2";            				   
-            
-            $al_result = $this->Execute( $al_query );     
-            if( !$al_result )
-                return false;
-                
-            while( $al_row = $al_result->FetchRow()) {
-            	$galleryalbums->deleteAlbum( $al_row["id"], $al_row["owner_id"] );
-            }
-            $al_result->Close();
-         
-            // check if the deleted user owns any blog, if they does, delete the blog
-            // the deleteBlog function will take care of deleting articles etc...            
-    		lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );            
-            $blogs = new Blogs();             
-            $userfolder = new GalleryResourceStorage();                        
-            
-            $b_query = "SELECT b.id 
-            					  FROM ".$this->getPrefix()."blogs AS b, ".$this->getPrefix()."users AS u 
-            					  WHERE b.owner_id=u.id AND u.status = 2";            					
-            				
-            $b_result = $this->Execute( $b_query );     
-            if( !$b_result )
-                return false;
-                
-            while( $b_row = $b_result->FetchRow()) {
-            	$blogs->deleteBlog( $b_row["id"] );            	
-            	// since the deleteResource doesn't take care of deleting all the user folder
-            	// and now that we have the blog id here, we can use the deleteDir function
-            	// to delete all uder folders and sub folders :)
-            	$filePath = $userfolder->getUserFolder( $b_row["id"] );  
-            	File::deleteDir( $filePath, true, false );
-            }            
-            $b_result->Close();
+        }          
 
-            // now we need to check if user belong to any other blog and have made any posts
-            // at the moment, we cannot dertermine which resource was posted by which user
-            // so when user is deleted, resource posted by him/her will stay intact in the blog
-            // maybe we should notify the blog owner that his member was deleted?						
-						$articles = new Articles();
-						
-						$a_query = "SELECT a.id AS id, a.user_id AS user_id, a.blog_id AS blog_id
-											  FROM ".$this->getPrefix()."articles AS a, ".$this->getPrefix()."users AS u 
-					 						  WHERE a.user_id=u.id AND u.status = 2";   
-            $a_result = $this->Execute( $a_query );
-            
-            if( !$a_result )
-                return false;
-                
-            while( $a_row = $a_result->FetchRow()) {
-            	$articles->deleteArticle( $a_row["id"], $a_row["user_id"], $a_row["blog_id"], true );          	
-            }            
-            $a_result->Close();
-                     
-            // finally remove the user                                 
-            $u_query = "SELECT * FROM ".$this->getPrefix()."users WHERE status = 2";
-
-            $u_result = $this->Execute( $u_query );
-            if( !$u_result )
-                return false;
-            
-            while( $u_row = $u_result->FetchRow()) {
-                $this->deleteUser( $u_row["id"] );
-            }            
-            $u_result->Close();
-                    
-            return true;
-    	}
-
         /**
         * returns the total number of users
         *

Modified: plog/trunk/class/dao/userpermissions.class.php
===================================================================
--- plog/trunk/class/dao/userpermissions.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/userpermissions.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -151,7 +151,7 @@
          */
         function revokeBlogPermissions( $blogId )
         {
-			lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+			lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );		
 			
 			$blogs = new Blogs();
 			$blogInfo = $blogs->getBlogInfo( $blogId );
@@ -234,6 +234,6 @@
 										$row["id"] );
 
             return $perm;
-        }		
+        }
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/dao/users.class.php
===================================================================
--- plog/trunk/class/dao/users.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/dao/users.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -171,29 +171,6 @@
         }
         
         /**
-         * Purge users from the database
-         */
-        function purgeUsers()
-        {
-	        lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
-	        $blogs = new Blogs();
-	        $users = $this->_provider->getAllUsers( USER_STATUS_DISABLED );
-	        
-	        foreach( $users as $user )
-	        {
-	        	$userBlogs = $this->_provider->getUsersBlogs( $user->getId() );
-	        	foreach( $userBlogs as $userBlog )
-	        	{
-	        		$blogs->deleteBlog( $userBlog->getId() );
-	        	}
-	        	
-	        	$this->deleteUser( $user->getId() );
-	        }
-	        
-	        return true;
-        }      
-
-        /**
          * returns the total number of users
 		 *
 		 * @param status

Modified: plog/trunk/class/gallery/dao/galleryalbums.class.php
===================================================================
--- plog/trunk/class/gallery/dao/galleryalbums.class.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/class/gallery/dao/galleryalbums.class.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -328,8 +328,8 @@
             }
 
             return true;
-        }        
-		
+        }
+
 		/**
 		 * returns all the albums of the blog in an array. The key of the array is the
 		 * parent id of all the albums in the position, and each position is either an

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/locale/locale_en_UK.php	2007-01-26 15:05:12 UTC (rev 4581)
@@ -1235,4 +1235,6 @@
 $messages['insert_more'] = 'Toggle "More..." link';
 
 $messages['posted_in'] = 'Posted in';
+
+$messages['purging_please_wait'] = 'Please wait while data is being purged. This page will keep refreshing itself until all data has been processed, please do not attempt to stop this process';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/cleanup.template
===================================================================
--- plog/trunk/templates/admin/cleanup.template	2007-01-26 14:54:09 UTC (rev 4580)
+++ plog/trunk/templates/admin/cleanup.template	2007-01-26 15:05:12 UTC (rev 4581)
@@ -3,40 +3,50 @@
 <form name="cleanUp" method="post" action="admin.php">
  <fieldset class="inputField">
   <legend>{$locale->tr("cleanUp")}</legend>
-  {include file="$admintemplatepath/successmessage.template" message=$viewSuccessMessage}
-  {include file="$admintemplatepath/errormessage.template" message=$viewErrorMessage}
-  <div class="field">
-   <label for="purgePosts">{$locale->tr("cleanup_posts")}</label>
-   <span class="required"></span>
-   <div class="formHelp">{$locale->tr("cleanup_posts_help")}</div>
-   <input type="submit" class="button" name="purgePosts" value="{$locale->tr("purge")}" />
-  </div>  
-  <div class="field">
-   <label for="purgeSpam">{$locale->tr("cleanup_spam")}</label>
-   <span class="required"></span>
-   <div class="formHelp">{$locale->tr("cleanup_spam_help")}</div>
-   <input type="submit" class="button" name="purgeSpam" value="{$locale->tr("purge")}" />
-  </div>
-  <div class="field">
-   <label for="purgePosts">{$locale->tr("cleanup_users")}</label>
-   <span class="required"></span>
-   <div class="formHelp">{$locale->tr("cleanup_users_help")}</div>
-   <input type="submit" class="button" name="purgeUsers" value="{$locale->tr("purge")}" />
-  </div>
-  <div class="field">
-   <label for="purgeBlogs">{$locale->tr("cleanup_blogs")}</label>
-   <span class="required"></span>
-   <div class="formHelp">{$locale->tr("cleanup_blogs_help")}</div>
-   <input type="submit" class="button" name="purgeBlogs" value="{$locale->tr("purge")}" />
-  </div>
-  <div class="field">
-   <label for="purgeTemp">{$locale->tr("cleanup_temp")}</label>
-   <span class="required"></span>
-   <div class="formHelp">{$locale->tr("cleanup_temp_help")}</div>
-   <input type="submit" class="button" name="purgeTemp" value="{$locale->tr("purge")}" />
-  </div>
-  <input type="hidden" name="op" value="doCleanUp" />
+  {if $continue}
+	  {** do a reload as soon as the page has finished loading **}
+	  {include file="$admintemplatepath/successmessage.template" message=$viewSuccessMessage}
+  {else}
+	  {include file="$admintemplatepath/successmessage.template" message=$viewSuccessMessage}
+	  {include file="$admintemplatepath/errormessage.template" message=$viewErrorMessage}
+	  <div class="field">
+	   <label for="purgePosts">{$locale->tr("cleanup_posts")}</label>
+	   <span class="required"></span>
+	   <div class="formHelp">{$locale->tr("cleanup_posts_help")}</div>
+	   <input type="submit" class="button" name="purgePosts" value="{$locale->tr("purge")}" />
+	  </div>  
+	  <div class="field">
+	   <label for="purgeSpam">{$locale->tr("cleanup_spam")}</label>
+	   <span class="required"></span>
+	   <div class="formHelp">{$locale->tr("cleanup_spam_help")}</div>
+	   <input type="submit" class="button" name="purgeSpam" value="{$locale->tr("purge")}" />
+	  </div>
+	  <div class="field">
+	   <label for="purgePosts">{$locale->tr("cleanup_users")}</label>
+	   <span class="required"></span>
+	   <div class="formHelp">{$locale->tr("cleanup_users_help")}</div>
+	   <input type="submit" class="button" name="purgeUsers" value="{$locale->tr("purge")}" />
+	  </div>
+	  <div class="field">
+	   <label for="purgeBlogs">{$locale->tr("cleanup_blogs")}</label>
+	   <span class="required"></span>
+	   <div class="formHelp">{$locale->tr("cleanup_blogs_help")}</div>
+	   <input type="submit" class="button" name="purgeBlogs" value="{$locale->tr("purge")}" />
+	  </div>
+	  <div class="field">
+	   <label for="purgeTemp">{$locale->tr("cleanup_temp")}</label>
+	   <span class="required"></span>
+	   <div class="formHelp">{$locale->tr("cleanup_temp_help")}</div>
+	   <input type="submit" class="button" name="purgeTemp" value="{$locale->tr("purge")}" />
+	  </div>
+	  <input type="hidden" name="op" value="doCleanUp" />
+  {/if}
  </fieldset>
 </form>
 {include file="$admintemplatepath/footernavigation.template"}
 {include file="$admintemplatepath/footer.template"}
+{if $continue}
+<script type="text/javascript">
+  window.location = "{$dest}";
+</script>
+{/if}
\ No newline at end of file



More information about the pLog-svn mailing list