Issue #2262975 by Berdir: Fixed Non-Multiple field types with per-field storage are not supported in CckFieldValues.

8.0.x
Dries 2014-05-23 13:32:14 -04:00
parent da1333318a
commit 4e681e62e4
7 changed files with 130 additions and 25 deletions

View File

@ -117,18 +117,49 @@ class CckFieldValues extends DrupalSqlBase implements SourceEntityInterface {
// Handle fields that have their own table.
foreach ($this->getSourceFieldInfo($bundle) as $field_name => $field_info) {
if ($field_info['multiple'] && !$field_info['db_storage']) {
if ($field_info['multiple'] || !$field_info['db_storage']) {
// Select the data.
$table = "content_$field_name";
$data = $this
$field_query = $this
->select($table, 't')
->fields('t', array('delta') + $field_info['columns'])
->condition('vid', $row->getSourceProperty('vid'))
->execute()
->fetchAllKeyed();
->condition('vid', $row->getSourceProperty('vid'));
if ($field_info['multiple']) {
$field_query->addField('t', 'delta');
}
$data = FALSE;
foreach ($field_info['columns'] as $display_name => $column_name) {
// The database API won't allow colons in column aliases, so we
// will accept the default alias, and fix up the field names later.
// Remember how to translate the field names.
if ($field_info['type'] == 'filefield' &&
(strpos($display_name, ':list') || strpos($display_name, ':description'))) {
if (!$data) {
//$this->fileDataFields[] = $field_name . '_data';
$field_query->addField('t', $field_name . '_data');
$data = TRUE;
}
}
else {
$field_query->addField('t', $column_name);
}
}
// Set it on the row.
$row->setSourceProperty($field_name, $data);
if ($field_info['multiple']) {
foreach ($field_query->execute() as $field_row) {
foreach ($field_info['columns'] as $display_name => $column_name) {
list ( , $column) = explode(':', $display_name);
$propery_path = $field_name . '.' . $field_row['delta'] . '.' . $column;
$row->setSourceProperty($propery_path, $field_row[$column_name]);
}
}
}
else {
if ($field_row = $field_query->execute()->fetchAssoc()) {
foreach ($field_info['columns'] as $display_name => $column_name) {
$row->setSourceProperty(str_replace(':', '.', $display_name), $field_row[$column_name]);
}
}
}
}
}
parent::prepareRow($row);

View File

@ -139,7 +139,7 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
))
->values(array(
'field_name' => 'field_test',
'type_name' => 'article',
'type_name' => 'test_page',
'weight' => 1,
'label' => 'Text Field',
'widget_type' => 'text_textfield',
@ -630,7 +630,7 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
// Create the field table.
$this->createTable('content_node_field', array(
'description' => 'Table that contains field instance settings.',
'description' => 'Table that contains field settings.',
'fields' => array(
'field_name' => array(
'type' => 'varchar',
@ -712,7 +712,7 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
'type' => 'text',
'global_settings' => 'a:4:{s:15:"text_processing";s:1:"1";s:10:"max_length";s:0:"";s:14:"allowed_values";s:0:"";s:18:"allowed_values_php";s:0:"";}',
'multiple' => 0,
'db_storage' => 1,
'db_storage' => 0,
'db_columns' => serialize(array(
'value' => array(
'type' => 'text',
@ -721,6 +721,12 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
'sortable' => TRUE,
'views' => TRUE,
),
'format' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
)),
'active' => 1,
))
@ -741,7 +747,16 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
'global_settings' => '',
'multiple' => 0,
'db_storage' => 1,
'db_columns' => 'a:0:{}',
'db_columns' => serialize(array(
'value' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
'sortable' => TRUE,
'views' => TRUE,
),
)),
'active' => 1,
))
->values(array(
@ -843,6 +858,53 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
))
->execute();
$this->createTable('content_field_test', array(
'description' => 'Table for field_test',
'fields' => array(
'vid' => array(
'description' => 'The primary identifier for this version.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The {node} this version belongs to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'field_test_value' => array(
'description' => 'Test field value.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'field_test_format' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('vid'),
));
$this->database->insert('content_field_test')->fields(array(
'vid',
'nid',
'field_test_value',
'field_test_format',
))
->values(array(
'vid' => 1,
'nid' => 1,
'field_test_value' => 'This is a shared text field',
'field_test_format' => 1,
))
->execute();
$this->createTable('content_field_test_two', array(
'description' => 'Table for field_test_two',
'fields' => array(

View File

@ -303,12 +303,12 @@ class Drupal6Node extends Drupal6DumpBase {
'unsigned' => TRUE,
'not null' => TRUE,
),
'field_test_value' => array(
'field_test_three_value' => array(
'description' => 'Test field column.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE
),
),
'primary key' => array('vid'),
@ -318,12 +318,12 @@ class Drupal6Node extends Drupal6DumpBase {
array(
'nid',
'vid',
'field_test_value',
'field_test_three_value',
))
->values(array(
'nid' => 1,
'vid' => 1,
'field_test_value' => 'This is a text field',
'field_test_three_value' => '42.42',
))
->execute();
$this->setModuleVersion('content', 6001);

View File

@ -58,6 +58,16 @@ class MigrateCckFieldValuesTest extends MigrateNodeTestBase {
'field_name' => 'field_test_two',
'bundle' => 'story',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'name' => 'field_test_three',
'type' => 'decimal',
))->save();
entity_create('field_instance_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_three',
'bundle' => 'story',
))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
@ -87,9 +97,11 @@ class MigrateCckFieldValuesTest extends MigrateNodeTestBase {
*/
public function testCckFields() {
$node = node_load(1);
$this->assertEqual($node->field_test->value, 'This is a text field', "Single field storage field is correct.");
$this->assertEqual($node->field_test->value, 'This is a shared text field', "Shared field storage field is correct.");
$this->assertEqual($node->field_test->format, 1, "Shared field storage field with multiple columns is correct.");
$this->assertEqual($node->field_test_two->value, 10, 'Multi field storage field is correct');
$this->assertEqual($node->field_test_two[1]->value, 20, 'Multi field second value is correct.');
$this->assertEqual($node->field_test_three->value, '42.42', 'Single field second value is correct.');
}
}

View File

@ -40,7 +40,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupalTestBase {
public function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'article'))->save();
entity_create('node_type', array('type' => 'test_page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Create the node preview view mode.
entity_create('view_mode', array('id' => 'node.preview', 'targetEntityType' => 'node'))->save();
@ -102,7 +102,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupalTestBase {
$this->assertEqual($display->getComponent($field_name), $expected);
// Test migrate worked with multiple bundles.
$display = entity_load('entity_view_display', 'node.article.teaser');
$display = entity_load('entity_view_display', 'node.test_page.teaser');
$this->assertEqual($display->getComponent($field_name), $expected);
// Test RSS because that has been converted from 4 to rss.

View File

@ -66,13 +66,13 @@ class MigrateFieldInstanceTest extends MigrateDrupalTestBase {
'd6_node_type' => array(
array(array('page'), array('page')),
array(array('story'), array('story')),
array(array('article'), array('article')),
array(array('test_page'), array('test_page')),
),
);
$this->prepareIdMappings($id_mappings);
entity_create('node_type', array('type' => 'page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
entity_create('node_type', array('type' => 'article'))->save();
entity_create('node_type', array('type' => 'test_page'))->save();
$migration = entity_load('migration', 'd6_field_instance');
$dumps = array(

View File

@ -47,7 +47,7 @@ class MigrateFieldWidgetSettingsTest extends MigrateDrupalTestBase {
public function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'article'))->save();
entity_create('node_type', array('type' => 'test_page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Add some id mappings for the dependant migrations.