[pLog-svn] r2223 - in plog/trunk: . class/dao/userdata

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue Jun 14 21:24:23 GMT 2005


Author: oscar
Date: 2005-06-14 21:24:23 +0000 (Tue, 14 Jun 2005)
New Revision: 2223

Modified:
   plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
   plog/trunk/wizard.php
Log:
added an extra table so that the information needed by the integration
with phpbb can be stored somewhere... Please re-run the wizard to get
the new table or run the following:

CREATE TABLE plog_phpbb2_users(
id int(10) unsigned NOT NULL auto_increment,
   phpbb_id int(10) unsigned NOT NULL,
   full_name varchar(255) NOT NULL default '',
   about text,
   properties TEXT NOT NULL default '',
   resource_picture_id integer(10) NOT NULL DEFAULT 0,
   PRIMARY KEY  (id),
   UNIQUE KEY phpbb_id(phpbb_id)
   ) TYPE=MyISAM;

The integration is almost working, but I still have some conceptual
issues with the user statuses. Pphpbb only understand enabled and disabled
users, while plog can have as many as needed (via custom status codes) We
could do so that a non-active user in phpbb is non-active in plog too
but an active user in phpbb can have many more status codes in plog...

And the last conceptual issue is what to do with new phpbb users, since those
do not have a blog in plog yet. Hacking phpbb to create a blog when a user
is new is not an option so probably we'll go for the solution of creating
a new brand blog every time a new user is detected in phpbb.


Modified: plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-14 21:18:13 UTC (rev 2222)
+++ plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-14 21:24:23 UTC (rev 2223)
@@ -115,6 +115,8 @@
          */
         function getUserInfoFromId( $userid, $extendedInfo = false )
         {
+	        include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
+	        
 	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE user_id = '".Db::qstr( $userid )."'";
 	                  
 	        $result = $this->_dbc->Execute( $query );
@@ -135,15 +137,17 @@
         {
 	        include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
 	        
+	        $plogPhpBB2Data = $this->getpLogPHPBBUserData( $row["user_id"] );
+	        
 	        $row["user"] = $row["username"];
 	        $row["password"] = $row["user_password"];
 	        $row["email"] = $row["user_email"];
-	        $row["about"] = "";
-	        $row["full_name"] = "";
-	        $row["resource_picture_id"] = 0;
+	        $row["about"] = $plogPhpBB2Data["about"];
+	        $row["full_name"] = $plogPhpBB2Data["full_name"];
+	        $row["resource_picture_id"] = $plogPhpBB2Data["resource_picture_id"];
 	        $row["properties"] = serialize(Array());
-	        $row["id"] = $row["user_id"];
-	        $row["status"] = USER_STATUS_ACTIVE;
+	        $row["id"] = $row["user_id"];   
+	        $row["status"] = $row["user_active"];
 	        
 	        $perms = new UserPermissions();
 	        $row["site_admin"] = $perms->isSiteAdmin( $row["user_id"] );	 	        
@@ -191,7 +195,13 @@
 	                              
             $result = $this->_dbc->Execute( $query );            
             
+            if( !$result )
+            	return false;
+            
             BaseUserDataProvider::updateUser( $userInfo );
+            
+			// update plog's phpbb2_user table
+			$result = $this->updatepLogPHPBB2UserData( $userInfo );
 
 			return( $result );
         }
@@ -220,11 +230,17 @@
          */
         function addUser( &$user )
         {	        
+	        // update the phpbb table
 	        $password = $user->getPassword();
 	        $id = $this->getLastPhpBBUserId();
+	        if($user->getStatus() == USER_STATUS_ACTIVE )
+	        	$phpBBStatus = 1;
+	        else
+	        	$phpBBStatus = 0;
+	        	
 	        $query = "INSERT INTO ".$this->_phpbbprefix."users (user_id,username,user_password,user_email,user_active)
 	                  VALUES ($id, '".Db::qstr($user->getUserName())."','".md5($user->getPassword())."','".
-                      Db::qstr($user->getEmail())."',1);";                      
+                      Db::qstr($user->getEmail())."',$phpBBStatus);";
                       
             $result = $this->_dbc->Execute( $query );            
 
@@ -232,9 +248,75 @@
                 return false;
 			
 			$user->setId( $id );
+			
+			// update plog's phpbb2_user table
+			$this->updatepLogPHPBB2UserData( $user );
 
             return( $id );
         }
+        
+        /**
+         * @private
+         * Updates the plog-specific user data that is used when the phpbb2 integration is enabled, since
+         * plog has some extra information that does not fit anywhere in phpbb2
+         *
+         * @param user A UserInfo object
+         * @return true if successful or false otherwise
+         */
+        function updatepLogPHPBB2UserData( &$user )
+        {
+	    	// is the user already there?
+	    	if( $this->getpLogPHPBBUserData( $user->getId())) {
+		    	$this->log->debug("phpbb user ".$user->getUsername()." already exists! Running an UPDATE query..." );
+		    	// we need to run an UPDATE query...
+		    	$query = "UPDATE ".$this->getPrefix()."phpbb2_users
+		    	          SET full_name = '".Db::qstr( $user->getFullName())."', 
+		    	              about = '".Db::qstr( $user->getAboutMyself())."',
+		    	              properties = '".Db::qstr( serialize($user->getProperties()))."',
+		    	              resource_picture_id = '".Db::qstr( $user->getPictureId())."',
+		    	              status = '".Db::qstr( $user->getStatus())."'
+		    	          WHERE phpbb_id = '".Db::qstr( $user->getId())."'";    
+	    	}
+	    	else {
+		    	// we need to run an INSERT query...	
+		    	$this->log->debug("phpbb user ".$user->getUsername()." does NOT exist yet! Running an INSERT query..." );
+		    	$query = "INSERT INTO ".$this->getPrefix()."phpbb2_users
+		    	          (full_name, about, properties, resource_picture_id,phpbb_id,status)
+		    	          VALUES ('".Db::qstr( $user->getFullName())."', '".
+		    	          Db::qstr($user->getAboutMyself())."','".
+		    	          Db::qstr(serialize($user->getProperties()))."','".
+		    	          Db::qstr($user->getPictureId())."','".
+		    	          Db::qstr($user->getId())."','".
+		    	          Db::qstr($user->getStatus())."');";
+	    	}
+	    	
+	    	$result = $this->Execute( $query );
+	    	
+			return( true );
+        }
+        
+        /**
+         * @private
+         * Load the plog-specific phpbb2 user data
+         *
+         * @param userId
+         * @return A row with the extra user data or false otherwise
+         */
+        function getpLogPHPBBUserData( $userId )
+        {
+	        $query = "SELECT * FROM ".$this->getPrefix()."phpbb2_users WHERE phpbb_id = '".Db::qstr($userId)."'";
+	        
+	        $result = $this->Execute( $query );
+	        
+	        if( !$result )
+	        	return false;
+	        	
+	        if( $result->RowCount() == 0 )
+	        	return false;
+	        	
+	        return ($result->FetchRow());
+        }
+        
 
         /**
          * disables a user

Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php	2005-06-14 21:18:13 UTC (rev 2222)
+++ plog/trunk/wizard.php	2005-06-14 21:24:23 UTC (rev 2223)
@@ -436,6 +436,18 @@
    FULLTEXT KEY normalized_topic (normalized_topic),
    FULLTEXT KEY normalized_fields (normalized_text, normalized_topic)
    ) TYPE=MyISAM;";
+   
+   $Tables[25]["desc"] = "PhpBB2 User Integration Table";
+   $Tables[25]["code"] = "CREATE TABLE {dbprefix}phpbb2_users (
+   id int(10) unsigned NOT NULL auto_increment,
+   phpbb_id int(10) unsigned NOT NULL,
+   full_name varchar(255) NOT NULL default '',
+   about text,
+   properties TEXT NOT NULL default '',
+   resource_picture_id integer(10) NOT NULL DEFAULT 0,
+   PRIMARY KEY  (id),
+   UNIQUE KEY phpbb_id(phpbb_id)
+   ) TYPE=MyISAM;";
 
 
 




More information about the pLog-svn mailing list