You are here

function profile_migrate_prepare_user in Migrate 6

Implementation of hook_migrate_prepare_user(). Because user_save() on a new user record only saves those profile fields with register=1, we pull the profile fields out and stash them in the row object to be saved later.

File

modules/profile.migrate.inc, line 28
Implementation of profile destination handling

Code

function profile_migrate_prepare_user(&$account, $tblinfo, &$row) {

  // Cache categories for each field
  static $cats;
  if (!isset($cats)) {
    $cats = array();
    $sql = "SELECT name,category FROM {profile_fields}";
    $result = db_query($sql);
    while ($catrow = db_fetch_object($result)) {
      $cats[$catrow->name] = $catrow->category;
    }
  }
  foreach ($account as $fieldname => $value) {
    if (!strncmp($fieldname, 'profile_', 8)) {
      $cat = $cats[$fieldname];
      $row->profile_fields[$cat][$fieldname] = $value;
      unset($account[$fieldname]);
    }
  }
  return array();
}