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

matason’s picture

Hi 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!

nk_’s picture

Thanks for tip, I'll give it a try !

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

@nk_ - did matason's suggestion help you? The user data field is kind of an odd (and kludgy) duck...

moshe weitzman’s picture

Status: Postponed (maintainer needs more info) » Fixed

please reopen if needed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.