In the fbuser.module function function fb_user_fb($op, $data, &$return) a new role is assigned to a new app user as set forth in the facebook app node. If the user is already existing (e.g. a drupal user connects his or her account with drupal) then the user might already have the role. In such case an sql error is caused since an doublette entry in the user_roles table.
I inserted a if statemtent that checks if a user has already a role:
// Insert new role only if not already assigned to user
if (db_result(db_query("SELECT COUNT(*) FROM {users_roles} WHERE uid = %d and rid = %d", $user->uid, $fb_user_data['new_user_rid'])) == 0) {
db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)',
$user->uid, $fb_user_data['new_user_rid']);
watchdog('fb_user', "Added role %role to existing user !username for application %app",
array('!username' => theme('username', $user),
'%app' => $fb_app->label,
'%role' => $fb_user_data['new_user_rid']));
}
Comments
Comment #1
Dave Cohen commentedWrite before that code, is a line:
The last clause of the
if (...)is supposed to prevent that. Is that broken?