Commit 6fb49f76 authored by KarenS's avatar KarenS
Browse files

#781088 by mradcliffe and KarenS, initial work to get D6 to D7 field migration code working again.

parent 1ea293eb
......@@ -197,6 +197,7 @@ function _content_migrate_batch_process_create_fields($field_names) {
// Create the field and store the new field
// definition in $context so we can retrieve it later.
try {
// @bug mradcliffe - $data doesn't seem to exist in this context..
unset($data['field']['columns']);
unset($data['field']['db_storage']);
$field = field_create_field($field_value);
......@@ -209,7 +210,7 @@ function _content_migrate_batch_process_create_fields($field_names) {
foreach ($instance_values as $bundle => $instance_value) {
try {
$instance = field_create_instance($instance_value);
$context['instances'][$fieldname][$instance['bundle']] = $instance;
$context['instances'][$field_name][$instance['bundle']] = $instance;
drupal_set_message(t("Created instance of @field_name in bundle @bundle.", array(
'@field_name' => $field_name, '@bundle' => $type_names[$instance['bundle']])));
}
......@@ -248,34 +249,34 @@ function _content_migrate_batch_process_migrate_data($field_name) {
$new_revision_table = content_migrate_new_revision($field);
$new_columns = content_migrate_new_columns($field);
$query = db_select($old_table, 'old');
$query = db_select($old_table, 'old_table');
// We need a new columns for bundle name, entity type, and language.
// We need new columns for bundle name, entity type, and language.
$query->addExpression("'". $instance_value['bundle'] ."'", 'bundle');
$query->addExpression(1, 'etid');
$query->addExpression("'node'", 'entity_type');
$query->addExpression("'". LANGUAGE_NONE ."'", 'language');
// There are new names for what were the nid and vid columns.
$query->addField('old', 'nid', 'entity_id');
$query->addField('old', 'vid', 'revision_id');
$query->addField('old_table', 'nid', 'entity_id');
$query->addField('old_table', 'vid', 'revision_id');
// Add the field columns to the select query.
// Use the new column names as aliases in case the
// name changed, hopefully none did.
foreach ($old_cols as $key => $col) {
$query->addField('old', $col, $new_columns[$key]);
$query->addField('old_table', $col, $new_columns[$key]);
}
// Add delta, or construct it if missing.
if (content_migrate_storage_type($field_value, $instance_value) == CONTENT_DB_STORAGE_PER_FIELD) {
$query->addField('old', 'delta', 'delta');
$query->addField('old_table', 'delta', 'delta');
}
else {
$query->addExpression(0, 'delta');
}
// Now copy the data to the new field tables.
try {
// try {
db_insert($new_table)
->from($query)
->execute();
......@@ -284,11 +285,11 @@ function _content_migrate_batch_process_migrate_data($field_name) {
->execute();
drupal_set_message(t('Data migrated for field @field_name in bundle @bundle.', array(
'@field_name' => $field_name, '@bundle' => $instance_value['bundle'])));
}
/* }
catch (Exception $e) {
drupal_set_message(t('Data could not be migrated for field @field_name in bundle @bundle.', array(
'@field_name' => $field_name, '@bundle' => $instance_value['bundle'])), 'error');
drupal_set_message($e, 'error');
}
} */
}
}
\ No newline at end of file
}
......@@ -127,7 +127,7 @@ function content_migrate_get_instance_values($bundle = NULL, $field_name = NULL)
foreach (array('widget_settings', 'display_settings', 'global_settings') as $key) {
$instance_value[$key] = (!empty($instance_value[$key])) ? (array) unserialize($instance_value[$key]) : array();
}
// Build instance values.
$instance_value['bundle'] = $instance_value['type_name'];
$instance_value['active'] = $instance_value['widget_active'];
......@@ -136,8 +136,10 @@ function content_migrate_get_instance_values($bundle = NULL, $field_name = NULL)
// Core does not support this, but retain it so
// another module can do something with it
// in drupal_alter.
$instance_value['settings']['default_value_php'] = $instance_value['widget_settings']['default_value_php'];
if (isset($instance_value['widget_settings']['default_value_php'])) {
$instance_value['settings']['default_value_php'] = $instance_value['widget_settings']['default_value_php'];
}
// Build widget values.
$instance_value['widget'] = array();
......@@ -151,34 +153,41 @@ function content_migrate_get_instance_values($bundle = NULL, $field_name = NULL)
// Build display values.
$instance_value['display'] = $instance_value['display_settings'];
$label = $instance_value['display']['label'];
unset($instance_value['display']['label']);
foreach ($instance_value['display'] as $context => $settings) {
$label = $instance_value['display_settings']['label'];
foreach ($instance_value['display_settings'] as $context => $settings) {
// @TODO Multigroup fields have some unexpected elements, we need to work out what should happen to them.
if ($context == 'parent' || $context == 'weight') {
continue;
}
$instance_value['display'][$context]['label'] = $label['format'];
// The format used in D6 may not match the formatter in D7.
// Fix it using drupal_alter().
$instance_value['display'][$context]['type'] = $settings['format'];
$instance_value['display'][$context]['settings'] = field_info_formatter_settings($settings['format']);
unset($instance_value['display'][$context]['exclude'], $instance_value['display'][$context]['format']);
}
// Unset unneeded values.
unset($instance_value['type_name'], $instance_value['global_settings'], $instance_value['widget_settings'], $instance_value['display_settings'], $instance_value['widget_module'], $instance_value['widget_active'], $instance_value['widget']['settings']['default_value'], $instance_value['widget']['settings']['default_value_php']);
unset($instance_value['type_name'], $instance_value['global_settings'], $instance_value['widget_settings'], $instance_value['display_settings'], $instance_value['widget_module'], $instance_value['widget_active']);
// 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.
unset($instance_value['settings']['default_value_php']);
if (isset($instance_value['settings']['default_value_php'])) unset($instance_value['settings']['default_value_php']);
// Add instance information to instance array.
$instance_values['instances'][$instance_value['bundle']][$instance_value['field_name']] = $instance_value;
$instance_values['fields'][$instance_value['field_name']][$instance_value['bundle']] = $instance_value;
}
}
if (!empty($bundle)) {
if (!empty($field_name)) {
return $instance_values['instances'][$bundle][$field_name];
......@@ -488,4 +497,4 @@ function content_migrate_content_migrate_instance_alter(&$instance_value) {
}
break;
}
}
\ No newline at end of file
}
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