[pLog-svn] r2131 - in plog/trunk: class/action/admin class/controller class/dao locale templates/admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue May 31 11:42:11 GMT 2005


Author: oscar
Date: 2005-05-31 11:42:11 +0000 (Tue, 31 May 2005)
New Revision: 2131

Modified:
   plog/trunk/class/action/admin/admincleanupaction.class.php
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/class/dao/users.class.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/cleanup.template
Log:
merged issue 534 (http://bugs.plogworld.net/view.php?id=534)


Modified: plog/trunk/class/action/admin/admincleanupaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincleanupaction.class.php	2005-05-31 10:54:35 UTC (rev 2130)
+++ plog/trunk/class/action/admin/admincleanupaction.class.php	2005-05-31 11:42:11 UTC (rev 2131)
@@ -4,6 +4,7 @@
 	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/users.class.php" );
 
     /**
      * \ingroup Action
@@ -26,7 +27,9 @@
 				$this->_op = "cleanupPosts";
 			elseif( $this->_request->getValue( "purgeSpam" ))
 				$this->_op = "cleanupSpam";
-			
+			elseif( $this->_request->getValue( "purgeUsers" ))
+				$this->_op = "cleanupUsers";
+
 			$this->_message = "";
 		}
 
@@ -44,6 +47,22 @@
 		}
 
 		/**
+		 * cleans up users. Returns true if successful or false otherwise
+		 */		
+		function cleanupUsers()
+		{
+	    $users = new Users();
+			$users->purgeUsers();
+
+			$this->_message = $this->_locale->tr("users_purged_ok");
+
+			return true;
+		}
+		
+		//-- End: Conan 20-05-2005 Add option to remove user permanently -->
+
+
+		/**
 		 * cleans up spam comments. Returns true if successful or false otheriwse
 		 */
 		function cleanupComments()
@@ -65,6 +84,9 @@
 			elseif( $this->_op == "cleanupPosts" ) {
 				$result = $this->cleanupPosts();
 			}
+			elseif( $this->_op == "cleanupUsers" ) {
+				$result = $this->cleanupUsers();
+			}
 
 			// create the view and see if there was a success message
 			$this->_view = new AdminTemplatedView( $this->_blogInfo, "cleanup" );

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2005-05-31 10:54:35 UTC (rev 2130)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2005-05-31 11:42:11 UTC (rev 2131)
@@ -248,4 +248,6 @@
 	// clean up
 	$actions["cleanUp"] = "AdminCleanupAction";
 	$actions["doCleanUp"] = "AdminCleanupAction";
+	// removes all users marked as deleted
+    $actions["purgeUsers"] = "AdminPurgeUsersAction";	
 ?>

Modified: plog/trunk/class/dao/users.class.php
===================================================================
--- plog/trunk/class/dao/users.class.php	2005-05-31 10:54:35 UTC (rev 2130)
+++ plog/trunk/class/dao/users.class.php	2005-05-31 11:42:11 UTC (rev 2131)
@@ -5,6 +5,7 @@
     include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/userstatus.class.php" );
+    include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );  
     
     /**
      * Model representing the users in our application. Provides the methods such as
@@ -416,8 +417,102 @@
                 return false;
 
             return true;
-        }        
+        }  
+        
+        /**
+         * 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
+            $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"] );
+            }
+            
+            // 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"] );
+            }
+                        
+            // check if the deleted user owns any blog, if they does, delete the blog
+            // the deleteBlog function will take care of deleting articles etc...            
+            $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 );
+            }            
+            
+            // 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 );          	
+            }            
+                                    
+            // 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"] );
+            }            
+                                   
+            return true;
+    	}
+
         /**
          * returns the total number of users
          *
@@ -496,4 +591,4 @@
                 return false;
         }
     }
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2005-05-31 10:54:35 UTC (rev 2130)
+++ plog/trunk/locale/locale_en_UK.php	2005-05-31 11:42:11 UTC (rev 2131)
@@ -911,4 +911,8 @@
 $messages['trackback_marked_as_nonspam_ok'] = 'The trackback was marked successfully as non-spam';
 $messages['upload_here'] = 'Upload here';
 $messages['reply_string'] = 'Re: ';
+
+$messages['cleanup_users'] = 'Purge Users';
+$messages['cleanup_users_help'] = 'This will remove all users that have been deleted by administrator (marked as "Deleted"). It will also remove any blogs that user own including everything in that blog. If user has permission to post in other blog, all posts made by them will be deleted as well.  It will not be possible to recover once users have been removed';
+$messages['users_purged_ok'] = 'Users purged successfully';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/cleanup.template
===================================================================
--- plog/trunk/templates/admin/cleanup.template	2005-05-31 10:54:35 UTC (rev 2130)
+++ plog/trunk/templates/admin/cleanup.template	2005-05-31 11:42:11 UTC (rev 2131)
@@ -18,7 +18,13 @@
    <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>  
   <input type="hidden" name="op" value="doCleanUp" />
  </fieldset>
 </form>




More information about the pLog-svn mailing list