[pLog-svn] r3183 - in plog/trunk/class: action/admin dao gallery/dao

mark at devel.lifetype.net mark at devel.lifetype.net
Tue Apr 4 10:32:38 GMT 2006


Author: mark
Date: 2006-04-04 10:32:37 +0000 (Tue, 04 Apr 2006)
New Revision: 3183

Modified:
   plog/trunk/class/action/admin/admincleanupaction.class.php
   plog/trunk/class/dao/articles.class.php
   plog/trunk/class/dao/blogs.class.php
   plog/trunk/class/gallery/dao/galleryalbums.class.php
   plog/trunk/class/gallery/dao/galleryresources.class.php
Log:
Now the purgeBolgs works with some changes:

1. we can not use delete( "status", BLOG_STATUS_DISABLE) to purge disabled blogs. Becasue it only delete the record in lt_blogs table. We have to use deleteBlog to Purge the blogs, and delete all related data.

2. I just add two new methods - deleteUserResources() and deleteUserAlbums() - to GalleryResource and GalleryAlbum. And now when we purge/delete the blog, the resources and albums are purged, too.

Modified: plog/trunk/class/action/admin/admincleanupaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincleanupaction.class.php	2006-04-04 10:03:37 UTC (rev 3182)
+++ plog/trunk/class/action/admin/admincleanupaction.class.php	2006-04-04 10:32:37 UTC (rev 3183)
@@ -53,7 +53,7 @@
 		 */		
 		function cleanupUsers()
 		{
-	    $users = new Users();
+	    	$users = new Users();
 			$users->purgeUsers();
 
 			$this->_message = $this->_locale->tr("users_purged_ok");
@@ -85,13 +85,15 @@
 			$comments = new ArticleComments();
 			$comments->purgeSpamComments();
 
-            		$this->_message = $this->_locale->tr("spam_comments_purged_ok");
+            $this->_message = $this->_locale->tr("spam_comments_purged_ok");
 
 			return true;
 		}
 
 		function perform()
 		{
+			$result = false;
+			
 			// decide what we're going to do...
 			if( $this->_op == "cleanupSpam" ) {
 				$result = $this->cleanupComments();

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2006-04-04 10:03:37 UTC (rev 3182)
+++ plog/trunk/class/dao/articles.class.php	2006-04-04 10:32:37 UTC (rev 3183)
@@ -1087,7 +1087,7 @@
 			if( $article->getStatus() == POST_STATUS_PUBLISHED ) {            
 	            $blogs = new Blogs();
     	        $blogInfo = $article->getBlogInfo();
-        	    $blogInfo->setTotalArticles( $blogInfo->getTotalArticles() - 1 );
+        	    $blogInfo->setTotalPosts( $blogInfo->getTotalPosts() - 1 );
             	$blogs->updateBlog( $blogInfo );
             }
             

Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php	2006-04-04 10:03:37 UTC (rev 3182)
+++ plog/trunk/class/dao/blogs.class.php	2006-04-04 10:32:37 UTC (rev 3183)
@@ -271,6 +271,8 @@
             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' );
  
             // first of all, delete the posts
             $articles = new Articles();
@@ -285,17 +287,23 @@
             $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 );
 
             // the permissions for the blog
             $perms = new UserPermissions();
             $perms->revokeBlogPermissions( $blogId );
             
             // update blog categories
-            $blog = getBlogInfo( $blogId );
+            $blog = $this->getBlogInfo( $blogId );
 			$this->updateBlogCategoriesLink( $blog );
 
             // and finally, delete the blog
-            return( $this->delete( "blog_id", $blogId ));
+            return( $this->delete( "id", $blogId ));
         }
 
         /**
@@ -305,7 +313,14 @@
          */        
         function purgeBlogs()
         {                                  
-        	return( $this->delete( "status", BLOG_STATUS_DISABLED ));
+        	// return( $this->delete( "status", BLOG_STATUS_DISABLED ));
+        	$disabledBlogs = $this->getAllBlogs( BLOG_STATUS_DISABLED );
+        	foreach( $disabledBlogs as $blog ) {
+        		$blogId = $blog->getId();
+        		$this->deleteBlog( $blogId );
+        	}
+        	
+        	return true;
         }
 
 		/**

Modified: plog/trunk/class/gallery/dao/galleryalbums.class.php
===================================================================
--- plog/trunk/class/gallery/dao/galleryalbums.class.php	2006-04-04 10:03:37 UTC (rev 3182)
+++ plog/trunk/class/gallery/dao/galleryalbums.class.php	2006-04-04 10:32:37 UTC (rev 3183)
@@ -284,6 +284,23 @@
             
             return( true );
         }
+
+        /**
+         * Removes all the albums from the given ownerId
+         *
+         * @param ownerId The blog identifier
+         */
+        function deleteUserAlbums( $ownerId )
+        {
+            $userAlbums = $this->getUserAlbums( $ownerId, false, -1);
+
+            // remove resources belong to the owner one by one
+            foreach( $userAlbums as $album ) {
+                $this->deleteAlbum( $album->getId(), $album->getOwnerId() );
+            }
+
+            return true;
+        }        
 		
 		/**
 		 * returns all the albums of the blog in an array. The key of the array is the

Modified: plog/trunk/class/gallery/dao/galleryresources.class.php
===================================================================
--- plog/trunk/class/gallery/dao/galleryresources.class.php	2006-04-04 10:03:37 UTC (rev 3182)
+++ plog/trunk/class/gallery/dao/galleryresources.class.php	2006-04-04 10:32:37 UTC (rev 3183)
@@ -722,25 +722,49 @@
         {
         	// first, get information about the resource
             $resource = $this->getResource( $resourceId, $ownerId );
-            if( $resource ) {
-            	$this->delete( "id", $resourceId );
-	            $this->_cache->removeData( $resource->getId(), CACHE_RESOURCES );
-				$this->_cache->removeData( $resource->getOwnerId(), CACHE_RESOURCES_USER );
-				$this->_cache->removeData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME );
-				// update the counters
-				include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
-				$albums = new GalleryAlbums();
-				$album = $resource->getAlbum();
-				$album->setNumResources( $album->getNumResources() - 1 );
-				$albums->updateAlbum( $album );		
-	            // proceed and remove the file from disk
-			    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
-        	    $storage = new GalleryResourceStorage();
-            	return $storage->remove( $resource );            	
-            }
-            else {
+            
+            if( empty( $resource ) )
             	return false;
+ 
+ 	        if( $ownerId > -1 )
+	         	if( $resource->getOwnerId() != $ownerId )
+	           		return false;             	
+        	
+            $this->delete( "id", $resourceId );
+	        $this->_cache->removeData( $resource->getId(), CACHE_RESOURCES );
+			$this->_cache->removeData( $resource->getOwnerId(), CACHE_RESOURCES_USER );
+			$this->_cache->removeData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME );
+			// update the counters
+			include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
+			$albums = new GalleryAlbums();
+			$album = $resource->getAlbum();
+			$album->setNumResources( $album->getNumResources() - 1 );
+			$albums->updateAlbum( $album );		
+	        // proceed and remove the file from disk
+			include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
+        	$storage = new GalleryResourceStorage();
+            return $storage->remove( $resource );            	
+        }
+
+        /**
+         * Removes all the resource from the given ownerId
+         *
+         * @param ownerId The blog identifier
+         */
+        function deleteUserResources( $ownerId )
+        {
+            $userResources = $this->getUserResources( $ownerId, 
+                                   					  GALLERY_NO_ALBUM, 
+                                   					  GALLERY_RESOURCE_ANY,
+								   					  "",
+                                   					  -1);
+
+            // remove resources belong to the owner one by one
+            foreach( $userResources as $resource ) {
+                $this->deleteResource( $resource->getId(), $resource->getOwnerId() );
             }
+
+            return true;
         }
 
 		/**



More information about the pLog-svn mailing list