profile fields end up in user data

rares - May 4, 2009 - 14:09
Project:User Import
Version:6.x-1.2
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

I've attempted several imports with different settings and have noticed the following behavior:
When using the Replace data and Add data settings for Profile fields, the users table ends up having profile data.
For example, the data field in the users table looks like this for one of the users:
a:4:{s:13:"profile_first";s:4:"L***";s:12:"profile_last";s:4:"C***";s:13:"form_build_id";s:37:"form-62edc9e9552a21fd32590b2779******";s:7:"contact";i:1;}
Fortunately, the profile data is also saved in the profile_values, but the fact that it is stored in user data as well tends to confuse Drupal. For instance, all scripts that work with the profile_values table do not affect the profile values that Drupal then displays, since during user_load, whatever is in loaded from profile_users is overridden by whatever is stored in the user data.

This issue comes from how user_save is called in line 1411 of user_import.module (6.x-1.2):

<?php
                    
if ($existing_account) {
                      
$account = user_save($existing_account, $account);
                      
$updated = TRUE;
                     }    
?>

Notice that in profile_user (http://api.drupal.org/api/function/profile_user/6), which is invoked with op=='update' by user_save, the category parameter is used to extract which profile fields are going to be saved in the profile_values table. When profile_save_profile (http://api.drupal.org/api/function/profile_save_profile/6) is called, the $category parameter must be present or the fields will not be removed from &$edit, and the data will be saved to user data.

I don't understand how the profile data eventually makes it to profile_values, but at least I was able to understand why it was showing up in user data.

#1

rares - May 4, 2009 - 16:55
Priority:normal» critical
Status:active» needs review

I've looked at this module's code more and have found the problem to be in supported/profile.inc
I am attaching a patch and the new version that I am using and which solves this problem.
The patch removes the profile fields from user data (there was some code that was prepared to replace user data but no instruction to actually remove profile fields from it).
Also, this patch checks whether the respective fields are actually being imported before calling profile_user_import_save_profile(). I have elevated this to critical because without this check, the module would delete all profile data that was not being imported when the import was done with the Update data option.

AttachmentSize
profile.inc.patch 2.52 KB
profile.inc 3.46 KB
 
 

Drupal is a registered trademark of Dries Buytaert.