You are here

function hook_usermerge_merge_accounts in User Merge 7.2

Merge specific account properties.

Parameters

$user_to_delete: The full object of the user to be deleted.

$user_to_keep: The full object of the user to be kept.

$review: The array containing review data (as form elements).

7 functions implement hook_usermerge_merge_accounts()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entityreference_usermerge_merge_accounts in includes/entityreference.usermerge.inc
Implements hook_usermerge_merge_accounts().
multiple_email_usermerge_merge_accounts in includes/multiple_email.usermerge.inc
Implements hook_usermerge_merge_accounts() on behalf of multiple_email.
profile2_usermerge_merge_accounts in includes/profile2.usermerge.inc
Implements hook_usermerge_merge_accounts().
profile_usermerge_merge_accounts in includes/profile.usermerge.inc
Implements hook_usermerge_merge_accounts() on behalf of profile module.
usermerge_usermerge_merge_accounts in ./usermerge.usermerge.inc
Implements hook_usermerge_merge_accounts().

... See full list

File

./usermerge.api.php, line 231
Hooks provided by the User Merge module.

Code

function hook_usermerge_merge_accounts($user_to_delete, $user_to_keep, $review) {

  // Example from multiple_email_usermerge_merge_accounts()
  $emails_to_keep = $review['multiple_email']['multiple_email']['options'];
  if ($emails_to_keep == 'merge') {
    $query = db_update('multiple_email')
      ->fields(array(
      'uid' => $user_to_keep->uid,
    ))
      ->condition('uid', $user_to_delete->uid)
      ->execute();

    // Make sure $user_to_keep's primary email remains primary
    // Necessary because support for regular mail property is disabled by this extension
    multiple_email_make_primary(multiple_email_find_address($user_to_keep->mail));
  }
  else {
    $emails_to_delete = $emails_to_keep == 'user_to_keep' ? 'user_to_delete' : 'user_to_keep';
    $query_delete = db_delete('multiple_email')
      ->condition('uid', ${$emails_to_delete}->uid)
      ->execute();

    // This fires only if the emails to keep are those of the account to delete
    // If not, this would be redundant
    if ($emails_to_keep == 'user_to_delete') {
      $query_update = db_update('multiple_email')
        ->fields(array(
        'uid' => $user_to_keep->uid,
      ))
        ->condition('uid', ${$emails_to_keep}->uid)
        ->execute();
    }

    // Make sure $emails_to_keep's primary email remains primary
    multiple_email_make_primary(multiple_email_find_address(${$emails_to_keep}->mail));
  }
}