? profile_migrate-771008.patch
Index: profile_migrate.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/profile_migrate/profile_migrate.module,v
retrieving revision 1.3
diff -u -p -r1.3 profile_migrate.module
--- profile_migrate.module	6 Dec 2009 12:37:24 -0000	1.3
+++ profile_migrate.module	15 Apr 2010 13:15:14 -0000
@@ -404,6 +404,69 @@ function profile_migrate_fields($type_na
     $settings = content_profile_content_profile_settings();
     variable_set('content_profile_'. $type_name, $settings);
   }
+
+  // See if any users have pictures
+  $result = db_query("SELECT COUNT(*) FROM {users} WHERE picture != ''");
+  if (db_result($result) > 0) {
+    $context['message'] = t('Migrating Portrait field');
+
+    // Create a new filefield field called field_portrait
+    $field_name = 'field_portrait';
+    while (in_array($field_name, $all_fields)) {
+      $field_name .= '_1';
+    }
+    $field = array(
+      'field_name' => $field_name,
+      'type_name' => $type_name,
+      'display_settings' => array(
+        'label' => array(
+          'format' => 'hidden',
+        ),
+        'teaser' => array(
+           'format' => 'image_plain',
+           'exclude' => 0,
+        ),
+        'full' => array(
+           'format' => 'image_plain',
+           'exclude' => 0,
+        ),
+        4 => array(
+          'format' => 'default',
+          'exclude' => 0,
+        ),
+      ),
+      'widget_active' => 1,
+      'required' => 0,
+      'multiple' => 0,
+      'active' => 1,
+      'locked' => 0,
+      'widget' => array(
+        'rows' => 1,
+        'size' => 60,
+        'default_value' => array(),
+        'default_value_php' => '',
+        'label' => 'Portrait',
+        'weight' => 0,
+        'description' => 'User portrait',
+      ),
+    );
+    
+    $field['type'] = 'filefield';
+    $field['module'] = 'filefield';
+    $field['widget']['type'] = 'imagefield_widget';
+    $field['widget']['module'] = 'imagefield';
+    $field['list_field'] = 0;
+    $field['list_default'] = 1;
+    $field['description_field'] = 0;
+    $field['file_path'] = 'portraits';
+
+    content_field_instance_create($field);
+
+    variable_set('content_profile_use_'. $type_name, 1);
+    $settings = content_profile_content_profile_settings();
+    variable_set('content_profile_'. $type_name, $settings);
+  }
+
   $_SESSION['sandbox']['new_fields'] = $new_fields;
   $_SESSION['sandbox']['new_groups'] = $new_groups;
   $_SESSION['sandbox']['new_types'] = $new_types;
@@ -483,6 +546,32 @@ function profile_migrate_data($type_name
         break;
     }
   }
+
+  // See if the current uid has a picture and get the path
+  $result = db_query("SELECT picture FROM {users} WHERE uid = %d", $uid);
+  if ($filepath = db_result($result)) {
+
+    // Check for and create a portraits directory under the default files directory
+    $dest = file_directory_path() .'/portraits';
+    file_check_directory($dest, FILE_CREATE_DIRECTORY);
+
+    // Save a copy of the user picture to the portraits directory (and register it in the files table)
+    $portrait = field_file_save_file($filepath, array(), $dest);
+
+    // Attach the copied file to the node's field_portrait
+    $node->field_portrait = array(
+      0 => array(
+        'fid' => $portrait['fid'],
+        'list' => 1,
+        'data' => array(
+          'description' => '',
+          'alt' => '',
+          'title' => ''
+        )
+      )
+    );
+  }
+
   node_save($node);
   
   // Multistep processing : report progress.
