Commit 59ea776a authored by KarenS's avatar KarenS
Browse files

#781088 More work on content migrate. A simple text field migrates correctly now.

parent 6fb49f76
......@@ -193,7 +193,7 @@ function _content_migrate_batch_process_create_fields($field_names) {
foreach ($field_names as $field_name) {
$context['message'] = "creating field $field_name";
$field_value = content_migrate_get_field_values($field_name);
// Create the field and store the new field
// definition in $context so we can retrieve it later.
try {
......@@ -203,10 +203,10 @@ function _content_migrate_batch_process_create_fields($field_names) {
$field = field_create_field($field_value);
$context['fields'][$field_name] = $field;
drupal_set_message(t("Created field @field_name", array('@field_name' => $field_name)));
// Create each of the new instances and store
// Create each of the new instances and store
// the new instance definitions in $context.
$instance_values = content_migrate_get_instance_values(NULL, $field_name);
foreach ($instance_values as $bundle => $instance_value) {
try {
$instance = field_create_instance($instance_value);
......
......@@ -52,9 +52,17 @@ function content_migrate_get_field_values($field_name = NULL) {
$field_value = $row;
// All Drupal 6 fields were attached to nodes.
$field_value['entity_types'] = array('node');
$field_value['cardinality'] = $field_value['multiple'] != 1 ? $field_value['multiple'] : FIELD_CARDINALITY_UNLIMITED;
$field_value['entity_types'] = array();
if ($field_value['multiple'] == 0) {
$field_value['cardinality'] = 1;
}
elseif ($field_value['multiple'] == 1) {
$field_value['cardinality'] = FIELD_CARDINALITY_UNLIMITED;
}
else {
$field_value['cardinality'] = $field_value['multiple'];
}
// We need column information for the old table.
$field_value['columns'] = unserialize($field_value['db_columns']);
......@@ -130,14 +138,13 @@ function content_migrate_get_instance_values($bundle = NULL, $field_name = NULL)
// Build instance values.
$instance_value['bundle'] = $instance_value['type_name'];
$instance_value['active'] = $instance_value['widget_active'];
$instance_value['default_value'] = $instance_value['widget_settings']['default_value'];
// Core does not support this, but retain it so
// another module can do something with it
// in drupal_alter.
if (isset($instance_value['widget_settings']['default_value_php'])) {
$instance_value['settings']['default_value_php'] = $instance_value['widget_settings']['default_value_php'];
$instance_value['widget']['settings']['default_value_php'] = $instance_value['widget_settings']['default_value_php'];
}
// Build widget values.
......@@ -147,12 +154,13 @@ function content_migrate_get_instance_values($bundle = NULL, $field_name = NULL)
$instance_value['widget']['type'] = $instance_value['widget_type'];
$instance_value['widget']['weight'] = $instance_value['weight'];
$instance_value['widget']['module'] = $instance_value['widget_module'];
$instance_value['widget']['active'] = $instance_value['widget_active'];
$default_settings = field_info_widget_settings($field_value['type']);
$instance_value['widget']['settings'] = array_merge($default_settings, $instance_value['widget_settings']);
// Build display values.
$instance_value['display'] = $instance_value['display_settings'];
$instance_value['display'] = array();
$label = $instance_value['display_settings']['label'];
foreach ($instance_value['display_settings'] as $context => $settings) {
......@@ -174,13 +182,12 @@ function content_migrate_get_instance_values($bundle = NULL, $field_name = NULL)
// Unset some values that don't exist on all fields.
if (isset($instance_value['widget']['settings']['default_value'])) unset($instance_value['widget']['settings']['default_value']);
if (isset($instance_value['widget']['settings']['default_value_php'])) unset($instance_value['widget']['settings']['default_value_php']);
// Let modules change these values.
drupal_alter('content_migrate_instance', $instance_value);
// Get rid of this value once CCK or some other module has handled it.
if (isset($instance_value['settings']['default_value_php'])) unset($instance_value['settings']['default_value_php']);
if (isset($instance_value['widget']['settings']['default_value_php'])) unset($instance_value['widget']['settings']['default_value_php']);
// Add instance information to instance array.
$instance_values['instances'][$instance_value['bundle']][$instance_value['field_name']] = $instance_value;
......@@ -321,7 +328,10 @@ function content_migrate_content_migrate_field_alter(&$field_value) {
switch ($field_value['type']) {
case 'text':
// Text fields are translatable.
$field_value['translatable'] = TRUE;
// The max_length field can no longer be empty
// or it will create a SQL error.
if (empty($field_value['settings']['max_length'])) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment