function hook_usermerge_account_properties in User Merge 7.2
Define which properties of the user account will be merged.
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.
$action: 'delete' or 'block'. Usually does not affect the properties.
4 functions implement hook_usermerge_account_properties()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- multiple_email_usermerge_account_properties in includes/
multiple_email.usermerge.inc - Implements hook_usermerge_account_properties() on behalf of multiple_email.
- profile2_usermerge_account_properties in includes/
profile2.usermerge.inc - Implements hook_usermerge_account_properties().
- usermerge_usermerge_account_properties in ./
usermerge.usermerge.inc - Implement hook_usermerge_account_properties().
- userpoints_usermerge_account_properties in includes/
userpoints.usermerge.inc - Implements hook_usermerge_account_properties() on behalf of userpoints.
File
- ./
usermerge.api.php, line 35 - Hooks provided by the User Merge module.
Code
function hook_usermerge_account_properties($user_to_delete, $user_to_keep, $action) {
// Example taken from usermerge_usermerge_account_properties()
// Define list of fields and other user data
// Using the columns in the user table, so non-field data added from other modules doesn't get mixed in
$user_entity_info = entity_get_info('user');
$user_entity_properties['core'] = $user_entity_info['schema_fields_sql']['base table'];
// Adding roles
$user_entity_properties['core'][] = 'roles';
// Define an array of properties that can be used to display the data-review table(s)
$account_properties = array(
'core' => array(
'title' => t('Core properties'),
'items' => array(),
),
);
// Define list of all user properties (including fields)
// Using $user_to_delete insures that all properties are accounted for
$user_all_properties = array_keys((array) $user_to_delete);
// Find custom fields
$user_entity_properties['fields'] = preg_grep("/^field_/", $user_all_properties);
if (count($user_entity_properties['fields'])) {
$account_properties['fields'] = array(
'title' => t('Fields'),
'description' => t('Please note that single-value fields cannot be merged.'),
'items' => array(),
);
}
// Find other user properties
$user_noncore_properties = array_diff($user_all_properties, $user_entity_properties['core']);
$user_entity_properties['other'] = array_diff($user_noncore_properties, $user_entity_properties['fields']);
if (count($user_entity_properties['other'])) {
$account_properties['other'] = array(
'title' => t('Other properties'),
'items' => array(),
);
}
foreach ($user_entity_properties as $type => $properties) {
foreach (array_flip($properties) as $property_name => $delta) {
$account_properties[$type]['items'][$property_name] = array(
'name' => $property_name,
'criterion' => 'merge',
);
}
}
// These could be defined via settings page
// Remove unwanted items
unset($user_entity_properties, $account_properties['core']['items']['pass']);
// Set default choices for core properties
// This could be defined via settings page
$account_properties['core']['items']['theme']['default'] = $user_to_keep->theme;
$account_properties['core']['items']['signature']['default'] = $user_to_keep->signature;
$account_properties['core']['items']['signature_format']['default'] = $user_to_keep->signature_format;
// Choose older created date
if ($user_to_delete->created < $user_to_keep->created) {
$account_properties['core']['items']['created']['default'] = $user_to_delete->created;
}
else {
$account_properties['core']['items']['created']['default'] = $user_to_keep->created;
}
// Choose newer access date
if ($user_to_delete->access > $user_to_keep->access) {
$account_properties['core']['items']['access']['default'] = $user_to_delete->access;
}
else {
$account_properties['core']['items']['access']['default'] = $user_to_keep->access;
}
$account_properties['core']['items']['login']['default'] = $user_to_keep->login;
$account_properties['core']['items']['status']['default'] = $user_to_keep->status;
$account_properties['core']['items']['timezone']['default'] = $user_to_keep->timezone;
$account_properties['core']['items']['language']['default'] = $user_to_keep->language;
$account_properties['core']['items']['picture']['default'] = $user_to_keep->picture;
$account_properties['core']['items']['init']['default'] = $user_to_keep->init;
$account_properties['core']['items']['data']['default'] = $user_to_keep->data;
// Keep the ability to choose between roles of the two users, but set the default option to merge
$account_properties['core']['items']['roles']['default_option'] = 'merge';
// Properties that should not have a "both" option
$account_properties['core']['items']['uid']['criterion'] = 'no_merge';
$account_properties['core']['items']['name']['criterion'] = 'no_merge';
$account_properties['core']['items']['mail']['criterion'] = 'no_merge';
// Special settings for fields
foreach ($account_properties['fields']['items'] as $field_name => $properties) {
$field_settings = field_info_field($field_name);
// If the field's cardinality is not 1, do not allow merging
// This could pose problems for fields whose cardinality is greater than one, but not unlimited
if ($field_settings['cardinality'] != FIELD_CARDINALITY_UNLIMITED) {
$account_properties['fields']['items'][$field_name]['criterion'] = 'force_select';
}
}
// Authored entitites
$account_properties['entities']['title'] = t('Authored entities');
foreach (usermerge_get_authorable_entities() as $entity_name => $entity) {
$account_properties['entities']['items'][$entity_name] = array(
'name' => $entity_name,
'criterion' => 'no_merge',
);
}
return $account_properties;
}