[pLog-svn] r5648 - in plog/trunk/class: action/admin dao plugin

mark at devel.lifetype.net mark at devel.lifetype.net
Fri Jul 13 04:41:29 EDT 2007


Author: mark
Date: 2007-07-13 04:41:28 -0400 (Fri, 13 Jul 2007)
New Revision: 5648

Modified:
   plog/trunk/class/action/admin/adminsendprivatemessageaction.class.php
   plog/trunk/class/dao/friendgroups.class.php
   plog/trunk/class/dao/friends.class.php
   plog/trunk/class/dao/privatemessage.class.php
   plog/trunk/class/dao/privatemessages.class.php
   plog/trunk/class/dao/users.class.php
   plog/trunk/class/plugin/eventlist.properties.php
Log:
Now, when delete the user, the related friend group, friends, private messages and private message boxes will delete according to user id.

Modified: plog/trunk/class/action/admin/adminsendprivatemessageaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminsendprivatemessageaction.class.php	2007-07-12 06:06:24 UTC (rev 5647)
+++ plog/trunk/class/action/admin/adminsendprivatemessageaction.class.php	2007-07-13 08:41:28 UTC (rev 5648)
@@ -11,7 +11,7 @@
      *
      * Action that adds a new private message to the database.
      */
-    class AdminSendPrivateMessageAction extends AdminAction 
+    class AdminSendPrivateMessageAction extends AdminAction
 	{
 
     	var $_receiverName;
@@ -28,7 +28,7 @@
         function AdminSendPrivateMessageAction( $actionInfo, $request )
         {
         	$this->AdminAction( $actionInfo, $request );
-			
+
 			// register two validators
 			$this->registerFieldValidator( "receiverName", new StringValidator() );
 			$this->registerFieldValidator( "subject", new StringValidator() );
@@ -79,9 +79,9 @@
     		lt_include( PLOG_CLASS_PATH."class/dao/privatemessages.class.php" );
             $privateMessages = new PrivateMessages();
 			$receiverPrivateMessage = new PrivateMessage( $receiverInbox->getId(),
-                                                          $this->_receiverId, 
+                                                          $this->_receiverId,
                                                           $this->_senderId,
-                                                          $this->_subject, 
+                                                          $this->_subject,
                                                           $this->_messageText );
 
 			// fire the pre event...
@@ -92,9 +92,9 @@
                 if( $this->_backupPrivateMessage ) {
                     $senderOutbox = $privateMessageBoxes->getPrivateMessageOutboxFromUserId( $this->_senderId );
                     $senderPrivateMessage = new PrivateMessage( $senderOutbox->getId(),
-                                                                $this->_receiverId, 
+                                                                $this->_receiverId,
                                                                 $this->_senderId,
-                                                                $this->_subject, 
+                                                                $this->_subject,
                                                                 $this->_messageText );
                     $privateMessages->addPrivateMessage( $senderPrivateMessage );
                 }
@@ -102,10 +102,10 @@
 				$this->_view->setSuccess( true );
 				$this->_view->setSuccessMessage( $this->_locale->pr("private_message_sended_ok", $receiverPrivateMessage->getSubject()));
 				$this->notifyEvent( EVENT_POST_SEND_PRIVATE_MESSAGE, Array( "privatemessage" => &$receiverPrivateMessage ));
-				
+
 				$this->sendPrivateMessageEmail( $receiver );
-				
-				$this->setCommonData();				
+
+				$this->setCommonData();
             }
             else {
 				// if there was an error, we should say so... as well as not changing the view since

Modified: plog/trunk/class/dao/friendgroups.class.php
===================================================================
--- plog/trunk/class/dao/friendgroups.class.php	2007-07-12 06:06:24 UTC (rev 5647)
+++ plog/trunk/class/dao/friendgroups.class.php	2007-07-13 08:41:28 UTC (rev 5648)
@@ -106,6 +106,26 @@
 			return( $result );
 		}
 
+        /**
+         * Removes all the friend groups from the given user identifier
+         *
+         * @param userId The blog identifier
+         */
+        function deleteUserFriendGroups( $userId )
+        {
+        	$friendGroups = $this->getUserFriendGroups( $userId );
+
+        	if( $this->delete( "user_id", $userId )) {
+	        	foreach ( $friendGroups as $friendGroup ) {
+					$this->_cache->removeData( $friendGroup->getId(), CACHE_FRIEND_GROUPS );
+	        	}
+	        	$this->_cache->removeData( $userId, CACHE_FRIEND_GROUPS_BY_USER );
+	        	return true;
+        	}
+        	else
+        		return false;
+        }
+
 		/**
 		 * update a given blog category
 		 *
@@ -143,10 +163,10 @@
 		function getNumFriendsGroup( $groupId, $userAuthorizationStatus = USER_AUTHORIZATION_ALL, $friendAuthorizationStatus = FRIEND_AUTHORIZATION_ALL )
 		{
 			$cond = "b.group_id = '".Db::qstr( $groupId )."'";
-			
+
 			if( $userAuthorizationStatus != USER_AUTHORIZATION_ALL )
 				$cond .= " AND user_authorization_status = '".Db::qstr( $userAuthorizationStatus )."'";
-				
+
 			if( $friendAuthorizationStatus != FRIEND_AUTHORIZATION_ALL )
 				$cond .= " AND friend_authorization_status = '".Db::qstr( $friendAuthorizationStatus )."'";
 

Modified: plog/trunk/class/dao/friends.class.php
===================================================================
--- plog/trunk/class/dao/friends.class.php	2007-07-12 06:06:24 UTC (rev 5647)
+++ plog/trunk/class/dao/friends.class.php	2007-07-13 08:41:28 UTC (rev 5648)
@@ -33,7 +33,7 @@
 		function getFriends( $userId, $groupId = 0, $userAuthorizationStatus = USER_AUTHORIZATION_ALL, $friendAuthorizationStatus = FRIEND_AUTHORIZATION_ALL, $searchTerms = "", $page = -1, $itemsPerPage = 15 )
 		{
 			$friends = Array();
-			$query = "SELECT id FROM ".$this->getPrefix()."friends WHERE user_id = '".$userId."' AND"; 
+			$query = "SELECT id FROM ".$this->getPrefix()."friends WHERE user_id = '".$userId."' AND";
 			if( $groupId != 0 )
 				$query .= " group_id = '".Db::qstr($groupId)."' AND";
 			if( $userAuthorizationStatus != USER_AUTHORIZATION_ALL )
@@ -54,7 +54,7 @@
 
 			while( $row = $result->FetchRow()) {
 				// use the primary key to retrieve the items via the cache
-				$friends[] = $friend = $this->get( "id", $row["id"], CACHE_FRIENDS );
+				$friends[] = $this->get( "id", $row["id"], CACHE_FRIENDS );
 			}
 
             return $friends;
@@ -72,10 +72,10 @@
 		{
 			return( count( $this->getFriends( $userId, $groupId, $userAuthorizationStatus, $friendAuthorizationStatus, $searchTerms )));
 		}
-		
+
 		function isFriend( &$friend )
 		{
-			return $this->getNumItems( $this->getPrefix().'friends', 'user_id = '.$friend->getUserId().' AND friend_id = '.$friend->getFriendId() );	
+			return $this->getNumItems( $this->getPrefix().'friends', 'user_id = '.$friend->getUserId().' AND friend_id = '.$friend->getFriendId() );
 		}
 
 		/**
@@ -122,7 +122,7 @@
         {
         	if( $this->isFriend( $friend ) )
         		return false;
-        	
+
         	$result = $this->add( $friend );
 
 			if( $result ) {
@@ -156,7 +156,7 @@
         	else
         		return false;
         }
-        
+
         /**
          * Removes a Friend object from the database.
          *
@@ -174,11 +174,11 @@
 		            $this->_cache->removeData( $id, CACHE_FRIENDS );
 					// update friend realtionship counters
 					$this->updateFriendGroupCounters( $friend );
-	
+
 					return( true );
 	        	}
         	}
-        	
+
        		return false;
         }
 
@@ -193,7 +193,7 @@
 
         	if( $this->delete( "user_id", $userId )) {
 	        	foreach ( $friends as $friend ) {
-					$this->deleteFriend( $friend->getId(), $friend->getUserId() );
+					$this->_cache->removeData( $friends->getId(), CACHE_FRIENDS );
 	        	}
 	        	return true;
         	}
@@ -202,6 +202,48 @@
         }
 
         /**
+         * Removes all the friends from the given friendId
+         *
+         * @param friendId The friend identifier
+         */
+        function deleteAllUsersFriendsByFriendId( $friendId )
+        {
+        	$friends = $this->_getAllUsersFriendsByFriendId( $friendId );
+
+        	if( $this->delete( "friend_id", $friendId )) {
+	        	foreach ( $friends as $friend ) {
+					$this->_cache->removeData( $friends->getId(), CACHE_FRIENDS );
+	        	}
+	        	return true;
+        	}
+        	else
+        		return false;
+        }
+
+        /**
+		 * Retrieves the friends of the given friend identifier. This method only
+		 * used in $this->deleteAllUsersFriendsByFriendId()
+         *
+         * @param friendId Identifier of the user
+		 */
+		function _getAllUsersFriendsByFriendId( $friendId )
+		{
+			$friends = Array();
+			$query = "SELECT id FROM ".$this->table." WHERE friend_id = '".$friendId;
+
+			$result = $this->Execute( $query );
+			if( !$result )
+				return $friends;
+
+			while( $row = $result->FetchRow()) {
+				// use the primary key to retrieve the items via the cache
+				$friends[] = $this->get( "id", $row["id"], CACHE_FRIENDS );
+			}
+
+            return $friends;
+		}
+
+        /**
          * Retrieves a single friend object from db.
          *
          * @param id The identifier
@@ -222,7 +264,7 @@
 			else
 				return false;
         }
-        
+
         /**
          * Removes a Friend object from the database.
          *
@@ -238,7 +280,7 @@
 					return $friend;
 	        	}
         	}
-        	
+
        		return false;
         }
 
@@ -261,7 +303,7 @@
 
 			// clean the cache
             $this->_cache->removeData( $friend->getId(), CACHE_FRIENDS );
-            
+
 			// update friend realtionship counters
 			$this->updateFriendGroupCounters( $friend, $prevVersion );
 

Modified: plog/trunk/class/dao/privatemessage.class.php
===================================================================
--- plog/trunk/class/dao/privatemessage.class.php	2007-07-12 06:06:24 UTC (rev 5647)
+++ plog/trunk/class/dao/privatemessage.class.php	2007-07-13 08:41:28 UTC (rev 5648)
@@ -2,6 +2,7 @@
 
 	lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/dao/privatemessagereceiverreadstatus.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 
 	/**
 	 * \ingroup DAO
@@ -43,12 +44,11 @@
 			$this->_subject = $subject;
 			$this->_message = $message;
 			if( $this->_date == '' ) {
-				lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 				$this->_timestamp = new Timestamp();
 				$this->_date = $this->_timestamp->getTimestamp();
 			} else {
 				$this->_date = $date;
-				$this->_timestamp = null;
+				$this->_timestamp = new Timestamp( $date );
 			}
 			$this->_receiverReadStatus = $receiverReadStatus;
 			$this->_id = $id;
@@ -221,11 +221,6 @@
          */
         function getDateObject()
         {
-            if( empty( $this->_timestamp ) ) {
-	            lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
-	            $this->_timestamp = new Timestamp($this->_date);
-            }
-
         	return $this->_timestamp;
         }
 
@@ -314,8 +309,6 @@
          */
         function setDate( $newDate )
         {
-            lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
-
             $this->_date = $newDate;
             $this->_timestamp = new Timestamp( $newDate );
         }

Modified: plog/trunk/class/dao/privatemessages.class.php
===================================================================
--- plog/trunk/class/dao/privatemessages.class.php	2007-07-12 06:06:24 UTC (rev 5647)
+++ plog/trunk/class/dao/privatemessages.class.php	2007-07-13 08:41:28 UTC (rev 5648)
@@ -232,13 +232,58 @@
          */
         function deletePrivateMessagesByBoxId( $boxId )
         {
+        	$privateMessages = $this->getPrivateMessagesFromBoxId( $boxId );
         	if( $this->delete( "box_id", $boxId )) {
+        		foreach( $privateMessages as $privateMessage ) {
+        			$this->_cache->removeData( $privateMessage->getId(), CACHE_PRIVATE_MESSAGES );
+        		}
 	        	return( $this->_cache->removeData( $boxId, CACHE_PRIVATE_MESSAGES_BY_BOX_ID ));
         	}
         	else
         		return false;
         }
 
+        /**
+         * Removes all the users' private messages from the given sender id
+         *
+         * @param receiverId The receiver identifier
+         */
+        function deleteAllUsersPrivateMessagesBySenderId( $senderId )
+        {
+        	$privateMessages = $this->_getAllUsersPrivateMessagesBySenderId( $senderId );
+        	if( $this->delete( "sender_id", $senderId )) {
+        		foreach( $privateMessages as $privateMessage ) {
+        			$this->_cache->removeData( $privateMessage->getId(), CACHE_PRIVATE_MESSAGES );
+        		}
+	        	return( $this->_cache->removeData( $boxId, CACHE_PRIVATE_MESSAGES_BY_BOX_ID ));
+        	}
+        	else
+        		return false;
+        }
+
+        /**
+		 * Retrieves the private messages of the given sender identifier. This method only
+		 * used in $this->deleteAllUsersPrivateMessagesBySenderId()
+         *
+         * @param friendId Identifier of the user
+		 */
+		function _getAllUsersPrivateMessagesBySenderId( $senderId )
+		{
+			$privateMessages = Array();
+			$query = "SELECT id FROM ".$this->table." WHERE sender_id = '".$senderId;
+
+			$result = $this->Execute( $query );
+			if( !$result )
+				return $friends;
+
+			while( $row = $result->FetchRow()) {
+				// use the primary key to retrieve the items via the cache
+				$privateMessages[] = $this->get( "id", $row["id"], CACHE_PRIVATE_MESSAGES );
+			}
+
+            return $privateMessages;
+		}
+
 		/**
 		 * @see Model::getSearchConditions
 		 */

Modified: plog/trunk/class/dao/users.class.php
===================================================================
--- plog/trunk/class/dao/users.class.php	2007-07-12 06:06:24 UTC (rev 5647)
+++ plog/trunk/class/dao/users.class.php	2007-07-13 08:41:28 UTC (rev 5648)
@@ -168,6 +168,32 @@
          */
         function deleteUser( $userId )
         {
+			// delete friends & friend groups before delete the user
+			lt_include( PLOG_CLASS_PATH."class/dao/friends.class.php" );
+			$friends = new Friends();
+			// delete the user's all friends
+			$friends->deleteUserFriends( $userId );
+			// delete the friends that link to this user
+			$friends->deleteAllUsersFriendsByFriendId( $userId );
+
+			// delete friend groups
+			lt_include( PLOG_CLASS_PATH."class/dao/friendgroups.class.php" );
+			$friendGroups = new FriendGroups();
+			$friendGroups->deleteUserFriendGroups( $userId );
+
+			// delete private messages
+			lt_include( PLOG_CLASS_PATH."class/dao/privatemessageboxes.class.php" );
+			lt_include( PLOG_CLASS_PATH."class/dao/privatemessages.class.php" );
+			$privateMessageBoxes = new PrivateMessageBoxes();
+			$privateMessages = new PrivateMessages();
+			$inbox = $privateMessageBoxes->getPrivateMessageInboxFromUserId( $userId );
+			$outbox = $privateMessageBoxes->getPrivateMessageOutboxFromUserId( $userId );
+			$privateMessages->deletePrivateMessagesByBoxId( $inbox->getId() );
+			$privateMessages->deletePrivateMessagesByBoxId( $outbox->getId() );
+			$privateMessages->deleteAllUsersPrivateMessagesBySenderId( $userId );
+			$privateMessageBoxes->deletePrivateMessageBox( $inbox->getId() );
+			$privateMessageBoxes->deletePrivateMessageBox( $outbox->getId() );
+
 	        return( $this->_provider->deleteUser( $userId ));
         }
         

Modified: plog/trunk/class/plugin/eventlist.properties.php
===================================================================
--- plog/trunk/class/plugin/eventlist.properties.php	2007-07-12 06:06:24 UTC (rev 5647)
+++ plog/trunk/class/plugin/eventlist.properties.php	2007-07-13 08:41:28 UTC (rev 5648)
@@ -208,6 +208,8 @@
 	// friends
 	define( "EVENT_PRE_SEND_PRIVATE_MESSAGE", ++$eventValue );
 	define( "EVENT_POST_SEND_PRIVATE_MESSAGE", ++$eventValue );
+	define( "EVENT_PRE_UPDATE_PRIVATE_MESSAGE", ++$eventValue );
+	define( "EVENT_POST_UPDATE_PRIVATE_MESSAGE", ++$eventValue );
 	define( "EVENT_PRE_DELETE_PRIVATE_MESSAGE", ++$eventValue );
 	define( "EVENT_POST_DELETE_PRIVATE_MESSAGE", ++$eventValue );
 	define( "EVENT_PRIVATE_MESSAGE_LOADED", ++$eventValue );



More information about the pLog-svn mailing list