in the user managment screen, when performing block/unblock on a user the profile fields are erased.
this is due to a bug in the profile save function which is also called on the hook_user update event.
the function assumes that the $edit field is not empty and contains all the relevant fields, which is incorrect. (for example when the user_operations calls
the user_save method, it only provides the status field the has changed).

the fix i suggest would be creating another function to handle updates as follows or simply make these changes to the save function (simple fix which takes the field value from the user account
if not exist in the $edit array):
function profile_update_profile(&$edit, &$user, $category, $register = FALSE) {
$result = _profile_get_fields($category, $register);
while ($field = db_fetch_object($result)) {
if(isset($edit[$field->name]))
$val = $edit[$field->name];
else
$val = $user->{$field->name};
if (_profile_field_serialize($field->type))
$val = serialize($val);
db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $user->uid);
db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $val);
// Mark field as handled (prevents saving to user->data).
$edit[$field->name] = NULL;
}
}

CommentFileSizeAuthor
#2 drupal_804572_user_save.patch1.36 KBhefox
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dddave’s picture

Status: Needs review » Postponed (maintainer needs more info)

No patch to review. Anyways this behavior needs to be confirmed against an up-to-date install.

hefox’s picture

Version: 6.12 » 6.x-dev
Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.36 KB

#1040552: Linking existing account to shib identity deletes profile (module) field data is an example where a contrib module had to deal with this issue; they decided to do a work around where they directly insert their changes to the database then invoke after_update (which means modules cannot hook into other op's, ouch).

user_save, defaults to category = 'account'
profile_user =>
profile_save_profile =>
_profile_get_fields => gets all fields for 'account'
since none are set, deletes all values for those fields

I'm assuming fields can be attached to account; I don't actually have profile enabled or anything.

Untested patch attached

dorion’s picture

#2: drupal_804572_user_save.patch queued for re-testing.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.