Drupal 6 to Drupal 7 Profile Migration

Drupal 6 to Drupal 7 Profile Migration

Working on the Raintree Village upgrade to Drupal 7 and came on the problem of migrating D6 Content Profile module profiles to D7 Profile2.

We are trying to move profile data from Drupal 6 nodes that are content types to Drupal 7 data in entities. There is no direct upgrade path so thanks to the insperation gathered here I was able to use VBO to move the data.

I already had a view set to show a table for the users with a total of 4 fields showing. In the view settings I added a "Bulk operations: User" field and checked the "Execute arbitrary PHP script" setting. This gives the ability to update the live view by using a script that's pasted in a text field. Checkboxes are provided for selection of which users to update or "All" can be selected.

This process works on fields that are in the node even if they aren't used in the view. Of course your Profile2 profile type is already set up if you have a view using it. Below is the code used in this project.

  1. <?php
  2. $newprofile = profile2_load_by_user($entity->uid, 'main');
  3.  
  4. $query = new EntityFieldQuery();
  5.  
  6. $query->entityCondition('entity_type','node')
  7. ->entityCondition('bundle','uprofile')
  8. ->propertyCondition('uid',$entity->uid);
  9. $result = $query->execute();
  10.  
  11. if ($result && $result['node']) {
  12. $item = array_pop($result['node']);
  13. $node = node_load($item->nid);
  14.  
  15. if (!$newprofile) {
  16. $newprofile = profile2_create(array('type'=>'main','uid'=>$entity->uid));
  17. }
  18. // Question on whether field_name is going to come from title or field_name in the node.
  19. //$newprofile->field_name['und'][0]['value'] = $node->title;
  20. $newprofile->field_name['und'][0]['value'] = $node->field_name['und'][0]['value'];
  21. $newprofile->field_about_me = $node->field_about_me;
  22. $newprofile->field_address = $node->field_address;
  23. $newprofile->field_aim = $node->field_aim;
  24. $newprofile->field_blog = $node->field_blog;
  25. $newprofile->field_children = $node->field_children;
  26. $newprofile->field_facebook = $node->field_facebook;
  27. $newprofile->field_favorite1 = $node->field_favorite1;
  28. $newprofile->field_favorite2 = $node->field_favorite2;
  29. $newprofile->field_favorite3 = $node->field_favorite3;
  30. $newprofile->field_friendfeed = $node->field_friendfeed;
  31. $newprofile->field_gender = $node->field_gender;
  32. $newprofile->field_google = $node->field_google;
  33. $newprofile->field_homepage = $node->homepage;
  34. $newprofile->field_icq = $node->field_icq;
  35. $newprofile->field_interests = $node->field_interests;
  36. $newprofile->field_linkedin = $node->field_linkedin;
  37. $newprofile->field_myspace = $node->field_myspace;
  38. // field_name is above
  39. $newprofile->field_occupation = $node->field_occupation;
  40. $newprofile->field_skype = $node->field_skype;
  41. $newprofile->field_status = $node->status;
  42. $newprofile->field_twitter = $node->field_twitter;
  43. $newprofile->field_yahoo = $node->field_yahoo;
  44. $newprofile->field_zodiac_sign = $node->zodiac_sign;
  45. $newprofile->field_ethnicity = $node->field_ethnicity;
  46.  
  47. profile2_save($newprofile);
  48. }
  49.  
  50. ?>