Currently, if I unlink a contact from /redhen/contact/%redhen_contact/view/user, the entry in the redhen_contact_user table remains, but this status is sent to NULL. This prevents me from re-linking that user to the same contact in the future.

A user just accidentally unlinked a contact and wanted to re-link it to the contact. In order to fix it, I had to manually update the redhen_contact_user table.

Possible suggestions:

  • If an entry already exists in redhen_contact_user, show the user a confirm dialog to make sure that the do, indeed want to re-link the contact.
  • Create a new site-wide setting , "Allow un-linked users to be re-linked to contacts"

I'm happy to work on a patch for either solution, but I was unsure what they best way to proceed would be.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

levelos’s picture

Some more messaging to users would be great. There's actually two actions already available: Deleting the connection does allow it to be re-added. Unlinking, however, is designed to prevent recreating the linkage. This could be much better communicated and any patches would be welcome.

Weijian’s picture

As temporary solution, I just remove the unlinked validation and update the contact user status to 1. It works for me. Hope this help others.

1. Remove the validation code of below in function redhen_contact_contact_user_form_validate

$result = db_select('redhen_contact_user', 'cu')
      ->fields('cu')
      ->condition('uid', $user->uid, '=')
      ->condition('contact_id', $contact->contact_id, '=')
      ->condition('status', NULL, 'is')
      ->execute();

    if ($result->rowCount() > 0) {
      form_set_error('existing', t('Drupal user %name has been unlinked from this contact to prevent it   from being reconnected.',
        array('%name' => $user->name)
      ));
    }

2. Change the function setUser to update the contact user status for the unlinked -> relink case
Add code after
if ($row->contact_id == $contact->contact_id && $row->status == NULL) {

to replace "return FALSE" with:

// Update with the unlinked user.
              db_update('redhen_contact_user')
                ->fields(array(
                'status' => 1,
                'updated' => REQUEST_TIME,
                ))
                ->condition('contact_id', $contact->contact_id)
                ->execute();
              return TRUE;
levelos’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)
andyg5000’s picture

Title: Allow unlinked contacts to be relinked » Improve unlink/delete Redhen contact to Drupal user, user experience.
Status: Closed (works as designed) » Needs review
FileSize
3.96 KB

We had this issue with users accidentally getting unlinked. Here's a patch that adds a confirm form as well as some descriptions and new button labels to hopefully improve the user experience.

The patch does not address re-linking unlinked contacts. I'm still reading up on the reason to unlink vs delete and will submit another patch if that feature is necessary.

SocialNicheGuru’s picture

Dishvola’s picture

I've used my code snippet when I wanted to re-link drupal user to the contact.
You can use "/devel/php" page for code executing if devel module are installed and enabled.
It worked for me :)

// Fix for a situation when we get this message: "Drupal user %name has been unlinked from this contact to prevent it from being reconnected.".
$user_uid = 1111;
$contact_id = 2222;

$contact = redhen_contact_load($contact_id);
if ($contact instanceof RedhenContact) {
  // Update with the unlinked user.
  db_update('redhen_contact_user')
    ->fields(array(
      'status' => 1,
      'updated' => REQUEST_TIME,
    ))
    ->condition('uid', $user_uid)
    ->condition('contact_id', $contact_id)
    ->execute();

  $contact->uid = $user_uid;
  $contact->save();
}