As part of our recent site upgrade from Drupal 6 to Drupal 7, we had a bunch of content profiles to clean up. Content Profile is a Drupal 6 module that allows you to create "Profile" content types, and we've used that on a bunch of sites for things like directory information, staff biographies, board biographies, etc. And in Drupal 7, it's replaced by Profile2. Profile2 stores profile data in its own entities, not in nodes. And there's no direct path for getting your data from a content profile to a profile2. VBO to the rescue! Views Bulk Operations (VBO) with a little PHP snippet is perfect for this task. The challenge is figuring out the PHP you need to use.

Set up Profile2

First thing, get your new profile2 profiles set up. Profile2 does not let you add the old body fields directly, and does not have a title field. So if you store the user's name in the title and biography in the body, you will need to create and add these fields to your profile2 type. Then add all of the rest of your existing fields to the type.

Migrate the data using "Execute Arbitrary PHP script"

The following snippet migrates data from an "employee" content profile to an "employee" profile2, and it first loads an existing profile2 before updating values -- so you can experiment with values first. To develop this snippet, I created a profile2 for one user with dummy values, and then used "dpm()" (from the devel module) to see its structure and figure out exactly how to make this work. So this snippet replaces the dummy data on existing profiles with the data from the original content_profile: $newprofile = profile2_load_by_user($entity->uid, 'employee'); $query = new EntityFieldQuery(); $query->entityCondition('entity_type','node') ->entityCondition('bundle','employee') ->propertyCondition('uid',$entity->uid); $result = $query->execute(); if ($result && $result['node']) { $item = array_pop($result['node']); $node = node_load($item->nid); if (!$newprofile) { $newprofile = profile2_create(array('type'=>'employee','uid'=>$entity->uid)); } $newprofile->field_name['und'][0]['value'] = $node->title; $newprofile->field_bio = $node->body; $newprofile->field_petprojects = $node->field_petprojects; $newprofile->field_profileimage = $node->field_profileimage; $newprofile->field_weight = $node->field_weight; profile2_save($newprofile); } To use this snippet:

  1. In a VBO view of content, select all of the content profiles to migrate. Be sure your view is set up to use batch operations if you have a lot of data.
  2. Check the boxes for all the items to migrate.
  3. Select "Execute Arbitrary PHP Script"
  4. Paste in the above code, adjusting it for the fields you have on your content profile and profile2.
  5. Execute, and test! Hope that helps!
Permalink

I've been searching and experimenting. Their solution was the success. Thank you very much

Permalink

It would make the code easier to follow if the old profile and the new profile had different names (eg "employee" and "employee2") so it would be clearer where the values should be edited to match our set-up. And edit the instructions to match of course. You may be surprised how difficult it is for some of us to decipher code and every little hint will help!
Thanks for this code - it has worked once for me but I now need to import into a profile2 with a slightly different name from the original profile and that's not working yet.

Permalink

uid, 'profile');

if (!$profile) {
$profile = profile2_create(array('type'=>'profile','uid'=>$entity->uid));
}

foreach($entity as $f => $fdata){
$profile->$f = $fdata;
}

$profile->field_name['und'][0]['value'] = $entity->title;
$profile->field_profile_body = $entity->body;

profile2_save($profile);

$entity->status = 0;
node_save($entity);

?>

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <blockquote cite> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h1> <h2 id> <h3 id> <h4 id> <h5 id> <p> <br> <img src alt height width>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.