I've got multiple profile fields, but only want to update one field (e.g. "points"). So I create a cvs file with just email address and "points" columns. Then when I run User Import, set the appropriate drupal fields with cvs columns, and select under "Update Existing User", "Profile" "Replace Data", it replaces the data I told it to, but resets all other values back to nothing/default value.

Comments

JasonMR’s picture

Priority: Normal » Critical

Maybe we should remove the "update" feature, until this is fixed?

robert castelo’s picture

Status: Active » Closed (works as designed)

Works as intended, you replaced the existing data.

If you want to add data select 'Add Data'.

If you want to only replace data in a particular field, you could delete the profile field, thus deleting existing data, then use 'Add Data'.

Test first!

robert castelo’s picture

* I meant delete the field, then recreate it, then Add Data.

JasonMR’s picture

Nope, I've tried this on a demo-site and if I have multiple profile fields and try to update just one field using "replace data", it updates all fields, replacing selected field with provided data, and all other fields with default data.

Is this "by design"? Looking at the code I don't think so.

JasonMR’s picture

If you need more info, please let me know.

JasonMR’s picture

By the way, add data does nothing, as no field is defined.

JasonMR’s picture

*sorry, didn't realise I can actually edit posts

OliverColeman’s picture

This may be due to the way the Profile module works: it doesn't allow updating a single field, you have to retrieve all the field values into an array (for the relevant category if desired), edit the desired one, then save it again (either using profile_save_profile or user_save). Or you could make your own version of profile_save_profile that is more flexible.

jvieille’s picture

This is a bug actually.
The function profile_user_import_after_save processes any defined profile fields by setting imported fields, resetttings any others.
A simple check solves this issue :

function profile_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
// get all fields
$profile_fields = profile_get_fields();
$data = $old_data = unserialize($account->data);
foreach ($profile_fields as $field) {
+ if (isset($fields['profile'][$field->fid])){
profile_user_import_save_profile($field, $account->uid, $fields['profile'][$field->fid][0], $updated, $update_setting_per_module['profile'], $data);
+ }
}
// data column in the user table needs to be updated
if ($data != $old_data) {
db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", serialize($data), $account->uid);
}
return;
}