diff --git a/core/modules/migrate/config/schema/migrate.source.schema.yml b/core/modules/migrate/config/schema/migrate.source.schema.yml index b0ff9e7..86631c2 100644 --- a/core/modules/migrate/config/schema/migrate.source.schema.yml +++ b/core/modules/migrate/config/schema/migrate.source.schema.yml @@ -39,69 +39,31 @@ migrate.source.variable: migrate.source.d6_comment: type: migrate_source - label: 'Drupal 6 book' + label: 'Drupal 6 comment' mapping: constants: type: mapping label: 'Constants' mapping: - field_id: - type: string - label: 'Field ID' entity_type: type: string label: 'Entity type' -migrate.source.d6_comment_variable: +migrate.source.d6_comment_variable_per_comment_type: type: migrate_source - label: 'Drupal 6 book' + label: 'Drupal 6 comment variable' mapping: constants: - type: mapping + type: migrate_entity_constant label: 'Constants' - mapping: - entity_type: - type: string - label: 'Entity type' - field_name: - type: string - label: 'Entity type' - view_mode: - type: string - label: 'Entity type' - options: - type: sequence - label: 'Options' - sequence: - - type: string - label: 'Option' - type: - type: string - label: 'Type' - id: - type: string - label: 'ID' - name: - type: label - label: 'Name' -migrate.source.d6_comment: +migrate.source.d6_comment_entity_form_display_subject: type: migrate_source - label: 'Drupal 6 comment' + label: 'Drupal 6 comment subject entity form display' mapping: constants: - type: mapping + type: migrate_entity_constant label: 'Constants' - mapping: - field_name: - type: string - label: 'Field name' - comment_type: - type: string - label: 'Comment type' - entity_type: - type: string - label: 'Entity type' migrate.source.d6_box: type: migrate_source diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml index 34e681e..46a7bc7 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml @@ -3,8 +3,6 @@ label: Drupal 6 comments source: plugin: d6_comment constants: - field_name: comment - comment_type: comment entity_type: node process: cid: cid @@ -20,8 +18,10 @@ process: migration: d6_node source: nid entity_type: constants.entity_type - field_name: constants.field_name - comment_type: constants.comment_type + # field_name & comment_type is calculated in + # \Drupal\migrate_drupal\Plugin\migrate\source\d6\Comment::prepareRow() + field_name: field_name + comment_type: comment_type subject: subject uid: - diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml index 20c99f6..46bd998 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml @@ -4,7 +4,6 @@ source: plugin: d6_comment_variable constants: entity_type: node - field_name: comment label: Comment settings required: true process: diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Comment.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Comment.php index 7ae2aa8..b68c27d 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Comment.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Comment.php @@ -28,7 +28,9 @@ public function query() { ->fields('c', array('cid', 'pid', 'nid', 'uid', 'subject', 'comment', 'hostname', 'timestamp', 'status', 'thread', 'name', 'mail', 'homepage', 'format')); - $query->orderBy('timestamp'); + $query->innerJoin('node', 'n', 'c.nid = n.nid'); + $query->fields('n', array('type')); + $query->orderBy('c.timestamp'); return $query; } @@ -36,6 +38,15 @@ public function query() { * {@inheritdoc} */ public function prepareRow(Row $row, $keep = TRUE) { + if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) { + // Comment subject visible. + $row->setSourceProperty('field_name', 'comment'); + $row->setSourceProperty('comment_type', 'comment'); + } + else { + $row->setSourceProperty('field_name', 'comment_no_subject'); + $row->setSourceProperty('comment_type', 'comment_no_subject'); + } // In D6, status=0 means published, while in D8 means the opposite. // See https://drupal.org/node/237636 $row->setSourceProperty('status', !$row->getSourceProperty('status')); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php index d07b02b..0aaca72 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php @@ -37,14 +37,20 @@ public static function getInfo() { public function setUp() { parent::setUp(); entity_create('node_type', array('type' => 'page'))->save(); + entity_create('node_type', array('type' => 'story'))->save(); $this->container->get('entity.manager')->getStorage('comment_type')->create(array( 'id' => 'comment', 'label' => 'comment', 'target_entity_type_id' => 'node', ))->save(); + $this->container->get('entity.manager')->getStorage('comment_type')->create(array( + 'id' => 'comment_no_subject', + 'label' => 'comment_no_subject', + 'target_entity_type_id' => 'node', + ))->save(); $node = entity_create('node', array( - 'type' => 'page', + 'type' => 'story', 'nid' => 1, )); $node->enforceIsNew(); @@ -53,16 +59,19 @@ public function setUp() { 'd6_filter_format' => array(array(array(1), array('filtered_html'))), 'd6_node' => array(array(array(1), array(1))), 'd6_user' => array(array(array(0), array(0))), - 'd6_comment_entity_display' => array(array(array('page'), array('node', 'page', 'default', 'comment'))), - 'd6_comment_entity_form_display' => array(array(array('page'), array('node', 'page', 'default', 'comment'))), + 'd6_comment_type' => array(array(array('comment'), array('comment_no_subject'))), + 'd6_comment_entity_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))), + 'd6_comment_entity_form_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))), ); $this->prepareIdMappings($id_mappings); - \Drupal::service('comment.manager')->addDefaultField('node', 'page'); + \Drupal::service('comment.manager')->addDefaultField('node', 'story'); /** @var \Drupal\migrate\entity\Migration $migration */ $migration = entity_load('migration', 'd6_comment'); $dumps = array( + $this->getDumpDirectory() . '/Drupal6Node.php', + $this->getDumpDirectory() . '/Drupal6CommentVariable.php', $this->getDumpDirectory() . '/Drupal6Comment.php', ); $this->prepare($migration, $dumps); @@ -74,15 +83,16 @@ public function setUp() { * Tests the Drupal 6 to Drupal 8 comment migration. */ public function testComments() { - /** @var Comment $comment */ + /** @var \Drupal\comment\CommentInterface $comment */ $comment = entity_load('comment', 1); - $this->assertEqual('The first comment.', $comment->subject->value); + $this->assertEqual('The first comment.', $comment->getSubject()); $this->assertEqual('The first comment body.', $comment->comment_body->value); $this->assertEqual('filtered_html', $comment->comment_body->format); $this->assertEqual(0, $comment->pid->target_id); - $this->assertEqual(1, $comment->entity_id->target_id); - $this->assertEqual('node', $comment->entity_type->value); + $this->assertEqual(1, $comment->getCommentedEntityId()); + $this->assertEqual('node', $comment->getCommentedEntityTypeId()); $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $comment->language()->id); + $this->assertEqual('comment_no_subject', $comment->getTypeId()); $comment = entity_load('comment', 2); $this->assertEqual('The response to the second comment.', $comment->subject->value); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentVariableField.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentVariableField.php index f2285ed..62e202c 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentVariableField.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentVariableField.php @@ -41,7 +41,7 @@ public function setUp() { 'id' => $comment_type, 'target_entity_type_id' => 'node', )) - ->save(); + ->save(); } // Add some id mappings for the dependant migrations. $id_mappings = array( diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php index 592992e..c6908dc 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php @@ -65,6 +65,7 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase { 'd6_comment', 'd6_comment_entity_display', 'd6_comment_entity_form_display', + 'd6_comment_entity_form_display_subject', 'd6_comment_field', 'd6_comment_field_instance', 'd6_contact_category', @@ -233,6 +234,7 @@ protected function getTestClassesList() { __NAMESPACE__ . '\MigrateCommentTest', __NAMESPACE__ . '\MigrateCommentVariableEntityDisplay', __NAMESPACE__ . '\MigrateCommentVariableEntityFormDisplay', + __NAMESPACE__ . '\MigrateCommentVariableEntityFormDisplaySubject', __NAMESPACE__ . '\MigrateCommentVariableField', __NAMESPACE__ . '\MigrateCommentVariableInstance', __NAMESPACE__ . '\MigrateContactCategoryTest',