it causes warning message like "key appkey_uid is duplicated" when I'm trying to logout

CommentFileSizeAuthor
#11 fb_user_uid.diff3.15 KBDave Cohen

Comments

Dave Cohen’s picture

Status: Active » Postponed (maintainer needs more info)

I'll keep an eye out for this, but unless you can tell me exactly how to reproduce it I'm not sure how to fix it.

vectoroc’s picture

For me logout from second (I'm testing with 2 fb accounts) causes this warning. Can you check how it works with 2+ accounts ?

vectoroc’s picture

here is exactly warning message

user warning: Duplicate entry '941a0eca057ba141ae90e62deec98a99-0' for key 'apikey_uid' query: UPDATE fb_user_app SET time_access=1257491529, session_key='3.PC0mdE1Nv2CZT0i5NOdWfQ__.86400.1257580800-1839318189', session_key_expires=1257580800, uid=0 WHERE apikey='941a0eca057ba141ae90e62deec98a99' AND fbu=1839318189 in ./sites/all/modules/fb/fb_user.module on line 74.

Dave Cohen’s picture

OK that helps. I don't think their should be entries with uid=0 in that table.

What are your fb_user settings? Do you have it create new accounts automatically?

vectoroc’s picture

automatically for second account

aronmalkine’s picture

I'm actually getting a similar issue around line 71. Facebook is trying to set the uid value to NULL, but the database is complaining, saying that the uid column does not accept NULL values.

fb_user.install line 27:

'uid' => array(
        'type' => 'int', 'size' => 'normal', 'not null' => TRUE,
),

fb_user.module line 69:

$result = db_query("UPDATE {fb_user_app} SET time_access=%d, session_key='%s', session_key_expires=%d, uid=NULL WHERE apikey='%s' AND fbu=%d",

Seems like a contradiction here... Maybe I don't understand the situation where would you want to set the uid to NULL... especially if you have automatic account creation.

Dave Cohen’s picture

Status: Postponed (maintainer needs more info) » Active

This does need to be fixed.

The uid can be null, as users who authorize the app do not necessarily have a local account. So the fix will be to allow null and write an update function to change the db.

Dave Cohen’s picture

Status: Active » Needs review

I hope this is the fix.

Index: fb_user.install                                                          
===================================================================
--- fb_user.install     (revision 2209)                                         
+++ fb_user.install     (working copy)                                          
@@ -25,7 +25,7 @@
       ),                                                                       
       'fbu' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE, ),  
       'uid' => array(                                                          
-        'type' => 'int', 'size' => 'normal', 'not null' => TRUE,               
+        'type' => 'int', 'size' => 'normal', 'not null' => FALSE,              
       ),                                                                       
       'added' => array(                                                        
         'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,               
@@ -128,4 +128,18 @@
   drupal_set_message(t('Note that if you see a warning about "Can\'t DROP ..."\
, it is safe to ignore that message.  See fb_user.install.'));                  
   return $ret;                                                                 
 }                                                                              
+                                                                               
+function fb_user_update_6006() {                                               
+  $ret = array();                                                              
+                                                                               
+  // uid can be zero or NULL.                                                  
+  db_change_field($ret, 'fb_user_app', 'uid', 'uid', array(                    
+                    'type' => 'int',                                           
+                    'size' => 'normal',                                        
+                    'not null' => FALSE                                        
+                  )                                                            
+  );                                                                           
+  return $ret;                                                                 
+}                                                                              
+                                                                               
 ?>                                                                             
\ No newline at end of file                                                     
aronmalkine’s picture

Can you give me some quick background on why we want to set the uid to NULL? Not understanding that from a FB_Connect site perspective. Wouldn't this dissasociate the facebook account from the drupal user in a sense?

Dave Cohen’s picture

There are times when a user is interacting with the site, and the facebook id is known, but there is no local drupal account. I believe there was a time when I just used uid 0 in this case. I can't recall exactly the history of the decision to use NULL. I think it implies an association with no drupal account, rather than with the anonymous account.

The fb_user_app table, where this stuff is stored, is mostly for statistical purposes. It's possible to learn which facebook users have used the app. It also stores their session key which in some cases allows the app to interact with facebook on their behalf even when they are not logged in.

If you have more database know-how than I do, feel free to suggest the best approach for what to store in the uid column when there is no local account.

Dave Cohen’s picture

StatusFileSize
new3.15 KB

My plan now is to use 0 in the uid field, rather than allow null. Here's a patch to apply instead of the previous one.

Dave Cohen’s picture

Status: Needs review » Fixed

Checked in for inclusion in beta4.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.