diff -u b/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php --- b/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -387,8 +387,13 @@ } } // No plugins or no value means do not set. - if ($plugins && !is_null($value)) { - $row->setDestinationProperty($destination, $value); + if ($plugins) { + if (isset($value)) { + $row->setDestinationProperty($destination, $value); + } + else { + $row->setEmptyDestinationProperty($destination); + } } // Reset the value. $value = NULL; @@ -402,13 +407,8 @@ } } // No plugins or no value means do not set. - if ($plugins) { - if (isset($value)) { - $row->setDestinationProperty($destination, $value); - } - else { - $row->setEmptyDestinationProperty($destination); - } + if ($plugins && !is_null($value)) { + $row->setDestinationProperty($destination, $value); } // Reset the value. $value = NULL; diff -u b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php --- b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php @@ -160,9 +160,9 @@ } /** - * Tests empty destinations. + * Tests creation of ID columns table with definitions taken from entity type. */ - public function testEmptyDestinations() { + public function testEntityWithStringId() { $this->enableModules(['migrate_entity_test']); $this->installEntitySchema('migrate_string_id_entity_test'); @@ -180,7 +180,6 @@ 'id' => ['type' => 'integer', 'size' => 'big'], 'version' => ['type' => 'string'], ], - 'constants' => ['null' => NULL], ], 'process' => [ 'id' => 'id', @@ -191,6 +190,53 @@ ], ]; + $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition); + $executable = new MigrateExecutable($migration, new MigrateMessage()); + $result = $executable->import(); + $this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result); + + /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */ + $id_map_plugin = $migration->getIdMap(); + + // Check that the destination has been stored. + $map_row = $id_map_plugin->getRowBySource(['id' => 123, 'version' => 'foo']); + $this->assertEquals(123, $map_row['destid1']); + $map_row = $id_map_plugin->getRowBySource(['id' => 123456789012, 'version' => 'bar']); + $this->assertEquals(123456789012, $map_row['destid1']); + } + + /** + * Tests empty destinations. + */ + public function testEmptyDestinations() { + $this->enableModules(['migrate_entity_test']); + $this->installEntitySchema('migrate_string_id_entity_test'); + + $definition = [ + 'source' => [ + 'plugin' => 'embedded_data', + 'data_rows' => [ + ['id' => 123, 'version' => 'foo'], + // This integer needs an 'int' schema with 'big' size. If 'destid1' + // is not correctly taking the definition from the destination entity + // type, the import will fail with a SQL exception. + ['id' => 123456789012, 'version' => 'bar'], + ], + 'ids' => [ + 'id' => ['type' => 'integer', 'size' => 'big'], + 'version' => ['type' => 'string'], + ], + 'constants' => ['null' => NULL], + ], + 'process' => [ + 'id' => 'id', + 'version' => 'version', + ], + 'destination' => [ + 'plugin' => 'entity:migrate_string_id_entity_test', + ], + ]; + $migration = \Drupal::service('plugin.manager.migration') ->createStubMigration($definition); $executable = new MigrateExecutable($migration, new MigrateMessage());