Commit 242b03da authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2863437 by maxocub, masipila: Migrate Drupal 7 title data to Drupal 8

parent a116715c
......@@ -40,6 +40,15 @@ public function prepareRow(Row $row) {
$row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid));
}
// If the comment subject was replaced by a real field using the Drupal 7
// Title module, use the field value instead of the comment subject.
if ($this->moduleExists('title')) {
$subject_field = $row->getSourceProperty('subject_field');
if (isset($subject_field[0]['value'])) {
$row->setSourceProperty('subject', $subject_field[0]['value']);
}
}
return parent::prepareRow($row);
}
......
......@@ -78,6 +78,13 @@ public function testMigration() {
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('1', $node->id());
// Tests that comments that used the Drupal 7 Title module and that have
// their subject replaced by a real field are correctly migrated.
$comment = Comment::load(2);
$this->assertInstanceOf(Comment::class, $comment);
$this->assertSame('TNG for the win!', $comment->getSubject());
$this->assertSame('TNG is better than DS9.', $comment->comment_body->value);
}
}
......@@ -65,6 +65,10 @@ public function providerSource() {
'id' => '1',
'translatable' => '0',
],
[
'id' => '2',
'translatable' => '1',
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
......@@ -76,6 +80,15 @@ public function providerSource() {
'data' => 'a:0:{}',
'deleted' => '0',
],
[
'id' => '15',
'field_id' => '2',
'field_name' => 'subject_field',
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$tests[0]['source_data']['field_data_comment_body'] = [
[
......@@ -90,6 +103,26 @@ public function providerSource() {
'comment_body_format' => 'filtered_html',
],
];
$tests[0]['source_data']['field_data_subject_field'] = [
[
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'subject_field_value' => 'A comment (subject_field)',
'subject_field_format' => NULL,
],
];
$tests[0]['source_data']['system'] = [
[
'name' => 'title',
'type' => 'module',
'status' => 1,
],
];
// The expected results.
$tests[0]['expected_data'] = [
......@@ -98,7 +131,7 @@ public function providerSource() {
'pid' => '0',
'nid' => '1',
'uid' => '1',
'subject' => 'A comment',
'subject' => 'A comment (subject_field)',
'hostname' => '::1',
'created' => '1421727536',
'changed' => '1421727536',
......
......@@ -34,6 +34,19 @@ public function query() {
->condition('fci.deleted', 0);
$query->join('field_config_instance', 'fci', 'fc.id = fci.field_id');
// If the Drupal 7 Title module is enabled, we don't want to migrate the
// fields it provides. The values of those fields will be migrated to the
// base fields they were replacing.
if ($this->moduleExists('title')) {
$title_fields = [
'title_field',
'name_field',
'description_field',
'subject_field',
];
$query->condition('fc.field_name', $title_fields, 'NOT IN');
}
return $query;
}
......
......@@ -42,6 +42,19 @@ public function query() {
}
}
// If the Drupal 7 Title module is enabled, we don't want to migrate the
// fields it provides. The values of those fields will be migrated to the
// base fields they were replacing.
if ($this->moduleExists('title')) {
$title_fields = [
'title_field',
'name_field',
'description_field',
'subject_field',
];
$query->condition('fc.field_name', $title_fields, 'NOT IN');
}
return $query;
}
......
......@@ -132,6 +132,16 @@ public function testFieldInstances() {
$this->assertLinkFields('node.test_content_type.field_link', DRUPAL_OPTIONAL);
$this->assertLinkFields('node.article.field_link', DRUPAL_DISABLED);
$this->assertLinkFields('node.blog.field_link', DRUPAL_REQUIRED);
// Tests that fields created by the Title module are not migrated.
$title_field = FieldConfig::load('node.test_content_type.title_field');
$this->assertNull($title_field);
$subject_field = FieldConfig::load('comment.comment_node_article.subject_field');
$this->assertNull($subject_field);
$name_field = FieldConfig::load('taxonomy_term.test_vocabulary.name_field');
$this->assertNull($name_field);
$description_field = FieldConfig::load('taxonomy_term.test_vocabulary.description_field');
$this->assertNull($description_field);
}
/**
......
......@@ -105,6 +105,16 @@ public function testFields() {
$this->assertEntity('node.field_date_without_time', 'datetime', TRUE, 1);
$this->assertEntity('node.field_datetime_without_time', 'datetime', TRUE, 1);
// Tests that fields created by the Title module are not migrated.
$title_field = FieldStorageConfig::load('node.title_field');
$this->assertNull($title_field);
$subject_field = FieldStorageConfig::load('comment.subject_field');
$this->assertNull($subject_field);
$name_field = FieldStorageConfig::load('taxonomy_term.name_field');
$this->assertNull($name_field);
$description_field = FieldStorageConfig::load('taxonomy_term.description_field');
$this->assertNull($description_field);
// Assert that the taxonomy term reference fields are referencing the
// correct entity type.
$field = FieldStorageConfig::load('node.field_term_reference');
......
......@@ -138,6 +138,7 @@ class ReviewForm extends MigrateUpgradeFormBase {
'simpletest',
'stylizer',
'term_depth',
'title',
'toolbar',
'translation',
'trigger',
......
......@@ -53,7 +53,7 @@ protected function getEntityCounts() {
'block' => 25,
'block_content' => 1,
'block_content_type' => 1,
'comment' => 1,
'comment' => 2,
// The 'standard' profile provides the 'comment' comment type, and the
// migration creates 6 comment types, one per node type.
'comment_type' => 7,
......@@ -98,7 +98,7 @@ protected function getEntityCounts() {
protected function getEntityCountsIncremental() {
$counts = $this->getEntityCounts();
$counts['block_content'] = 2;
$counts['comment'] = 2;
$counts['comment'] = 3;
$counts['file'] = 4;
$counts['menu_link_content'] = 11;
$counts['node'] = 6;
......
......@@ -123,6 +123,7 @@ protected function getAvailablePaths() {
'simpletest',
'stylizer',
'term_depth',
'title',
'toolbar',
'translation',
'trigger',
......
......@@ -60,7 +60,7 @@ protected function getEntityCounts() {
'block' => 25,
'block_content' => 1,
'block_content_type' => 1,
'comment' => 1,
'comment' => 2,
// The 'standard' profile provides the 'comment' comment type, and the
// migration creates 6 comment types, one per node type.
'comment_type' => 7,
......@@ -106,7 +106,7 @@ protected function getEntityCounts() {
protected function getEntityCountsIncremental() {
$counts = $this->getEntityCounts();
$counts['block_content'] = 2;
$counts['comment'] = 2;
$counts['comment'] = 3;
$counts['file'] = 4;
$counts['menu_link_content'] = 13;
$counts['node'] = 6;
......
......@@ -127,6 +127,16 @@ public function prepareRow(Row $row) {
if ($row->getSourceProperty('tnid') == 0) {
$row->setSourceProperty('tnid', $row->getSourceProperty('nid'));
}
// If the node title was replaced by a real field using the Drupal 7 Title
// module, use the field value instead of the node title.
if ($this->moduleExists('title')) {
$title_field = $row->getSourceProperty('title_field');
if (isset($title_field[0]['value'])) {
$row->setSourceProperty('title', $title_field[0]['value']);
}
}
return parent::prepareRow($row);
}
......
......@@ -71,6 +71,15 @@ public function prepareRow(Row $row) {
$row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, $field_language));
}
// If the node title was replaced by a real field using the Drupal 7 Title
// module, use the field value instead of the node title.
if ($this->moduleExists('title')) {
$title_field = $row->getSourceProperty('title_field');
if (isset($title_field[0]['value'])) {
$row->setSourceProperty('title', $title_field[0]['value']);
}
}
return parent::prepareRow($row);
}
......
......@@ -154,8 +154,8 @@ protected function assertRevision($id, $title, $uid, $log, $timestamp) {
* Test node migration from Drupal 7 to 8.
*/
public function testNode() {
$this->assertEntity(1, 'test_content_type', 'en', 'A Node', '2', TRUE, '1421727515', '1441032132', TRUE, FALSE);
$this->assertRevision(1, 'A Node', '1', NULL, '1441032132');
$this->assertEntity(1, 'test_content_type', 'en', 'An English Node', '2', TRUE, '1421727515', '1441032132', TRUE, FALSE);
$this->assertRevision(1, 'An English Node', '1', NULL, '1441032132');
$node = Node::load(1);
$this->assertTrue($node->field_boolean->value);
......@@ -183,8 +183,10 @@ public function testNode() {
// Test that fields translated with Entity Translation are migrated.
$node_fr = $node->getTranslation('fr');
$this->assertEquals('A French Node', $node_fr->getTitle());
$this->assertEquals('6', $node_fr->field_integer->value);
$node_is = $node->getTranslation('is');
$this->assertEquals('An Icelandic Node', $node_is->getTitle());
$this->assertEquals('7', $node_is->field_integer->value);
$node = Node::load(2);
......
......@@ -79,6 +79,21 @@ public function providerSource() {
'translatable' => 1,
'deleted' => 0,
],
[
'id' => 2,
'field_name' => 'title_field',
'type' => 'text',
'module' => 'text',
'active' => 1,
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => 1,
'locked' => 1,
'data' => 'a:0:{}',
'cardinality' => 1,
'translatable' => 1,
'deleted' => 0,
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
......@@ -91,7 +106,7 @@ public function providerSource() {
'deleted' => 0,
],
[
'id' => 1,
'id' => 2,
'field_id' => 1,
'field_name' => 'body',
'entity_type' => 'node',
......@@ -99,6 +114,15 @@ public function providerSource() {
'data' => 'a:0:{}',
'deleted' => 0,
],
[
'id' => 3,
'field_id' => 2,
'field_name' => 'title_field',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:0:{}',
'deleted' => 0,
],
];
$tests[0]['source_data']['field_revision_body'] = [
[
......@@ -150,6 +174,41 @@ public function providerSource() {
'body_format' => 'filtered_html',
],
];
$tests[0]['source_data']['field_revision_title_field'] = [
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'English Source',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'fr',
'delta' => '0',
'title_field_value' => 'French Translation',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'es',
'delta' => '0',
'title_field_value' => 'Spanish Translation',
'title_field_format' => NULL,
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => 1,
......@@ -210,6 +269,13 @@ public function providerSource() {
'sticky' => 0,
],
];
$tests[0]['source_data']['system'] = [
[
'name' => 'title',
'type' => 'module',
'status' => 1,
],
];
// The expected results.
$tests[0]['expected_data'] = [
......@@ -223,7 +289,7 @@ public function providerSource() {
'created' => 1531343508,
'changed' => 1531343508,
'type' => 'page',
'title' => 'Translated page',
'title' => 'French Translation',
'promote' => 0,
'sticky' => 0,
'log' => '',
......@@ -247,7 +313,7 @@ public function providerSource() {
'created' => 1531343528,
'changed' => 1531343528,
'type' => 'page',
'title' => 'Translated page',
'title' => 'Spanish Translation',
'promote' => 0,
'sticky' => 0,
'log' => '',
......
......@@ -175,6 +175,10 @@ public function providerSource() {
'id' => '2',
'translatable' => '0',
],
[
'id' => '3',
'translatable' => '1',
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
......@@ -195,6 +199,15 @@ public function providerSource() {
'data' => 'a:0:{}',
'deleted' => '0',
],
[
'id' => '4',
'field_id' => '3',
'field_name' => 'title_field',
'entity_type' => 'node',
'bundle' => 'article',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$tests[0]['source_data']['field_revision_body'] = [
[
......@@ -258,6 +271,48 @@ public function providerSource() {
'body_format' => 'filtered_html',
],
];
$tests[0]['source_data']['field_revision_title_field'] = [
[
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '5',
'revision_id' => '5',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'node title 5 (title_field)',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '6',
'revision_id' => '6',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'node title 5 (title_field)',
'title_field_format' => NULL,
],
[
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '7',
'revision_id' => '7',
'language' => 'en',
'delta' => '0',
'title_field_value' => 'node title 5 (title_field)',
'title_field_format' => NULL,
],
];
$tests[0]['source_data']['system'] = [
[
'name' => 'title',
'type' => 'module',
'status' => 1,
],
];
// The expected results.
$tests[0]['expected_data'] = [
......@@ -318,7 +373,7 @@ public function providerSource() {
'vid' => 5,
'type' => 'article',
'language' => 'en',
'title' => 'node title 5',
'title' => 'node title 5 (title_field)',
'node_uid' => 1,
'revision_uid' => 2,
'status' => 1,
......@@ -344,7 +399,7 @@ public function providerSource() {
'vid' => 6,
'type' => 'article',
'language' => 'en',
'title' => 'node title 5',
'title' => 'node title 5 (title_field)',
'node_uid' => 1,
'revision_uid' => 1,
'status' => 1,
......
......@@ -31,7 +31,7 @@ public function providerSource() {
'vid' => 7,
'type' => 'article',
'language' => 'fr',
'title' => 'fr - node title 5',
'title' => 'node title 5 (title_field)',
'node_uid' => 1,
'revision_uid' => 1,
'status' => 1,
......
......@@ -75,6 +75,20 @@ public function prepareRow(Row $row) {
$current_tid = $row->getSourceProperty('tid');
$row->setSourceProperty('is_container', in_array($current_tid, $forum_container_tids));
// If the term name or term description were replaced by real fields using
// the Drupal 7 Title module, use the fields value instead of the term name
// or term description.
if ($this->moduleExists('title')) {
$name_field = $row->getSourceProperty('name_field');
if (isset($name_field[0]['value'])) {
$row->setSourceProperty('name', $name_field[0]['value']);
}
$description_field = $row->getSourceProperty('description_field');
if (isset($description_field[0]['value'])) {
$row->setSourceProperty('description', $description_field[0]['value']);
}
}
return parent::prepareRow($row);
}
......
......@@ -104,7 +104,11 @@ protected function assertEntity($id, $expected_label, $expected_vid, $expected_d
*/
public function testTaxonomyTerms() {
$this->assertEntity(1, 'General discussion', 'forums', '', NULL, 2);
$this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.', 'filtered_html', 0, [], NULL, 3);
// Tests that terms that used the Drupal 7 Title module and that have their
// name and description replaced by real fields are correctly migrated.
$this->assertEntity(2, 'Term1 (This is a real field!)', 'test_vocabulary', 'The first term. (This is a real field!)', 'filtered_html', 0, [], NULL, 3);
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6);
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
......
......@@ -27,16 +27,16 @@ public function providerSource() {
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'name' => 'name value 1 (name_field)',
'description' => 'description value 1 (description_field)',
'weight' => 0,
'parent' => [0],
],
[
'tid' => 4,
'vid' => 5,
'name' => 'name value 4',
'description' => 'description value 4',
'name' => 'name value 4 (name_field)',
'description' => 'description value 4 (description_field)',
'weight' => 1,
'parent' => [1],
],
......
......@@ -131,6 +131,14 @@ public function providerSource() {
'id' => '3',
'translatable' => '0',
],
[
'id' => '4',
'translatable' => '1',
],
[
'id' => '5',
'translatable' => '1',
],
];
$tests[0]['source_data']['field_config_instance'] = [
[
......@@ -139,6 +147,7 @@ public function providerSource() {
'field_name' => 'field_term_field',
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'data' => 'a:0:{}',
'deleted' => 0,
],
[
......@@ -147,8 +156,27 @@ public function providerSource() {
'field_name' => 'field_term_field',
'entity_type' => 'taxonomy_term',
'bundle' => 'categories',
'data' => 'a:0:{}',
'deleted' => 0,
],
[
'id' => '4',
'field_id' => '4',
'field_name' => 'name_field',
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'data' => 'a:0:{}',
'deleted' => '0',
],
[
'id' => '5',
'field_id' => '5',
'field_name' => 'description_field',
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$tests[0]['source_data']['field_data_field_term_field'] = [
[
......@@ -166,6 +194,61 @@ public function providerSource() {
'delta' => 0,
],
];
$tests[0]['source_data']['field_data_name_field'] = [
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'name_field_value' => 'name value 1 (name_field)',
'name_field_format' => NULL,
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '4',
'revision_id' => '4',
'language' => 'und',
'delta' => '0',
'name_field_value' => 'name value 4 (name_field)',
'name_field_format' => NULL,
],
];
$tests[0]['source_data']['field_data_description_field'] = [
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'description_field_value' => 'description value 1 (description_field)',
'description_field_format' => NULL,
],
[
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
'deleted' => '0',
'entity_id' => '4',
'revision_id' => '4',
'language' => 'und',
'delta' => '0',
'description_field_value' => 'description value 4 (description_field)',
'description_field_format' => NULL,
],
];
$tests[0]['source_data']['system'] = [
[
'name' => 'title',
'type' => 'module',
'status' => 1,
],
];
$tests[0]['source_data']['variable'] = [
[
'name' => 'forum_containers',
......@@ -178,8 +261,8 @@ public function providerSource() {
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'name' => 'name value 1 (name_field)',
'description' => 'description value 1 (description_field)',
'weight' => 0,
'parent' => [0],
],
......@@ -202,8 +285,8 @@ public function providerSource() {
[