I'm not sure if I'm pointing this to the right module, because so many modules are required to implement proper OpenID AX.

Anyway, I'm trying to exchange profile information between two drupal installations. Everything seems to work fine, but I can see in the database that a new user profile (content profile) is created every time I try to log in with my test user account. I think it's because of node_save($profile); on line 349 in openid_cp_field_openid_client() function, but I don't fully understand that function.

CommentFileSizeAuthor
#3 661104-openid_cp-6.x.patch1.07 KBMaxWesten

Comments

merilainen’s picture

More precisely the database call which is checking if a profile type exists, returns zero always for me.
I made a PHP page with this code:

<?php
global $user;
$account = $user;
$profile_types = array_keys(content_profile_get_types('names'));
$result = db_result(call_user_func_array('db_query', array("SELECT COUNT(*) FROM {node} WHERE uid = %d AND type IN (". db_placeholders($profile_types, 'text') . ")", $account->uid) + $profile_types));
print ($result);
?>

And I get 0 as result with admin and test user.

I changed the if-statement to this:

<?php
$arguments[] = $account->uid;
$arguments = array_merge((array)$arguments, (array)$profile_types);
if (db_result(db_query("SELECT COUNT(*) FROM {node} WHERE uid = %d AND type IN (". db_placeholders($profile_types, 'text') . ")", $arguments)) > 0) {
    return;
}
?>

and now the user won't get a new profile on each login. This is easy to patch if it looks ok.

merilainen’s picture

The problem with my own solution above is that it won't update the profile if user already has a profile. So it can be used only when user registers for an account for the first time. But I really need to update the profiles when user logs in. So I changed the code to work if user has one profile. I have no idea what to do if user has many profiles in the site, which is quite unlikely in my opinion.

Anyway, here is the changed code (replacing if-statement on line 322 in openid_cp_field.module)

<?php
$node = new StdClass();
$node->type = $type;
if ($node->nid = content_profile_profile_exists($node, $account->uid)) {
  $profile = node_load($node->nid);
} else {
  $profile = new StdClass();
}
?>

This way the user's profile (only the OpenID AX mapped fields) is updated on the RP site each time user logs in.

MaxWesten’s picture

Status: Active » Needs review
StatusFileSize
new1.07 KB

Thanks a lot !
This fixed my problems too.
I've rolled it into a patch for easier use.

sanduhrs’s picture

MaxWesten’s picture

#4: Updating the profile is good. The problem that was patched in this thread however created new content_profiles on each login (ie: new nodes) this is solved by using this patch (#3).

xamanu’s picture

Status: Needs review » Closed (duplicate)

This should be work with the other patch, now committed to the module. Marking this as a duplicate.