Imagine user on drupal site with userid as drupal1 has associated his linkedin a/c with drupal site, now if drupal1 unlinks the linkedin account from drupal1 and associate with another a/c account lets say drupal2 then getting the following error:

"PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'xxxxxxxxxx' for key 'authname': INSERT INTO {authmap} (uid, module, authname) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 33 [:db_insert_placeholder_1] => linkedin [:db_insert_placeholder_2] => xxxxxxxxxx ) in user_set_authmaps() (line 2029 of user/user.module)."

It seems like user_set_authmaps() function is creating problem because there is alread a entry present in the authmap table for the corresponding linkedin a/c, and when you try to assoc with another account it gives error.

Just want to confirm what if I remove this line user_set_authmaps($account, array('authmap_linkedin' => $id['id'])); (line 26 of linkedin.inc), like if it doesnt create a entry in the authmap table will there be any problem.

CommentFileSizeAuthor
#2 linkedin-authmap-del-1943838-2.patch1.29 KBklausi

Comments

khandra’s picture

I think that to solve this issue is better to erase the line from authmap when resetting a linkedin account.
I am not completely sure of what I am saying, but in my case it seems to work.
I have modified linkedin_user_settings_form_submit in file linkedin-pages.inc as follows (bold line was added).

function linkedin_user_settings_form_submit($form, &$form_state) {
$op = $form_state['values']['op'];

if ($op == $form['linkedin']['reset']['#value']) {
$data = array();
foreach ($form_state['values'] as $key => $val) {
if (substr($key, 0, 8) == 'linkedin') {
$data[$key] = NULL;
}
}
user_save($form['#account'], array('data' => $data), 'linkedin');
db_delete('linkedin_token')
->condition('uid', $form['#account']->uid)
->execute();
user_set_authmaps($form['#account'], array('authmap_linkedin' => false));
drupal_set_message(t('LinkedIn preferences have been reset'));

But of course this issue remains when the module is removed from the drupal installation.

Linkedin integration module is giving me a lot of pain!

klausi’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.29 KB

Yep, the authmap entry should be removed if the linkedin account is disconnected.

This patch also contains an update function that removes stale entries.

dan3h’s picture

Had the exact same problem: Unlink LI account from one drupal account, and attempt to link it to another => Server error.

And arrived at the exact same solution. I thought I was coming here to post a new issue and share it, but turns out that @khandra had already done the exact same thing, in #1. (But I didn't have @klausi's clever update function in #2 -- nice work on that one.)

This seems like a simple fix. I hope it gets commited soon.

klausi’s picture

@dan3h: cool, could you review and test the code and then set this issue to RTBC?

helmo’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, the patch works as expected!