diff --git a/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php b/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php index 2e69972..ffcc3fe 100644 --- a/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php +++ b/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php @@ -15,7 +15,7 @@ class MigrateBookTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['language', 'book']; + public static $modules = ['book']; /** * {@inheritdoc} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php index 9c2af9a..5330e94 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php @@ -17,7 +17,7 @@ class MigrateCommentTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['language', 'comment']; + public static $modules = ['comment']; /** * {@inheritdoc} @@ -25,7 +25,6 @@ class MigrateCommentTest extends MigrateDrupal6TestBase { protected function setUp() { parent::setUp(); - $this->installSchema('node', ['node_access']); $this->installEntitySchema('node'); $this->installEntitySchema('comment'); $this->installSchema('comment', ['comment_entity_statistics']); diff --git a/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php index 0de0007..463ce02 100644 --- a/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php +++ b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php @@ -16,11 +16,6 @@ class MigrateUploadTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['language']; - - /** - * {@inheritdoc} - */ protected function setUp() { parent::setUp(); diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php index 86ed601..0cc00d6 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php @@ -68,9 +68,6 @@ public function getIds() { * The entity to update. * @param \Drupal\migrate\Row $row * The row object to update from. - * - * @return NULL|\Drupal\Core\Entity\EntityInterface - * An updated entity, or NULL if it's the same as the one passed in. */ protected function updateEntity(EntityInterface $entity, Row $row) { foreach ($row->getRawDestination() as $property => $value) { @@ -78,7 +75,6 @@ protected function updateEntity(EntityInterface $entity, Row $row) { } $this->setRollbackAction($row->getIdMap()); - return $entity; } /** diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index ff22336..3617f38 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -111,25 +111,23 @@ protected function save(ContentEntityInterface $entity, array $old_destination_i } /** - * Get the base IDs of this entity, not including dynamically determined IDs. + * Get whether this destination is for translations. * - * @return array - * An array of IDs. + * @return bool + * Whether this destination is for translations. */ - protected function baseIds() { - $id_key = $this->getKey('id'); - $ids[$id_key]['type'] = 'integer'; - return $ids; + protected function isTranslationDestination() { + return !empty($this->configuration['translations']); } - /** * {@inheritdoc} */ public function getIds() { - $ids = $this->baseIds(); + $id_key = $this->getKey('id'); + $ids[$id_key]['type'] = 'integer'; - if (!empty($this->configuration['translations'])) { + if ($this->isTranslationDestination()) { if ($key = $this->getKey('langcode')) { $ids[$key]['type'] = 'string'; } @@ -148,13 +146,16 @@ public function getIds() { * The entity to update. * @param \Drupal\migrate\Row $row * The row object to update from. + * + * @return NULL|\Drupal\Core\Entity\EntityInterface + * An updated entity, or NULL if it's the same as the one passed in. */ protected function updateEntity(EntityInterface $entity, Row $row) { // By default, an update will be preserved. $rollback_action = MigrateIdMapInterface::ROLLBACK_PRESERVE; // Make sure we have the right translation. - if ($entity instanceof TranslatableInterface) { + if ($this->isTranslationDestination()) { $property = $this->storage->getEntityType()->getKey('langcode'); if ($row->hasDestinationProperty($property)) { $language = $row->getDestinationProperty($property); @@ -238,10 +239,7 @@ protected function processStubRow(Row $row) { * {@inheritdoc} */ public function rollback(array $destination_identifier) { - if (empty($this->configuration['translations'])) { - parent::rollback($destination_identifier); - } - else { + if ($this->isTranslationDestination()) { // Attempt to remove the translation. $entity = $this->storage->load(reset($destination_identifier)); if ($entity && $entity instanceof TranslatableInterface) { @@ -260,6 +258,9 @@ public function rollback(array $destination_identifier) { } } } + else { + parent::rollback($destination_identifier); + } } } diff --git a/core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php b/core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php index 3eaa8ff..ce9c013 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php @@ -69,15 +69,15 @@ public function testMigrations() { $this->assertEquals('en', $node->language()->getId()); $this->assertEquals('Dog', $node->title->value); $this->assertEquals('Chien', $node->getTranslation('fr')->title->value); - $this->assertFalse($node->hasTranslation('es')); + $this->assertFalse($node->hasTranslation('es'), "No spanish translation for node 2"); $node = $storage->load(3); $this->assertEquals('en', $node->language()->getId()); $this->assertEquals('Monkey', $node->title->value); - $this->assertFalse($node->hasTranslation('fr')); - $this->assertFalse($node->hasTranslation('es')); + $this->assertFalse($node->hasTranslation('fr'), "No french translation for node 3"); + $this->assertFalse($node->hasTranslation('es'), "No spanish translation for node 3"); - $this->assertNull($storage->load(4)); + $this->assertNull($storage->load(4), "No node 4 migrated"); // Roll back the migrations. foreach ($migration_ids as $migration_id) { diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php index da20b49..33aec58 100644 --- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\ContentEntityType; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; @@ -97,6 +98,33 @@ public function testImportEntityLoadFailure() { $destination->import(new Row([], [])); } + /** + * Test that translation destination fails for untranslatable entities. + * + * @expectedException \Drupal\migrate\MigrateException + * @expectedExceptionMessage This entity type does not support translation + */ + public function testUntranslatable() { + // An entity type without a language. + $entity_type = $this->prophesize(ContentEntityType::class); + $entity_type->getKey('langcode')->willReturn(''); + $entity_type->getKey('id')->willReturn('id'); + + $this->storage->getEntityType()->willReturn($entity_type->reveal()); + + $destination = new EntityTestDestination( + [ 'translations' => TRUE ], + '', + [], + $this->migration->reveal(), + $this->storage->reveal(), + [], + $this->entityManager->reveal(), + $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() + ); + $destination->getIds(); + } + } /** diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php index bdac5c9..13dc157 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/EntityContentBaseTest.php @@ -4,7 +4,11 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\MigrateMessageInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\user\Entity\User; +use Prophecy\Argument; /** * @group migrate_drupal @@ -85,4 +89,39 @@ public function testOverwriteProperties() { $this->assertIdentical('proto@zo.an', $account->getInitialEmail()); } + /** + * Test that translation destination fails for untranslatable entities. + */ + public function testUntranslatable() { + $this->enableModules(['language_test']); + $this->installEntitySchema('no_language_entity_test'); + + /** @var MigrationInterface $migration */ + $migration = \Drupal::service('plugin.manager.migration')->createStubMigration([ + 'source' => [ + 'plugin' => 'embedded_data', + 'ids' => ['id' => ['type' => 'integer']], + 'data_rows' => [['id' => 1]], + ], + 'process' => [ + 'id' => 'id', + ], + 'destination' => [ + 'plugin' => 'entity:no_language_entity_test', + 'translations' => TRUE, + ], + ]); + + $message = $this->prophesize(MigrateMessageInterface::class); + // Match the expected message. Can't use default argument types, because + // we need to convert to string from TranslatableMarkup. + $argument = Argument::that(function($msg) { + return strpos((string) $msg, "This entity type does not support translation") !== FALSE; + }); + $message->display($argument, Argument::any()) + ->shouldBeCalled(); + + $executable = new MigrateExecutable($migration, $message->reveal()); + $executable->import(); + } } diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php index 148566b..3a9467e 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php @@ -89,18 +89,24 @@ protected function migrateFields() { /** * Executes all content migrations. * - * @param bool $include_revisions - * If TRUE, migrates node revisions. + * @param array $include + * Extra things to include as part of the migrations. Values may be + * 'revisions' or 'translations'. */ - protected function migrateContent($include_revisions = FALSE) { - $this->executeMigrations(['language']); + protected function migrateContent($include = []) { + if (in_array('translations', $include)) { + $this->executeMigrations(['language']); + } $this->migrateUsers(FALSE); $this->migrateFields(); $this->installEntitySchema('node'); - $this->executeMigrations(['d6_node_settings', 'd6_node', 'd6_node_translation']); + $this->executeMigrations(['d6_node_settings', 'd6_node']); - if ($include_revisions) { + if (in_array('translations', $include)) { + $this->executeMigrations(['translations']); + } + if (in_array('revisions', $include)) { $this->executeMigrations(['d6_node_revision']); } } diff --git a/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php b/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php index 2c02041..58c9256 100644 --- a/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php +++ b/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php @@ -30,7 +30,7 @@ * * @var array */ - public static $modules = ['language', 'migrate_drupal_ui', 'telephone']; + public static $modules = ['language', 'content_translation', 'migrate_drupal_ui', 'telephone']; /** * {@inheritdoc} diff --git a/core/modules/node/migration_templates/d6_node_translation.yml b/core/modules/node/migration_templates/d6_node_translation.yml index b9d279f..2ddd5a4 100644 --- a/core/modules/node/migration_templates/d6_node_translation.yml +++ b/core/modules/node/migration_templates/d6_node_translation.yml @@ -31,7 +31,6 @@ process: revision_timestamp: timestamp # unmapped d6 fields. -# tnid # translate # moderate # comment @@ -45,6 +44,7 @@ migration_dependencies: - d6_node_type - d6_node_settings - d6_filter_format + - language optional: - d6_field_instance_widget_settings - d6_field_formatter_settings diff --git a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php index e5b4008..e3c0356 100644 --- a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php @@ -38,25 +38,37 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface { protected $cckPluginManager; /** + * Whether or not to include translations. + * + * @var bool + */ + protected $includeTranslations; + + /** * D6NodeDeriver constructor. * * @param string $base_plugin_id * The base plugin ID for the plugin ID. * @param \Drupal\Component\Plugin\PluginManagerInterface $cck_manager * The CCK plugin manager. + * @param bool $translations + * Whether or not to include translations. */ - public function __construct($base_plugin_id, PluginManagerInterface $cck_manager) { + public function __construct($base_plugin_id, PluginManagerInterface $cck_manager, $translations) { $this->basePluginId = $base_plugin_id; $this->cckPluginManager = $cck_manager; + $this->includeTranslations = $translations; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, $base_plugin_id) { + // Translations don't make sense unless we have content_translation. return new static( $base_plugin_id, - $container->get('plugin.manager.migrate.cckfield') + $container->get('plugin.manager.migrate.cckfield'), + $container->get('module_handler')->moduleExists('content_translation') ); } @@ -72,6 +84,11 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * @see \Drupal\Component\Plugin\Derivative\DeriverBase::getDerivativeDefinition() */ public function getDerivativeDefinitions($base_plugin_definition) { + if ($base_plugin_definition['id'] == 'd6_node_translation' && !$this->includeTranslations) { + // Refuse to generate anything. + return $this->derivatives; + } + // Read all CCK field instance definitions in the source database. $fields = array(); try { @@ -99,7 +116,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { ]); $values['source']['node_type'] = $node_type; - // If this migration is based on the d6_node_revision migration, or + // If this migration is based on the d6_node_revision migration or // is for translations of nodes, it should explicitly depend on the // corresponding d6_node variant. if (in_array($base_plugin_definition['id'], ['d6_node_revision', 'd6_node_translation'])) { 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 ccefb2d..5ca698f 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/Node.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/Node.php @@ -2,6 +2,7 @@ namespace Drupal\node\Plugin\migrate\source\d6; +use Drupal\Core\Database\Query\SelectInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; @@ -15,11 +16,6 @@ class Node extends DrupalSqlBase { /** - * An expression for the translation set of a node. - */ - const NODE_TRANSLATION_SET = 'CASE n.tnid WHEN 0 THEN n.nid ELSE n.tnid END'; - - /** * The join options between the node and the node_revisions table. */ const JOIN = 'n.vid = nr.vid'; @@ -42,7 +38,9 @@ class Node extends DrupalSqlBase { * {@inheritdoc} */ public function query() { - $query = $this->translationQuery(); + $query = $this->select('node_revisions', 'nr'); + $query->innerJoin('node', 'n', static::JOIN); + $this->handleTranslations($query); $query->fields('n', array( 'nid', @@ -261,45 +259,21 @@ public function getIds() { } /** - * Query to get the max vid of the translation set in the node table. + * Adapt our query for translations. * - * @return \Drupal\Core\Database\Query\SelectInterface + * @param \Drupal\Core\Database\Query\SelectInterface * The generated query. */ - protected function maxVidQuery() { - $subquery = $this->select('node', 'n'); - $subquery->addExpression(self::NODE_TRANSLATION_SET, 'translation_set'); - $subquery->groupBy('translation_set'); - $subquery->addExpression('MAX(vid)', 'vid'); - return $subquery; - } - - /** - * Build a query that yields the rows we want to migrate. - * - * It should have a node table 'n', and a node_revision table 'nr'. - * - * @return \Drupal\Core\Database\Query\SelectInterface - * The generated query. - */ - protected function translationQuery() { - $query = $this->select('node_revisions', 'nr'); - $query->innerJoin('node', 'n', static::JOIN); - - // Claim our vid is the maximum vid of our translation set. - // Otherwise the revision the node is assigned in D8 may be confusing. - $query->join($this->maxVidQuery(), 'max_vid', - 'max_vid.translation_set IN (n.nid, n.tnid)'); - $query->fields('max_vid', ['vid']); - - // Are we yielding original nodes, or translations? + protected function handleTranslations(SelectInterface $query) { + // Check whether or not we want translations. if (empty($this->configuration['translations'])) { + // No translations: Yield untranslated nodes, or default translations. $query->where('n.tnid = 0 OR n.tnid = n.nid'); } else { + // Translations: Yield only non-default translations. $query->where('n.tnid <> 0 AND n.tnid <> n.nid'); } - - return $query; } + } diff --git a/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php b/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php index ee0f9b8..3f9a580 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php @@ -1,6 +1,7 @@ select('node_revisions', 'nr'); - $query->innerJoin('node', 'n', static::JOIN); - return $query; + protected function handleTranslations(SelectInterface $query) { + // @todo in https://www.drupal.org/node/2746541 } } diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php index 0311841..a02ef3f 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php @@ -13,9 +13,14 @@ class MigrateNodeRevisionTest extends MigrateNodeTestBase { /** * {@inheritdoc} */ + public static $modules = ['language', 'content_translation']; + + /** + * {@inheritdoc} + */ protected function setUp() { parent::setUp(); - $this->executeMigrations(['language', 'd6_node', 'd6_node_revision']); + $this->executeMigrations(['d6_node', 'd6_node_revision']); } /** 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 e7896cf..eb5649d 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTest.php @@ -20,6 +20,11 @@ class MigrateNodeTest extends MigrateNodeTestBase { /** * {@inheritdoc} */ + public static $modules = ['language', 'content_translation']; + + /** + * {@inheritdoc} + */ protected function setUp() { parent::setUp(); $this->setUpMigratedFiles(); @@ -82,13 +87,12 @@ public function testNode() { // Test that translations are working. $node = Node::load(9); - $this->assertTrue($node instanceof NodeInterface); $this->assertIdentical('en', $node->langcode->value); $this->assertIdentical('The Real McCoy', $node->title->value); - $this->assertTrue($node->hasTranslation('fr')); + $this->assertTrue($node->hasTranslation('fr'), "Node 9 has french translation"); // Node 10 is a translation of node 9, and should not be imported separately. - $this->assertNull(Node::load(10)); + $this->assertNull(Node::load(10), "Node 10 doesn't exist in D8, it was a translation"); // Rerun migration with invalid link attributes and a different URL and // title. If only the attributes are changed the error does not occur. diff --git a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTestBase.php b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTestBase.php index ca21ad7..e225003 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTestBase.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeTestBase.php @@ -13,11 +13,6 @@ /** * {@inheritdoc} */ - public static $modules = ['language']; - - /** - * {@inheritdoc} - */ protected function setUp() { parent::setUp(); diff --git a/core/modules/node/tests/src/Unit/Plugin/migrate/source/d6/NodeTest.php b/core/modules/node/tests/src/Unit/Plugin/migrate/source/d6/NodeTest.php index e18edbf..b6ce22e 100644 --- a/core/modules/node/tests/src/Unit/Plugin/migrate/source/d6/NodeTest.php +++ b/core/modules/node/tests/src/Unit/Plugin/migrate/source/d6/NodeTest.php @@ -96,7 +96,7 @@ class NodeTest extends NodeTestBase { ), array( 'nid' => 6, - 'vid' => 7, + 'vid' => 6, 'type' => 'story', 'language' => 'en', 'title' => 'node title 6', diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeRevisionTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeRevisionTest.php index ac9f881..facd69b 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeRevisionTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeRevisionTest.php @@ -14,7 +14,7 @@ class MigrateTermNodeRevisionTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['language', 'taxonomy']; + public static $modules = ['taxonomy']; /** * {@inheritdoc} @@ -22,7 +22,7 @@ class MigrateTermNodeRevisionTest extends MigrateDrupal6TestBase { protected function setUp() { parent::setUp(); $this->installSchema('node', ['node_access']); - $this->migrateContent(TRUE); + $this->migrateContent(['revisions']); $this->migrateTaxonomy(); $this->executeMigrations(['d6_term_node', 'd6_term_node_revision']); } diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeTest.php index 3e13a55..26f069c 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTermNodeTest.php @@ -15,7 +15,7 @@ class MigrateTermNodeTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['language', 'taxonomy']; + public static $modules = ['taxonomy']; /** * {@inheritdoc} diff --git a/core/modules/user/migration_templates/d7_user.yml b/core/modules/user/migration_templates/d7_user.yml index 5e9dcc7..12147f8 100644 --- a/core/modules/user/migration_templates/d7_user.yml +++ b/core/modules/user/migration_templates/d7_user.yml @@ -15,6 +15,7 @@ process: login: login status: status timezone: timezone + langcode: language preferred_langcode: language preferred_admin_langcode: language init: init diff --git a/core/modules/user/src/Plugin/migrate/User.php b/core/modules/user/src/Plugin/migrate/User.php index 65d5c2f..986b58d 100644 --- a/core/modules/user/src/Plugin/migrate/User.php +++ b/core/modules/user/src/Plugin/migrate/User.php @@ -2,80 +2,13 @@ namespace Drupal\user\Plugin\migrate; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\LanguageManagerInterface; use Drupal\migrate\Exception\RequirementsException; -use Drupal\migrate\Plugin\MigrateDestinationPluginManager; -use Drupal\migrate\Plugin\MigratePluginManager; use Drupal\migrate\Plugin\Migration; -use Drupal\migrate\Plugin\MigrationPluginManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin class for Drupal 7 user migrations dealing with fields and profiles. */ class User extends Migration { - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The language manager. - * - * @var \Drupal\Core\Language\LanguageManagerInterface - */ - protected $languageManager; - - /** - * Constructs a user migration. - * - * @param array $configuration - * Plugin configuration. - * @param string $plugin_id - * The plugin ID. - * @param mixed $plugin_definition - * The plugin definition. - * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager - * The migration plugin manager. - * @param \Drupal\migrate\Plugin\MigratePluginManager $source_plugin_manager - * The source migration plugin manager. - * @param \Drupal\migrate\Plugin\MigratePluginManager $process_plugin_manager - * The process migration plugin manager. - * @param \Drupal\migrate\Plugin\MigrateDestinationPluginManager $destination_plugin_manager - * The destination migration plugin manager. - * @param \Drupal\migrate\Plugin\MigratePluginManager $idmap_plugin_manager - * The ID map migration plugin manager. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManager $source_plugin_manager, MigratePluginManager $process_plugin_manager, MigrateDestinationPluginManager $destination_plugin_manager, MigratePluginManager $idmap_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration_plugin_manager, $source_plugin_manager, $process_plugin_manager, $destination_plugin_manager, $idmap_plugin_manager); - $this->moduleHandler = $module_handler; - $this->languageManager = $language_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('plugin.manager.migration'), - $container->get('plugin.manager.migrate.source'), - $container->get('plugin.manager.migrate.process'), - $container->get('plugin.manager.migrate.destination'), - $container->get('plugin.manager.migrate.id_map'), - $container->get('module_handler'), - $container->get('language_manager') - ); - } /** * Flag indicating whether the CCK data has been filled already. @@ -95,7 +28,7 @@ public function getProcess() { 'ignore_map' => TRUE, ] + $this->source; $definition['destination']['plugin'] = 'null'; - if ($this->moduleHandler->moduleExists('field')) { + if (\Drupal::moduleHandler()->moduleExists('field')) { $definition['source']['plugin'] = 'd7_field_instance'; $field_migration = $this->migrationPluginManager->createStubMigration($definition); foreach ($field_migration->getSourcePlugin() as $row) { @@ -117,15 +50,6 @@ public function getProcess() { // The checkRequirements() call will fail when the profile module does // not exist on the source site. } - - // Use the default language if none is provided. - $this->process['langcode'] = [ - 'source' => 'language', - 'plugin' => 'default_value', - 'strict' => FALSE, - 'default_value' => $this->languageManager->getDefaultLanguage()->getId(), - ]; - } return parent::getProcess(); } diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php index 15b4801..2e0965d 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php @@ -54,8 +54,6 @@ protected function setUp() { * Whether or not the account is blocked. * @param string $langcode * The user account's language code. - * @param string $preferred_langcode - * The user's preferred language. * @param string $init * The user's initial email address. * @param string[] $roles @@ -63,7 +61,7 @@ protected function setUp() { * @param bool $has_picture * Whether the user is expected to have a picture attached. */ - protected function assertEntity($id, $label, $mail, $password, $access, $login, $blocked, $langcode, $preferred_langcode, $init, array $roles = [RoleInterface::AUTHENTICATED_ID], $has_picture = FALSE) { + protected function assertEntity($id, $label, $mail, $password, $access, $login, $blocked, $langcode, $init, array $roles = [RoleInterface::AUTHENTICATED_ID], $has_picture = FALSE) { /** @var \Drupal\user\UserInterface $user */ $user = User::load($id); $this->assertTrue($user instanceof UserInterface); @@ -76,8 +74,8 @@ protected function assertEntity($id, $label, $mail, $password, $access, $login, // user preferred language is not configured on the site. We just want to // test if the value was imported correctly. $this->assertIdentical($langcode, $user->langcode->value); - $this->assertIdentical($preferred_langcode, $user->preferred_langcode->value); - $this->assertIdentical($preferred_langcode, $user->preferred_admin_langcode->value); + $this->assertIdentical($langcode, $user->preferred_langcode->value); + $this->assertIdentical($langcode, $user->preferred_admin_langcode->value); $this->assertIdentical($init, $user->getInitialEmail()); $this->assertIdentical($roles, $user->getRoles()); $this->assertIdentical($has_picture, !$user->user_picture->isEmpty()); @@ -89,8 +87,7 @@ protected function assertEntity($id, $label, $mail, $password, $access, $login, */ public function testUser() { $password = '$S$DGFZUE.FhrXbe4y52eC7p0ZVRGD/gOPtVctDlmC89qkujnBokAlJ'; - $this->assertEquals('en', \Drupal::languageManager()->getDefaultLanguage()->getId()); - $this->assertEntity(2, 'Odo', 'odo@local.host', $password, '0', '0', FALSE, 'en', '', 'odo@local.host'); + $this->assertEntity(2, 'Odo', 'odo@local.host', $password, '0', '0', FALSE, '', 'odo@local.host'); // Ensure that the user can authenticate. $this->assertEquals(2, \Drupal::service('user.auth')->authenticate('Odo', 'a password'));