reverted: --- b/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php +++ a/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php @@ -50,7 +50,7 @@ 'image_style' => 6, 'language_content_settings' => 2, 'migration' => 73, + 'node' => 3, - 'node' => 2, 'node_type' => 6, 'rdf_mapping' => 5, 'search_page' => 2, diff -u b/core/modules/node/migration_templates/d7_node_translation.yml b/core/modules/node/migration_templates/d7_node.yml --- b/core/modules/node/migration_templates/d7_node_translation.yml +++ b/core/modules/node/migration_templates/d7_node.yml @@ -1,16 +1,18 @@ -id: d7_node_translation -label: Node translations +id: d7_node +label: Nodes migration_tags: - Drupal 7 deriver: Drupal\node\Plugin\migrate\D7NodeDeriver source: plugin: d7_node - translations: true process: # If you are using this file to build a custom migration consider removing # the nid and vid fields to allow incremental migrations. + # In D7, nodes always have a tnid, but it's zero for untranslated nodes. + # We normalize it to equal the nid in that case. + # @see \Drupal\node\Plugin\migrate\source\d7\Node::prepareRow(). nid: tnid - type: type + vid: vid langcode: plugin: default_value source: language @@ -30,11 +32,6 @@ - translations: true - content_translation_update_definitions: - - node migration_dependencies: required: - d7_user - d7_node_type - - language optional: - d7_field_instance -provider: migrate_drupal diff -u b/core/modules/node/src/Plugin/migrate/source/d7/Node.php b/core/modules/node/src/Plugin/migrate/source/d7/Node.php --- b/core/modules/node/src/Plugin/migrate/source/d7/Node.php +++ b/core/modules/node/src/Plugin/migrate/source/d7/Node.php @@ -5,6 +5,11 @@ use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity; use Drupal\Core\Database\Query\SelectInterface; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Extension\ModuleHandler; +use Drupal\Core\State\StateInterface; +use Drupal\migrate\Plugin\MigrationInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Drupal 7 node source from database. @@ -15,8 +20,36 @@ * ) */ class Node extends FieldableEntity { + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandler + */ + protected $moduleHandler; /** + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ModuleHandler $module_handler) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager); + $this->moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('state'), + $container->get('entity.manager'), + $container->get('module_handler') + ); + } + /** * The join options between the node and the node_revisions table. */ const JOIN = 'n.vid = nr.vid'; @@ -50,6 +83,12 @@ $query->addField('nr', 'uid', 'revision_uid'); $query->innerJoin('node', 'n', static::JOIN); + // If the content_translation module is enabled, get the source langcode + // to fill the content_translation_source field. + if ($this->moduleHandler->moduleExists('content_translation')) { + $query->leftJoin('node', 'nt', 'n.tnid = nt.nid'); + $query->addField('nt', 'language', 'source_langcode'); + } $this->handleTranslations($query); if (isset($this->configuration['node_type'])) { diff -u b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php --- b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php @@ -46,6 +46,7 @@ 'd7_user_role', 'd7_user', 'd7_node_type', + 'd7_language_content_settings', 'd7_comment_type', 'd7_taxonomy_vocabulary', 'd7_field', @@ -161,8 +162,17 @@ $this->assertSame('internal:/', $translation->field_link->uri); $this->assertSame('Home', $translation->field_link->title); + // Test that content_translation_source is set. + $manager = $this->container->get('content_translation.manager'); + $this->assertSame('en', $manager->getTranslationMetadata($node->getTranslation('is'))->getSource()); + // Node 3 is a translation of node 2, and should not be imported separately. $this->assertNull(Node::load(3), "Node 3 doesn't exist in D8, it was a translation"); + + // Test that content_translation_source for a source other than English. + $node = Node::load(4); + $this->assertSame('is', $manager->getTranslationMetadata($node->getTranslation('en'))->getSource()); + } } only in patch2: unchanged: --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -5697,6 +5697,30 @@ 'body_summary' => '', 'body_format' => 'filtered_html', )) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'und', + 'delta' => '0', + 'body_value' => 'is - Is that is it awesome.', + 'body_summary' => '', + 'body_format' => 'filtered_html', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '5', + 'revision_id' => '5', + 'language' => 'und', + 'delta' => '0', + 'body_value' => 'en - Is that is it awesome.', + 'body_summary' => '', + 'body_format' => 'filtered_html', +)) ->execute(); $connection->schema()->createTable('field_revision_comment_body', array( @@ -8086,6 +8110,24 @@ 'mysql_character_set' => 'utf8', )); +$connection->insert('history') +->fields(array( + 'uid', + 'nid', + 'timestamp', +)) +->values(array( + 'uid' => '1', + 'nid' => '4', + 'timestamp' => '1478755275', +)) +->values(array( + 'uid' => '1', + 'nid' => '5', + 'timestamp' => '1478755314', +)) +->execute(); + $connection->schema()->createTable('image_effects', array( 'fields' => array( 'ieid' => array( @@ -8777,6 +8819,22 @@ 'context' => '', 'version' => 'none', )) +->values(array( + 'lid' => '49', + 'location' => 'misc/ajax.js', + 'textgroup' => 'default', + 'source' => 'The response failed verification so will not be processed.', + 'context' => '', + 'version' => 'none', +)) +->values(array( + 'lid' => '50', + 'location' => 'misc/ajax.js', + 'textgroup' => 'default', + 'source' => 'The callback URL is not local and not trusted: !url', + 'context' => '', + 'version' => 'none', +)) ->execute(); $connection->schema()->createTable('locales_target', array( @@ -29893,6 +29951,38 @@ 'tnid' => '2', 'translate' => '0', )) +->values(array( + 'nid' => '4', + 'vid' => '4', + 'type' => 'article', + 'language' => 'is', + 'title' => 'is - The thing about Firefly', + 'uid' => '1', + 'status' => '1', + 'created' => '1478755274', + 'changed' => '1478755274', + 'comment' => '2', + 'promote' => '1', + 'sticky' => '0', + 'tnid' => '4', + 'translate' => '0', +)) +->values(array( + 'nid' => '5', + 'vid' => '5', + 'type' => 'article', + 'language' => 'en', + 'title' => 'en - The thing about Firefly', + 'uid' => '1', + 'status' => '1', + 'created' => '1478755314', + 'changed' => '1478755314', + 'comment' => '2', + 'promote' => '1', + 'sticky' => '0', + 'tnid' => '4', + 'translate' => '0', +)) ->execute(); $connection->schema()->createTable('node_access', array( @@ -30037,6 +30127,22 @@ 'last_comment_uid' => '1', 'comment_count' => '0', )) +->values(array( + 'nid' => '4', + 'cid' => '0', + 'last_comment_timestamp' => '1478755274', + 'last_comment_name' => NULL, + 'last_comment_uid' => '1', + 'comment_count' => '0', +)) +->values(array( + 'nid' => '5', + 'cid' => '0', + 'last_comment_timestamp' => '1478755314', + 'last_comment_name' => NULL, + 'last_comment_uid' => '1', + 'comment_count' => '0', +)) ->execute(); $connection->schema()->createTable('node_counter', array( @@ -30091,15 +30197,27 @@ ->values(array( 'nid' => '2', 'totalcount' => '1', - 'daycount' => '1', + 'daycount' => '0', 'timestamp' => '1471428059', )) ->values(array( 'nid' => '3', 'totalcount' => '1', - 'daycount' => '1', + 'daycount' => '0', 'timestamp' => '1471428153', )) +->values(array( + 'nid' => '4', + 'totalcount' => '1', + 'daycount' => '1', + 'timestamp' => '1478755275', +)) +->values(array( + 'nid' => '5', + 'totalcount' => '1', + 'daycount' => '1', + 'timestamp' => '1478755314', +)) ->execute(); $connection->schema()->createTable('node_revision', array( @@ -30220,6 +30338,30 @@ 'promote' => '1', 'sticky' => '0', )) +->values(array( + 'nid' => '4', + 'vid' => '4', + 'uid' => '1', + 'title' => 'is - The thing about Firefly', + 'log' => '', + 'timestamp' => '1478755274', + 'status' => '1', + 'comment' => '2', + 'promote' => '1', + 'sticky' => '0', +)) +->values(array( + 'nid' => '5', + 'vid' => '5', + 'uid' => '1', + 'title' => 'en - The thing about Firefly', + 'log' => '', + 'timestamp' => '1478755314', + 'status' => '1', + 'comment' => '2', + 'promote' => '1', + 'sticky' => '0', +)) ->execute(); $connection->schema()->createTable('node_type', array( @@ -40812,6 +40954,16 @@ 'published' => '1', 'changed' => '1421727536', )) +->values(array( + 'nid' => '4', + 'published' => '1', + 'changed' => '1478755274', +)) +->values(array( + 'nid' => '5', + 'published' => '1', + 'changed' => '1478755314', +)) ->execute(); $connection->schema()->createTable('tracker_user', array(