diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index 9debae0..b18a4b3 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -41378,6 +41378,40 @@ 'tnid' => '10', 'translate' => '0', )) +->values(array( + 'nid' => '12', + 'vid' => '15', + 'type' => 'page', + 'language' => 'zu', + 'title' => 'Abantu zulu', + 'uid' => '1', + 'status' => '1', + 'created' => '1444238800', + 'changed' => '1444238808', + 'comment' => '0', + 'promote' => '0', + 'moderate' => '0', + 'sticky' => '0', + 'tnid' => '12', + 'translate' => '0', +)) +->values(array( + 'nid' => '13', + 'vid' => '16', + 'type' => 'page', + 'language' => 'en', + 'title' => 'The Zulu People', + 'uid' => '1', + 'status' => '1', + 'created' => '1444239050', + 'changed' => '1444239050', + 'comment' => '0', + 'promote' => '0', + 'moderate' => '0', + 'sticky' => '0', + 'tnid' => '12', + 'translate' => '0', +)) ->execute(); $connection->schema()->createTable('node_access', array( @@ -41807,6 +41841,28 @@ 'timestamp' => '1444239050', 'format' => '1', )) +->values(array( + 'nid' => '12', + 'vid' => '15', + 'uid' => '1', + 'title' => 'Abantu zulu', + 'body' => "Mr. Crusher, ready a collision course with the Borg ship.", + 'teaser' => "Mr. Crusher, ready a collision course with the Borg ship.", + 'log' => '', + 'timestamp' => '1444238808', + 'format' => '1', +)) +->values(array( + 'nid' => '13', + 'vid' => '16', + 'uid' => '1', + 'title' => 'The Zulu People', + 'body' => 'Mr. Crusher, ready a collision course with the Borg ship.', + 'teaser' => 'Mr. Crusher, ready a collision course with the Borg ship.', + 'log' => '', + 'timestamp' => '1444239050', + 'format' => '1', +)) ->execute(); $connection->schema()->createTable('node_type', array( diff --git a/core/modules/node/src/Plugin/migrate/source/d6/Node.php b/core/modules/node/src/Plugin/migrate/source/d6/Node.php index f849bef..2e4d1a6 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/Node.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/Node.php @@ -3,8 +3,13 @@ namespace Drupal\node\Plugin\migrate\source\d6; 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 Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Drupal 6 node source from database. @@ -35,12 +40,41 @@ class Node extends DrupalSqlBase { protected $fieldInfo; /** + * 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') + ); + } + + /** * {@inheritdoc} */ public function query() { $query = $this->select('node_revisions', 'nr'); $query->innerJoin('node', 'n', static::JOIN); - $query->leftJoin('node', 'nt', 'n.tnid = nt.nid'); $this->handleTranslations($query); $query->fields('n', array( @@ -68,7 +102,13 @@ public function query() { )); $query->addField('n', 'uid', 'node_uid'); $query->addField('nr', 'uid', 'revision_uid'); - $query->addField('nt', 'language', 'source_langcode'); + + // 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'); + } if (isset($this->configuration['node_type'])) { $query->condition('n.type', $this->configuration['node_type']); diff --git a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php index 97f41fe..7a0a272 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php @@ -105,6 +105,10 @@ public function testNode() { $manager = $this->container->get('content_translation.manager'); $this->assertIdentical('en', $manager->getTranslationMetadata($node->getTranslation('fr'))->getSource()); + // Test that content_translation_source for a source other than English. + $node = Node::load(12); + $this->assertIdentical('zu', $manager->getTranslationMetadata($node->getTranslation('en'))->getSource()); + // Node 11 is a translation of node 10, and should not be imported separately. $this->assertNull(Node::load(11), "Node 11 doesn't exist in D8, it was a translation");