To replicate problem: prepare import from CSV, use a CSV file that contains user email addresses for some accounts that already exist, set import settings for profile data to 'replace', perform import.
Expected behavior: the contents of the fields in the CSV file are copied to the respective accounts
Actual behavior: the contents of the fields in the CSV file are copied to the respective accounts, but all other profile data is lost. So if we have profile fields X, Y and Z and import just field X, then fields Y and Z are emptied.

Solution, in /supported/profile.inc, the following code change is necessary:

  foreach ($profile_fields as $field) {
    profile_user_import_save_profile($field, $account->uid, $fields['profile'][$field->fid][0], $updated, $update_setting_per_module['profile'], $data);
  }

should become

  foreach ($profile_fields as $field) {
    if($fields['profile'][$field->fid])
      profile_user_import_save_profile($field, $account->uid, $fields['profile'][$field->fid][0], $updated, $update_setting_per_module['profile'], $data);
  }

I've tested this solution and it works.

Comments

rares’s picture

Additionally, the field value '0' is not handled correctly by the code, because '0' is considered an empty value by PHP.
To fix this, the following changes are necessary in /supported/profile.inc

if (empty($value) || (!empty($exists) && $exists != '')) return;
should be
if (empty($value) || (!empty($exists) && $exists != '' && $exists != '0')) return;
and
if ((empty($exists) && $exists != '') || $exists === FALSE) {
should be
if ((empty($exists) && $exists != '' && $exists != '0') || $exists === FALSE) {

robert castelo’s picture

Category: bug » feature
Status: Needs review » Active

Actually 'replace' works as designed, so this is a feature request more than a bug.

The user case for this feature was to replace the whole Profile, leaving no old data behind.

I think what you are suggesting is a 'Replace imported fields only' option?

The existing option could be renamed 'Replace all fields'.

Anonymous’s picture

I consider this a data loss bug. Clearing profile values that aren't specified in the imported CSV is counter intuitive and an unexpected behaviour.

vpsaravanan’s picture

Issue summary: View changes

comment #1 worked for me

gisle’s picture

Status: Active » Closed (outdated)

The Drupal 6 version is no longer supported.
There is no Profile module in Drupal 7.
Closing as outdated.

gisle’s picture