Commit d1a1cc5b authored by catch's avatar catch

Issue #2979916 by maxocub, masipila, phenaproxima: D7 comment field values are not migrated

parent 246e95d4
......@@ -4,6 +4,7 @@ audit: true
migration_tags:
- Drupal 7
- Content
class: Drupal\comment\Plugin\migrate\D7Comment
source:
plugin: d7_comment
constants:
......
<?php
namespace Drupal\comment\Plugin\migrate;
use Drupal\migrate_drupal\Plugin\migrate\FieldMigration;
/**
* Migration plugin for Drupal 7 comments with fields.
*/
class D7Comment extends FieldMigration {
/**
* {@inheritdoc}
*/
public function getProcess() {
if ($this->init) {
return parent::getProcess();
}
$this->init = TRUE;
if (!\Drupal::moduleHandler()->moduleExists('field')) {
return parent::getProcess();
}
$definition['source'] = [
'ignore_map' => TRUE,
] + $this->getSourceConfiguration();
$definition['source']['plugin'] = 'd7_field_instance';
$definition['destination']['plugin'] = 'null';
$definition['idMap']['plugin'] = 'null';
$field_migration = $this->migrationPluginManager->createStubMigration($definition);
foreach ($field_migration->getSourcePlugin() as $row) {
$field_name = $row->getSourceProperty('field_name');
$field_type = $row->getSourceProperty('type');
if ($this->fieldPluginManager->hasDefinition($field_type)) {
if (!isset($this->fieldPluginCache[$field_type])) {
$this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($field_type, [], $this);
}
$info = $row->getSource();
$this->fieldPluginCache[$field_type]->processFieldValues($this, $field_name, $info);
}
else {
$this->setProcessOfProperty($field_name, $field_name);
}
}
return parent::getProcess();
}
}
......@@ -17,7 +17,18 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['filter', 'node', 'comment', 'text', 'menu_ui'];
public static $modules = [
'comment',
'datetime',
'filter',
'image',
'link',
'menu_ui',
'node',
'taxonomy',
'telephone',
'text',
];
/**
* {@inheritdoc}
......@@ -40,6 +51,9 @@ protected function setUp() {
'd7_comment_field_instance',
'd7_comment_entity_display',
'd7_comment_entity_form_display',
'd7_taxonomy_vocabulary',
'd7_field',
'd7_field_instance',
'd7_comment',
]);
}
......@@ -59,6 +73,7 @@ public function testMigration() {
$this->assertSame('This is a comment', $comment->comment_body->value);
$this->assertSame('filtered_html', $comment->comment_body->format);
$this->assertSame('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname());
$this->assertSame('1000000', $comment->field_integer->value);
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
......
......@@ -3095,6 +3095,18 @@
'created',
'changed',
))
->values(array(
'entity_type' => 'comment',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'source' => '',
'uid' => '1',
'status' => '1',
'translate' => '0',
'created' => '1421727536',
'changed' => '1421727536',
))
->values(array(
'entity_type' => 'user',
'entity_id' => '2',
......@@ -5768,6 +5780,16 @@
'delta',
'field_integer_value',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'field_integer_value' => '1000000',
))
->values(array(
'entity_type' => 'node',
'bundle' => 'test_content_type',
......@@ -9511,6 +9533,16 @@
'delta',
'field_integer_value',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'field_integer_value' => '1000000',
))
->values(array(
'entity_type' => 'node',
'bundle' => 'test_content_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