While programmatically importing thousands of users from an old site, I'm facing this very strange behaviour. The code snippet below correctly attach commerce customer profiles to the created users on localhost site, but attach them to uid 1
on production site !
localhost is a strict copy of remote site : git clone for code and Backup and Migrate DB copy The users are imported uploading and parsing a csv file in a custom form, connected as admin
$new_user = array(
'name' => $new_name,
'pass' => $pwd,
'mail' => $email,
'init' => $email,
'status' => 1,
);
$account = new stdClass;
$account->roles = array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',
9 => 'client',
);
if ($saved_user = user_save($account, $new_user)) {
dpm($saved_user, $new_name.'/'.$saved_user->uid );
//VERY STRANGE HERE (ON PROD SITE ONLY) see screen capture below
//the dpm title prints $saved_user->uid as a new uid
//but "inside" dpm $saved_user->uid is 1 !
}
//create user commerce profile
$profile = commerce_customer_profile_new('billing', $saved_user->uid);
$profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);
//... add profile values ...
$profile_wrapper->save();
Localhost : expected uid when dpm($saved_user, $new_name.'/'.$saved_user->uid );
Production site : uid 1 instead. The user is created with the new uid though, but uid 1 is passed then to commerce customer profile