Hello,
After some time I decided to ask for little support on this. I must be dumb :(
My problem is how to migrate some data from custom table's field (longtext) to users data. I tried following code, no success:
function mymodule_migrate_fields_user($type) {
$fields = array();
$user_fields['data'] = t('User: Data');
$fields = array_merge($fields, $user_fields);
return $fields;
}
function mymodule_migrate_prepare_user(&$account, $tblinfo, $row) {
foreach ($tblinfo->fields as $destfield => $values) {
if ($values['srcfield'] && isset($row->$values['srcfield'])) {
$newvalue = $row->$values['srcfield'];
}
else {
$newvalue = $values['default_value'];
}
if ($destfield == 'data') {
$account['data'] = serialize($newvalue);
}
}
return $errors;
}
It simply won't go ... Any tip much appreciated. Thanks!
Comments
Comment #1
matason commentedHi there,
You need to send key => value pairs of the stuff you want in users.data where key != 'data' - I know what you're doing seems like the obvious thing to do but if you have a look at user_save() in user.module and check out the code for inserting a new user you'll see data => 'blah' gets written in the initial insert for the new user then $data is built from fields coming in that are NOT in $user_fields (including 'data'), then the serialised $data is written to the database...
I haven't had time to test this, hopefully my memory serves me right!
Comment #2
nk_ commentedThanks for tip, I'll give it a try !
Comment #3
mikeryan@nk_ - did matason's suggestion help you? The user data field is kind of an odd (and kludgy) duck...
Comment #4
moshe weitzman commentedplease reopen if needed.