Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.367 diff -u -p -r1.367 system.install --- modules/system/system.install 12 Aug 2009 23:51:19 -0000 1.367 +++ modules/system/system.install 16 Aug 2009 09:57:06 -0000 @@ -2243,6 +2243,87 @@ function system_update_7032() { } /** + * Change profile.module fields into Field API fields. + */ +function system_update_7035() { + // Get all profile fields. + $fields = db_query('SELECT * FROM {profile_field} ORDER BY category, weight'); + + foreach ($fields as $old_field) { + // Create new fields using the field API. + $field = array( + 'field_name' => $old_field->name, + ); + + // Create field instance on the user bundle. + $instance = array( + 'field_name' => $field['field_name'], + 'bundle' => 'user', + 'description' => $old_field->explanation, + 'label' => $old_field->title, + 'required' => $old_field->required, + 'weight' => $old_field->weight, + ); + + switch ($old_field->type) { + case 'textfield': + $field['type'] = 'text'; + $instance['widget']['type'] = 'text_textfield'; + + // Only allow plain text. + $instance['settings']['text_processing'] = 0; + break; + + case 'textarea': + $field['type'] = 'text_long'; + $instance['widget']['type'] = 'text_textarea'; + // Use the default text format. + $instance['settings']['text_processing'] = 1; + break; + + case 'checkbox': + $field['type'] = 'list_boolean'; + $instance['widget']['type'] = 'options_onoff'; + // TODO: get allowed values. + break; + + case 'selection': + $field['type'] = 'list_text'; + $instance['widget']['type'] = 'options_select'; + // TODO: get allowed values. + break; + + case 'list': + $field['type'] = 'text'; + $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED; + break; + + case 'date': + case 'url': + continue; + } + + field_create_field($field); + field_create_instance($instance); + } + + // Get old field values from the profile.module table. + $results = db_query('SELECT uid, name as field_name, value FROM {profile_field} f JOIN {profile_value} v ON f.fid = v.fid WHERE value IS NOT NULL'); + + $accounts = array(); + foreach ($results as $result) { + $accounts[$result->uid]['uid'] = $result->uid; + $accounts[$result->uid][$result->field_name][0]['value'] = $result->value; + } + + // Set new field values using the field API. + foreach ($accounts as $account) { + $account = (object) $account; + field_attach_update('user', $account); + } +} + +/** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */