Commit 5cfa420d authored by webchick's avatar webchick

Issue #2853872 by heddn, maxocub, masipila, phenaproxima, quietone, andypost,...

Issue #2853872 by heddn, maxocub, masipila, phenaproxima, quietone, andypost, larowlan: Migration for forum and article comments: duplicate comment types and incorrect comment_entity_statistics
parent 2df0fc02
...@@ -16,8 +16,15 @@ process: ...@@ -16,8 +16,15 @@ process:
source: pid source: pid
entity_id: nid entity_id: nid
entity_type: 'constants/entity_type' entity_type: 'constants/entity_type'
comment_type: comment_type comment_type:
field_name: comment_type -
plugin: migration_lookup
source: comment_type
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
field_name: '@comment_type'
subject: subject subject: subject
uid: uid uid: uid
name: name name: name
......
...@@ -13,7 +13,14 @@ source: ...@@ -13,7 +13,14 @@ source:
weight: 20 weight: 20
process: process:
entity_type: 'constants/entity_type' entity_type: 'constants/entity_type'
field_name: bundle field_name:
-
plugin: migration_lookup
source: bundle
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
view_mode: 'constants/view_mode' view_mode: 'constants/view_mode'
options: 'constants/options' options: 'constants/options'
bundle: node_type bundle: node_type
......
...@@ -22,7 +22,14 @@ process: ...@@ -22,7 +22,14 @@ process:
map: map:
0: true 0: true
1: false 1: false
bundle: bundle bundle:
-
plugin: migration_lookup
source: bundle
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
destination: destination:
plugin: component_entity_form_display plugin: component_entity_form_display
migration_dependencies: migration_dependencies:
......
...@@ -9,9 +9,16 @@ source: ...@@ -9,9 +9,16 @@ source:
type: comment type: comment
process: process:
entity_type: 'constants/entity_type' entity_type: 'constants/entity_type'
field_name: bundle field_name:
-
plugin: migration_lookup
source: bundle
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
type: 'constants/type' type: 'constants/type'
'settings/comment_type': bundle 'settings/comment_type': '@field_name'
destination: destination:
plugin: entity:field_storage_config plugin: entity:field_storage_config
migration_dependencies: migration_dependencies:
......
...@@ -12,7 +12,14 @@ process: ...@@ -12,7 +12,14 @@ process:
entity_type: 'constants/entity_type' entity_type: 'constants/entity_type'
label: 'constants/label' label: 'constants/label'
required: 'constants/required' required: 'constants/required'
field_name: bundle field_name:
-
plugin: migration_lookup
source: bundle
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
bundle: node_type bundle: node_type
'default_value/0/status': 'constants/required' 'default_value/0/status': 'constants/required'
'settings/default_mode': default_mode 'settings/default_mode': default_mode
......
...@@ -8,7 +8,14 @@ source: ...@@ -8,7 +8,14 @@ source:
entity_type: node entity_type: node
process: process:
target_entity_type_id: 'constants/entity_type' target_entity_type_id: 'constants/entity_type'
id: bundle id:
plugin: static_map
source: bundle
bypass: true
# The Forum module provides its own comment type (comment_forum), which we
# want to reuse if it exists.
map:
comment_node_forum: comment_forum
label: label label: label
destination: destination:
plugin: entity:comment_type plugin: entity:comment_type
......
...@@ -53,7 +53,7 @@ public function testMigration() { ...@@ -53,7 +53,7 @@ public function testMigration() {
$this->assertDisplay('node.article.default', 'comment_node_article'); $this->assertDisplay('node.article.default', 'comment_node_article');
$this->assertDisplay('node.book.default', 'comment_node_book'); $this->assertDisplay('node.book.default', 'comment_node_book');
$this->assertDisplay('node.blog.default', 'comment_node_blog'); $this->assertDisplay('node.blog.default', 'comment_node_blog');
$this->assertDisplay('node.forum.default', 'comment_node_forum'); $this->assertDisplay('node.forum.default', 'comment_forum');
$this->assertDisplay('node.test_content_type.default', 'comment_node_test_content_type'); $this->assertDisplay('node.test_content_type.default', 'comment_node_test_content_type');
} }
......
...@@ -48,7 +48,7 @@ public function testMigration() { ...@@ -48,7 +48,7 @@ public function testMigration() {
$this->assertDisplay('comment.comment_node_article.default'); $this->assertDisplay('comment.comment_node_article.default');
$this->assertDisplay('comment.comment_node_book.default'); $this->assertDisplay('comment.comment_node_book.default');
$this->assertDisplay('comment.comment_node_blog.default'); $this->assertDisplay('comment.comment_node_blog.default');
$this->assertDisplay('comment.comment_node_forum.default'); $this->assertDisplay('comment.comment_forum.default');
$this->assertDisplay('comment.comment_node_test_content_type.default'); $this->assertDisplay('comment.comment_node_test_content_type.default');
} }
......
...@@ -79,7 +79,7 @@ public function testMigration() { ...@@ -79,7 +79,7 @@ public function testMigration() {
$this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.forum.comment_node_forum', 'comment_node_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.forum.comment_forum', 'comment_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.test_content_type.comment_node_test_content_type', 'comment_node_test_content_type', 'test_content_type', TRUE, 30, FALSE, CommentItemInterface::FORM_BELOW, TRUE); $this->assertEntity('node.test_content_type.comment_node_test_content_type', 'comment_node_test_content_type', 'test_content_type', TRUE, 30, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
} }
......
...@@ -54,7 +54,7 @@ public function testMigration() { ...@@ -54,7 +54,7 @@ public function testMigration() {
$this->assertEntity('node.comment_node_article', 'comment_node_article'); $this->assertEntity('node.comment_node_article', 'comment_node_article');
$this->assertEntity('node.comment_node_blog', 'comment_node_blog'); $this->assertEntity('node.comment_node_blog', 'comment_node_blog');
$this->assertEntity('node.comment_node_book', 'comment_node_book'); $this->assertEntity('node.comment_node_book', 'comment_node_book');
$this->assertEntity('node.comment_node_forum', 'comment_node_forum'); $this->assertEntity('node.comment_forum', 'comment_forum');
$this->assertEntity('node.comment_node_test_content_type', 'comment_node_test_content_type'); $this->assertEntity('node.comment_node_test_content_type', 'comment_node_test_content_type');
} }
......
...@@ -51,7 +51,7 @@ public function testMigration() { ...@@ -51,7 +51,7 @@ public function testMigration() {
$this->assertEntity('comment_node_article', 'Article comment'); $this->assertEntity('comment_node_article', 'Article comment');
$this->assertEntity('comment_node_blog', 'Blog entry comment'); $this->assertEntity('comment_node_blog', 'Blog entry comment');
$this->assertEntity('comment_node_book', 'Book page comment'); $this->assertEntity('comment_node_book', 'Book page comment');
$this->assertEntity('comment_node_forum', 'Forum topic comment'); $this->assertEntity('comment_forum', 'Forum topic comment');
$this->assertEntity('comment_node_test_content_type', 'Test content type comment'); $this->assertEntity('comment_node_test_content_type', 'Test content type comment');
$migration = $this->getMigration('d7_comment_type'); $migration = $this->getMigration('d7_comment_type');
......
...@@ -26,7 +26,15 @@ process: ...@@ -26,7 +26,15 @@ process:
plugin: skip_on_empty plugin: skip_on_empty
method: row method: row
entity_type: entity_type entity_type: entity_type
bundle: bundle # The bundle needs to be statically mapped in order to support comment types
# that might already exist before this migration is run. See
# d7_comment_type.yml or more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
view_mode: view_mode:
- -
plugin: migration_lookup plugin: migration_lookup
......
...@@ -15,7 +15,15 @@ process: ...@@ -15,7 +15,15 @@ process:
method: getFieldType method: getFieldType
entity_type: entity_type entity_type: entity_type
field_name: field_name field_name: field_name
bundle: bundle # The bundle needs to be statically mapped in order to support comment types
# that might already exist before this migration is run. See
# d7_comment_type.yml for more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
label: label label: label
description: description description: description
required: required required: required
......
...@@ -26,7 +26,15 @@ process: ...@@ -26,7 +26,15 @@ process:
- -
plugin: skip_on_empty plugin: skip_on_empty
method: row method: row
bundle: bundle # The bundle needs to be statically mapped in order to support comment types
# that might already exist before this migration is run. See
# d7_comment_type.yml for more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
form_mode: 'constants/form_mode' form_mode: 'constants/form_mode'
field_name: field_name field_name: field_name
entity_type: entity_type entity_type: entity_type
......
...@@ -56,7 +56,7 @@ protected function setUp() { ...@@ -56,7 +56,7 @@ protected function setUp() {
'label' => $this->randomMachineName(), 'label' => $this->randomMachineName(),
])->save(); ])->save();
CommentType::create([ CommentType::create([
'id' => 'comment_node_forum', 'id' => 'comment_forum',
'label' => $this->randomMachineName(), 'label' => $this->randomMachineName(),
])->save(); ])->save();
CommentType::create([ CommentType::create([
...@@ -213,8 +213,8 @@ public function testMigration() { ...@@ -213,8 +213,8 @@ public function testMigration() {
$this->assertEntity('comment.comment_node_book.default'); $this->assertEntity('comment.comment_node_book.default');
$this->assertComponent('comment.comment_node_book.default', 'comment_body', 'text_default', 'hidden', 0); $this->assertComponent('comment.comment_node_book.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_forum.default'); $this->assertEntity('comment.comment_forum.default');
$this->assertComponent('comment.comment_node_forum.default', 'comment_body', 'text_default', 'hidden', 0); $this->assertComponent('comment.comment_forum.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_page.default'); $this->assertEntity('comment.comment_node_page.default');
$this->assertComponent('comment.comment_node_page.default', 'comment_body', 'text_default', 'hidden', 0); $this->assertComponent('comment.comment_node_page.default', 'comment_body', 'text_default', 'hidden', 0);
......
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
namespace Drupal\Tests\field\Kernel\Migrate\d7; namespace Drupal\Tests\field\Kernel\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface; use Drupal\field\FieldConfigInterface;
use Drupal\taxonomy\Entity\Vocabulary; use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\migrate\Kernel\NodeCommentCombinationTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/** /**
* Migrates Drupal 7 field instances. * Migrates Drupal 7 field instances.
...@@ -16,10 +15,10 @@ ...@@ -16,10 +15,10 @@
*/ */
class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
use NodeCommentCombinationTrait;
/** /**
* The modules to be enabled during the test. * {@inheritdoc}
*
* @var array
*/ */
public static $modules = [ public static $modules = [
'comment', 'comment',
...@@ -40,35 +39,16 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { ...@@ -40,35 +39,16 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->installConfig(static::$modules); $this->installConfig(static::$modules);
$this->createType('page'); $this->createNodeCommentCombination('page');
$this->createType('article'); $this->createNodeCommentCombination('article');
$this->createType('blog'); $this->createNodeCommentCombination('blog');
$this->createType('book'); $this->createNodeCommentCombination('book');
$this->createType('forum'); $this->createNodeCommentCombination('forum', 'comment_forum');
$this->createType('test_content_type'); $this->createNodeCommentCombination('test_content_type');
Vocabulary::create(['vid' => 'test_vocabulary'])->save(); Vocabulary::create(['vid' => 'test_vocabulary'])->save();
$this->executeMigrations(['d7_field', 'd7_field_instance']); $this->executeMigrations(['d7_field', 'd7_field_instance']);
} }
/**
* Creates a node type with a corresponding comment type.
*
* @param string $id
* The node type ID.
*/
protected function createType($id) {
NodeType::create([
'type' => $id,
'label' => $this->randomString(),
])->save();
CommentType::create([
'id' => 'comment_node_' . $id,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
])->save();
}
/** /**
* Asserts various aspects of a field config entity. * Asserts various aspects of a field config entity.
* *
...@@ -127,7 +107,7 @@ public function testFieldInstances() { ...@@ -127,7 +107,7 @@ public function testFieldInstances() {
$this->assertEntity('comment.comment_node_book.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('comment.comment_node_book.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('node.book.body', 'Body', 'text_with_summary', FALSE, FALSE); $this->assertEntity('node.book.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('node.forum.taxonomy_forums', 'Forums', 'entity_reference', TRUE, FALSE); $this->assertEntity('node.forum.taxonomy_forums', 'Forums', 'entity_reference', TRUE, FALSE);
$this->assertEntity('comment.comment_node_forum.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('comment.comment_forum.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('node.forum.body', 'Body', 'text_with_summary', FALSE, FALSE); $this->assertEntity('node.forum.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('comment.comment_node_test_content_type.comment_body', 'Comment', 'text_long', TRUE, FALSE); $this->assertEntity('comment.comment_node_test_content_type.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('node.test_content_type.field_boolean', 'Boolean', 'boolean', FALSE, FALSE); $this->assertEntity('node.test_content_type.field_boolean', 'Boolean', 'boolean', FALSE, FALSE);
......
...@@ -35,7 +35,7 @@ public function testFieldInstances() { ...@@ -35,7 +35,7 @@ public function testFieldInstances() {
'comment.comment_node_book.comment_body', 'comment.comment_node_book.comment_body',
'node.book.body', 'node.book.body',
'node.forum.taxonomy_forums', 'node.forum.taxonomy_forums',
'comment.comment_node_forum.comment_body', 'comment.comment_forum.comment_body',
'node.forum.body', 'node.forum.body',
'comment.comment_node_test_content_type.comment_body', 'comment.comment_node_test_content_type.comment_body',
'node.test_content_type.field_boolean', 'node.test_content_type.field_boolean',
......
<?php
namespace Drupal\Tests\migrate\Kernel;
use Drupal\comment\Entity\CommentType;
use Drupal\node\Entity\NodeType;
/**
* Provides methods for testing node and comment combinations.
*/
trait NodeCommentCombinationTrait {
/**
* Creates a node type with a corresponding comment type.
*
* @param string $node_type
* The node type ID.
* @param string $comment_type
* (optional) The comment type ID, if not provided defaults to
* comment_node_{type}.
*/
protected function createNodeCommentCombination($node_type, $comment_type = NULL) {
if (!$comment_type) {
$comment_type = "comment_node_$node_type";
}
NodeType::create([
'type' => $node_type,
'label' => $this->randomString(),
])->save();
CommentType::create([
'id' => $comment_type,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
])->save();
}
}
...@@ -45,13 +45,13 @@ protected function getEntityCounts() { ...@@ -45,13 +45,13 @@ protected function getEntityCounts() {
'block_content' => 1, 'block_content' => 1,
'block_content_type' => 1, 'block_content_type' => 1,
'comment' => 1, 'comment' => 1,
'comment_type' => 8, 'comment_type' => 7,
// Module 'language' comes with 'en', 'und', 'zxx'. Migration adds 'is'. // Module 'language' comes with 'en', 'und', 'zxx'. Migration adds 'is'.
'configurable_language' => 4, 'configurable_language' => 4,
'contact_form' => 3, 'contact_form' => 3,
'editor' => 2, 'editor' => 2,
'field_config' => 63, 'field_config' => 61,
'field_storage_config' => 45, 'field_storage_config' => 44,
'file' => 3, 'file' => 3,
'filter_format' => 7, 'filter_format' => 7,
'image_style' => 6, 'image_style' => 6,
...@@ -73,9 +73,9 @@ protected function getEntityCounts() { ...@@ -73,9 +73,9 @@ protected function getEntityCounts() {
'menu_link_content' => 7, 'menu_link_content' => 7,
'view' => 16, 'view' => 16,
'date_format' => 11, 'date_format' => 11,
'entity_form_display' => 18, 'entity_form_display' => 17,
'entity_form_mode' => 1, 'entity_form_mode' => 1,
'entity_view_display' => 29, 'entity_view_display' => 28,
'entity_view_mode' => 14, 'entity_view_mode' => 14,
'base_field_override' => 9, 'base_field_override' => 9,
]; ];
......
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
namespace Drupal\Tests\user\Kernel\Migrate\d7; namespace Drupal\Tests\user\Kernel\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Vocabulary; use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\migrate\Kernel\NodeCommentCombinationTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\user\RoleInterface; use Drupal\user\RoleInterface;
...@@ -18,6 +17,8 @@ ...@@ -18,6 +17,8 @@
*/ */
class MigrateUserTest extends MigrateDrupal7TestBase { class MigrateUserTest extends MigrateDrupal7TestBase {
use NodeCommentCombinationTrait;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -43,12 +44,12 @@ protected function setUp() { ...@@ -43,12 +44,12 @@ protected function setUp() {
// Prepare to migrate user pictures as well. // Prepare to migrate user pictures as well.
$this->installEntitySchema('file'); $this->installEntitySchema('file');
$this->createType('page'); $this->createNodeCommentCombination('page');
$this->createType('article'); $this->createNodeCommentCombination('article');
$this->createType('blog'); $this->createNodeCommentCombination('blog');
$this->createType('book'); $this->createNodeCommentCombination('book');
$this->createType('forum'); $this->createNodeCommentCombination('forum', 'comment_forum');
$this->createType('test_content_type'); $this->createNodeCommentCombination('test_content_type');
Vocabulary::create(['vid' => 'test_vocabulary'])->save(); Vocabulary::create(['vid' => 'test_vocabulary'])->save();
$this->executeMigrations([ $this->executeMigrations([
'language', 'language',
...@@ -61,25 +62,6 @@ protected function setUp() { ...@@ -61,25 +62,6 @@ protected function setUp() {
]); ]);
} }
/**
* Creates a node type with a corresponding comment type.
*
* @param string $id
* The node type ID.
*/
protected function createType($id) {
NodeType::create([
'type' => $id,
'label' => $this->randomString(),
])->save();
CommentType::create([
'id' => 'comment_node_' . $id,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
])->save();
}
/** /**
* Asserts various aspects of a user account. * Asserts various aspects of a user account.
* *
......
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