Commit c28199f6 authored by catch's avatar catch

Issue #2842222 by maxocub, heddn, vasi, Jo Fitzgerald, masipila,...

Issue #2842222 by maxocub, heddn, vasi, Jo Fitzgerald, masipila, jeffwpetersen, catch, phenaproxima, markabur, quietone, mikeryan: D7 Plain text fields incorrectly migrated to D8 as Text (formatted)
parent 1f6adcd8
......@@ -9,6 +9,10 @@ source:
constants:
status: true
process:
type:
plugin: process_field
source: type
method: getFieldType
entity_type: entity_type
field_name: field_name
bundle: bundle
......
......@@ -88,15 +88,15 @@ protected function assertEntity($id, $expected_label, $expected_field_type, $is_
/** @var \Drupal\field\FieldConfigInterface $field */
$field = FieldConfig::load($id);
$this->assertTrue($field instanceof FieldConfigInterface);
$this->assertIdentical($expected_label, $field->label());
$this->assertIdentical($expected_field_type, $field->getType());
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
$this->assertIdentical($expected_bundle, $field->getTargetBundle());
$this->assertIdentical($expected_name, $field->getName());
$this->assertEqual($is_required, $field->isRequired());
$this->assertIdentical($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
$this->assertSame($expected_translatable, $field->isTranslatable());
$this->assertInstanceOf(FieldConfigInterface::class, $field);
$this->assertEquals($expected_label, $field->label());
$this->assertEquals($expected_field_type, $field->getType());
$this->assertEquals($expected_entity_type, $field->getTargetEntityTypeId());
$this->assertEquals($expected_bundle, $field->getTargetBundle());
$this->assertEquals($expected_name, $field->getName());
$this->assertEquals($is_required, $field->isRequired());
$this->assertEquals($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
$this->assertEquals($expected_translatable, $field->isTranslatable());
}
/**
......@@ -144,7 +144,7 @@ public function testFieldInstances() {
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'text', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'string', FALSE, FALSE);
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE, FALSE);
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE, FALSE);
......@@ -154,4 +154,61 @@ public function testFieldInstances() {
$this->assertLinkFields('node.blog.field_link', DRUPAL_REQUIRED);
}
/**
* Tests the migration of text field instances with different text processing.
*/
public function testTextFieldInstances() {
// All text and text_long field instances using a field base that has only
// plain text instances should be migrated to string and string_long fields.
// All text_with_summary field instances using a field base that has only
// plain text instances should not have been migrated since there's no such
// thing as a string_with_summary field.
$this->assertEntity('node.page.field_text_plain', 'Text plain', 'string', FALSE, FALSE);
$this->assertEntity('node.article.field_text_plain', 'Text plain', 'string', FALSE, TRUE);
$this->assertEntity('node.page.field_text_long_plain', 'Text long plain', 'string_long', FALSE, FALSE);
$this->assertEntity('node.article.field_text_long_plain', 'Text long plain', 'string_long', FALSE, TRUE);
$this->assertNull(FieldConfig::load('node.page.field_text_sum_plain'));
$this->assertNull(FieldConfig::load('node.article.field_text_sum_plain'));
// All text, text_long and text_with_summary field instances using a field
// base that has only filtered text instances should be migrated to text,
// text_long and text_with_summary fields.
$this->assertEntity('node.page.field_text_filtered', 'Text filtered', 'text', FALSE, FALSE);
$this->assertEntity('node.article.field_text_filtered', 'Text filtered', 'text', FALSE, TRUE);
$this->assertEntity('node.page.field_text_long_filtered', 'Text long filtered', 'text_long', FALSE, FALSE);
$this->assertEntity('node.article.field_text_long_filtered', 'Text long filtered', 'text_long', FALSE, TRUE);
$this->assertEntity('node.page.field_text_sum_filtered', 'Text summary filtered', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('node.article.field_text_sum_filtered', 'Text summary filtered', 'text_with_summary', FALSE, TRUE);
// All text, text_long and text_with_summary field instances using a field
// base that has both plain text and filtered text instances should not have
// been migrated.
$this->assertNull(FieldConfig::load('node.page.field_text_plain_filtered'));
$this->assertNull(FieldConfig::load('node.article.field_text_plain_filtered'));
$this->assertNull(FieldConfig::load('node.page.field_text_long_plain_filtered'));
$this->assertNull(FieldConfig::load('node.article.field_text_long_plain_filtered'));
$this->assertNull(FieldConfig::load('node.page.field_text_sum_plain_filtered'));
$this->assertNull(FieldConfig::load('node.article.field_text_sum_plain_filtered'));
// For each text field instances that were skipped, there should be a log
// message with the required steps to fix this.
$migration = $this->getMigration('d7_field_instance');
$messages = $migration->getIdMap()->getMessageIterator()->fetchAll();
$errors = array_map(function($message) {return $message->message;}, $messages);
$this->assertCount(8, $errors);
sort($errors);
$message = 'Can\'t migrate source field field_text_long_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[0], $message);
$this->assertEquals($errors[1], $message);
$message = 'Can\'t migrate source field field_text_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[2], $message);
$this->assertEquals($errors[3], $message);
$message = 'Can\'t migrate source field field_text_sum_plain of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[4], $message);
$this->assertEquals($errors[5], $message);
$message = 'Can\'t migrate source field field_text_sum_plain_filtered of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[6], $message);
$this->assertEquals($errors[7], $message);
}
}
......@@ -57,11 +57,11 @@ protected function assertEntity($id, $expected_type, $expected_translatable, $ex
/** @var \Drupal\field\FieldStorageConfigInterface $field */
$field = FieldStorageConfig::load($id);
$this->assertTrue($field instanceof FieldStorageConfigInterface);
$this->assertIdentical($expected_name, $field->getName());
$this->assertIdentical($expected_type, $field->getType());
$this->assertEqual($expected_translatable, $field->isTranslatable());
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
$this->assertInstanceOf(FieldStorageConfigInterface::class, $field);
$this->assertEquals($expected_name, $field->getName());
$this->assertEquals($expected_type, $field->getType());
$this->assertEquals($expected_translatable, $field->isTranslatable());
$this->assertEquals($expected_entity_type, $field->getTargetEntityTypeId());
if ($expected_cardinality === 1) {
$this->assertFalse($field->isMultiple());
......@@ -69,7 +69,7 @@ protected function assertEntity($id, $expected_type, $expected_translatable, $ex
else {
$this->assertTrue($field->isMultiple());
}
$this->assertIdentical($expected_cardinality, $field->getCardinality());
$this->assertEquals($expected_cardinality, $field->getCardinality());
}
/**
......@@ -91,7 +91,7 @@ public function testFields() {
$this->assertEntity('node.field_tags', 'entity_reference', TRUE, -1);
$this->assertEntity('node.field_term_reference', 'entity_reference', TRUE, 1);
$this->assertEntity('node.taxonomy_forums', 'entity_reference', TRUE, 1);
$this->assertEntity('node.field_text', 'text', TRUE, 1);
$this->assertEntity('node.field_text', 'string', TRUE, 1);
$this->assertEntity('node.field_text_list', 'list_string', TRUE, 3);
$this->assertEntity('node.field_boolean', 'boolean', TRUE, 1);
$this->assertEntity('node.field_email', 'email', TRUE, -1);
......@@ -105,24 +105,57 @@ public function testFields() {
// Assert that the taxonomy term reference fields are referencing the
// correct entity type.
$field = FieldStorageConfig::load('node.field_term_reference');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.taxonomy_forums');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
// Assert that the entityreference fields are referencing the correct
// entity type.
$field = FieldStorageConfig::load('node.field_node_entityreference');
$this->assertIdentical('node', $field->getSetting('target_type'));
$this->assertEquals('node', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_user_entityreference');
$this->assertIdentical('user', $field->getSetting('target_type'));
$this->assertEquals('user', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_term_entityreference');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
}
/**
* Tests the migration of text fields with different text processing.
*/
public function testTextFields() {
// All text and text_long field bases that have only plain text instances
// should be migrated to string and string_long fields.
// All text_with_summary field bases that have only plain text instances
// should not have been migrated since there's no such thing as a
// string_with_summary field.
$this->assertEntity('node.field_text_plain', 'string', TRUE, 1);
$this->assertEntity('node.field_text_long_plain', 'string_long', TRUE, 1);
$this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain'));
// All text, text_long and text_with_summary field bases that have only
// filtered text instances should be migrated to text, text_long and
// text_with_summary fields.
$this->assertEntity('node.field_text_filtered', 'text', TRUE, 1);
$this->assertEntity('node.field_text_long_filtered', 'text_long', TRUE, 1);
$this->assertEntity('node.field_text_sum_filtered', 'text_with_summary', TRUE, 1);
// All text, text_long and text_with_summary field bases that have both
// plain text and filtered text instances should not have been migrated.
$this->assertNull(FieldStorageConfig::load('node.field_text_plain_filtered'));
$this->assertNull(FieldStorageConfig::load('node.field_text_long_plain_filtered'));
$this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain_filtered'));
// Validate that the source count and processed count match up.
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
// For each text field bases that were skipped, there should be a log
// message with the required steps to fix this.
$migration = $this->getMigration('d7_field');
$this->assertSame($migration->getSourcePlugin()
->count(), $migration->getIdMap()->processedCount());
$messages = $migration->getIdMap()->getMessageIterator()->fetchAll();
$errors = array_map(function($message) {return $message->message;}, $messages);
sort($errors);
$this->assertCount(4, $errors);
$this->assertEquals($errors[0], 'Can\'t migrate source field field_text_long_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
$this->assertEquals($errors[1], 'Can\'t migrate source field field_text_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
$this->assertEquals($errors[2], 'Can\'t migrate source field field_text_sum_plain of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
$this->assertEquals($errors[3], 'Can\'t migrate source field field_text_sum_plain_filtered of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -50,8 +50,8 @@ protected function getEntityCounts() {
'configurable_language' => 4,
'contact_form' => 3,
'editor' => 2,
'field_config' => 53,
'field_storage_config' => 40,
'field_config' => 63,
'field_storage_config' => 45,
'file' => 3,
'filter_format' => 7,
'image_style' => 6,
......
......@@ -2,7 +2,9 @@
namespace Drupal\text\Plugin\migrate\field\d7;
use Drupal\text\Plugin\migrate\field\d6\TextField as D6TextField;
use Drupal\migrate\Row;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateField(
......@@ -15,4 +17,51 @@
* core = {7}
* )
*/
class TextField extends D6TextField {}
class TextField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldType(Row $row) {
$type = $row->getSourceProperty('type');
$plain_text = FALSE;
$filtered_text = FALSE;
foreach ($row->getSourceProperty('instances') as $instance) {
// Check if this field has plain text instances, filtered text instances,
// or both.
$data = unserialize($instance['data']);
switch ($data['settings']['text_processing']) {
case '0':
$plain_text = TRUE;
break;
case '1':
$filtered_text = TRUE;
break;
}
}
if (in_array($type, ['text', 'text_long'])) {
// If a text or text_long field has only plain text instances, migrate it
// to a string or string_long field.
if ($plain_text && !$filtered_text) {
$type = str_replace(['text', 'text_long'], ['string', 'string_long'], $type);
}
// If a text or text_long field has both plain text and filtered text
// instances, skip the row.
elseif ($plain_text && $filtered_text) {
$field_name = $row->getSourceProperty('field_name');
throw new MigrateSkipRowException("Can't migrate source field $field_name configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
}
}
elseif ($type == 'text_with_summary' && $plain_text) {
// If a text_with_summary field has plain text instances, skip the row
// since there's no such thing as a string_with_summary field.
$field_name = $row->getSourceProperty('field_name');
throw new MigrateSkipRowException("Can't migrate source field $field_name of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
}
return $type;
}
}
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