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:
source: pid
entity_id: nid
entity_type: 'constants/entity_type'
comment_type: comment_type
field_name: comment_type
comment_type:
-
plugin: migration_lookup
source: comment_type
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
field_name: '@comment_type'
subject: subject
uid: uid
name: name
......
......@@ -13,7 +13,14 @@ source:
weight: 20
process:
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'
options: 'constants/options'
bundle: node_type
......
......@@ -22,7 +22,14 @@ process:
map:
0: true
1: false
bundle: bundle
bundle:
-
plugin: migration_lookup
source: bundle
migration: d7_comment_type
-
plugin: skip_on_empty
method: row
destination:
plugin: component_entity_form_display
migration_dependencies:
......
......@@ -9,9 +9,16 @@ source:
type: comment
process:
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'
'settings/comment_type': bundle
'settings/comment_type': '@field_name'
destination:
plugin: entity:field_storage_config
migration_dependencies:
......
......@@ -12,7 +12,14 @@ process:
entity_type: 'constants/entity_type'
label: 'constants/label'
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
'default_value/0/status': 'constants/required'
'settings/default_mode': default_mode
......
......@@ -8,7 +8,14 @@ source:
entity_type: node
process:
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
destination:
plugin: entity:comment_type
......
......@@ -53,7 +53,7 @@ public function testMigration() {
$this->assertDisplay('node.article.default', 'comment_node_article');
$this->assertDisplay('node.book.default', 'comment_node_book');
$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');
}
......
......@@ -48,7 +48,7 @@ public function testMigration() {
$this->assertDisplay('comment.comment_node_article.default');
$this->assertDisplay('comment.comment_node_book.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');
}
......
......@@ -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.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.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);
}
......
......@@ -54,7 +54,7 @@ public function testMigration() {
$this->assertEntity('node.comment_node_article', 'comment_node_article');
$this->assertEntity('node.comment_node_blog', 'comment_node_blog');
$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');
}
......
......@@ -51,7 +51,7 @@ public function testMigration() {
$this->assertEntity('comment_node_article', 'Article comment');
$this->assertEntity('comment_node_blog', 'Blog entry 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');
$migration = $this->getMigration('d7_comment_type');
......
......@@ -26,7 +26,15 @@ process:
plugin: skip_on_empty
method: row
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:
-
plugin: migration_lookup
......
......@@ -15,7 +15,15 @@ process:
method: getFieldType
entity_type: entity_type
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
description: description
required: required
......
......@@ -26,7 +26,15 @@ process:
-
plugin: skip_on_empty
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'
field_name: field_name
entity_type: entity_type
......
......@@ -56,7 +56,7 @@ protected function setUp() {
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_forum',
'id' => 'comment_forum',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
......@@ -213,8 +213,8 @@ public function testMigration() {
$this->assertEntity('comment.comment_node_book.default');
$this->assertComponent('comment.comment_node_book.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_forum.default');
$this->assertComponent('comment.comment_node_forum.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_forum.default');
$this->assertComponent('comment.comment_forum.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_page.default');
$this->assertComponent('comment.comment_node_page.default', 'comment_body', 'text_default', 'hidden', 0);
......
......@@ -2,12 +2,11 @@
namespace Drupal\Tests\field\Kernel\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\migrate\Kernel\NodeCommentCombinationTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Migrates Drupal 7 field instances.
......@@ -16,10 +15,10 @@
*/
class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
use NodeCommentCombinationTrait;
/**
* The modules to be enabled during the test.
*
* @var array
* {@inheritdoc}
*/
public static $modules = [
'comment',
......@@ -40,35 +39,16 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->createType('page');
$this->createType('article');
$this->createType('blog');
$this->createType('book');
$this->createType('forum');
$this->createType('test_content_type');
$this->createNodeCommentCombination('page');
$this->createNodeCommentCombination('article');
$this->createNodeCommentCombination('blog');
$this->createNodeCommentCombination('book');
$this->createNodeCommentCombination('forum', 'comment_forum');
$this->createNodeCommentCombination('test_content_type');
Vocabulary::create(['vid' => 'test_vocabulary'])->save();
$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.
*
......@@ -127,7 +107,7 @@ public function testFieldInstances() {
$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.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('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);
......
......@@ -35,7 +35,7 @@ public function testFieldInstances() {
'comment.comment_node_book.comment_body',
'node.book.body',
'node.forum.taxonomy_forums',
'comment.comment_node_forum.comment_body',
'comment.comment_forum.comment_body',
'node.forum.body',
'comment.comment_node_test_content_type.comment_body',
'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() {
'block_content' => 1,
'block_content_type' => 1,
'comment' => 1,
'comment_type' => 8,
'comment_type' => 7,
// Module 'language' comes with 'en', 'und', 'zxx'. Migration adds 'is'.
'configurable_language' => 4,
'contact_form' => 3,
'editor' => 2,
'field_config' => 63,
'field_storage_config' => 45,
'field_config' => 61,
'field_storage_config' => 44,
'file' => 3,
'filter_format' => 7,
'image_style' => 6,
......@@ -73,9 +73,9 @@ protected function getEntityCounts() {
'menu_link_content' => 7,
'view' => 16,
'date_format' => 11,
'entity_form_display' => 18,
'entity_form_display' => 17,
'entity_form_mode' => 1,
'entity_view_display' => 29,
'entity_view_display' => 28,
'entity_view_mode' => 14,
'base_field_override' => 9,
];
......
......@@ -2,10 +2,9 @@
namespace Drupal\Tests\user\Kernel\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\Database\Database;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\migrate\Kernel\NodeCommentCombinationTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
......@@ -18,6 +17,8 @@
*/
class MigrateUserTest extends MigrateDrupal7TestBase {
use NodeCommentCombinationTrait;
/**
* {@inheritdoc}
*/
......@@ -43,12 +44,12 @@ protected function setUp() {
// Prepare to migrate user pictures as well.
$this->installEntitySchema('file');
$this->createType('page');
$this->createType('article');
$this->createType('blog');
$this->createType('book');
$this->createType('forum');
$this->createType('test_content_type');
$this->createNodeCommentCombination('page');
$this->createNodeCommentCombination('article');
$this->createNodeCommentCombination('blog');
$this->createNodeCommentCombination('book');
$this->createNodeCommentCombination('forum', 'comment_forum');
$this->createNodeCommentCombination('test_content_type');
Vocabulary::create(['vid' => 'test_vocabulary'])->save();
$this->executeMigrations([
'language',
......@@ -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.
*
......
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