diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php index cbe5f2f45627371b6e6f002ff199c3e804f8691c..94075b730e2bbe0b20a1c9487bded0fc2b085280 100644 --- a/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -386,14 +386,9 @@ public function processRow(Row $row, array $process = NULL, $value = NULL) { $multiple = $plugin->multiple(); } } - // Ensure all values, including nulls, are migrated. - if ($plugins) { - if (isset($value)) { - $row->setDestinationProperty($destination, $value); - } - else { - $row->setEmptyDestinationProperty($destination); - } + // No plugins or no value means do not set. + if ($plugins && !is_null($value)) { + $row->setDestinationProperty($destination, $value); } // Reset the value. $value = NULL; diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index cf3ae1dedb79e8cf6c83384b4f707e58888fb497..d4f9bd72ecc5dff1d86ccefeb1160f8a7481241e 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -149,7 +149,6 @@ public function getIds() { * An updated entity, or NULL if it's the same as the one passed in. */ protected function updateEntity(EntityInterface $entity, Row $row) { - $empty_destinations = $row->getEmptyDestinationProperties(); // By default, an update will be preserved. $rollback_action = MigrateIdMapInterface::ROLLBACK_PRESERVE; @@ -172,7 +171,6 @@ protected function updateEntity(EntityInterface $entity, Row $row) { // clone the row with an empty set of destination values, and re-add only // the specified properties. if (isset($this->configuration['overwrite_properties'])) { - $empty_destinations = array_intersect($empty_destinations, $this->configuration['overwrite_properties']); $clone = $row->cloneWithoutDestination(); foreach ($this->configuration['overwrite_properties'] as $property) { $clone->setDestinationProperty($property, $row->getDestinationProperty($property)); @@ -186,9 +184,6 @@ protected function updateEntity(EntityInterface $entity, Row $row) { $field->setValue($values); } } - foreach ($empty_destinations as $field_name) { - $entity->$field_name = NULL; - } $this->setRollbackAction($row->getIdMap(), $rollback_action); diff --git a/core/modules/migrate/src/Row.php b/core/modules/migrate/src/Row.php index 83e97b130d8e062e31d17c442e4d44e29b598960..95e7f28a0f6eda22adcea02666fb43fbeb12a5cb 100644 --- a/core/modules/migrate/src/Row.php +++ b/core/modules/migrate/src/Row.php @@ -77,13 +77,6 @@ class Row { */ protected $isStub = FALSE; - /** - * The empty destination properties. - * - * @var array - */ - protected $emptyDestinationProperties = []; - /** * Constructs a \Drupal\Migrate\Row object. * @@ -236,26 +229,6 @@ public function removeDestinationProperty($property) { NestedArray::unsetValue($this->destination, explode(static::PROPERTY_SEPARATOR, $property)); } - /** - * Sets a destination to be empty. - * - * @param string $property - * The destination property. - */ - public function setEmptyDestinationProperty($property) { - $this->emptyDestinationProperties[] = $property; - } - - /** - * Gets the empty destination properties. - * - * @return array - * An array of destination properties. - */ - public function getEmptyDestinationProperties() { - return $this->emptyDestinationProperties; - } - /** * Returns the whole destination array. * diff --git a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php index e2f02ae9d788e9857da3538d8081351fcc044c35..54c60ba928ef1da5fb6402f17cf14ecc0b9a490a 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php @@ -9,7 +9,6 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; -use Drupal\migrate_entity_test\Entity\StringIdEntityTest; /** * Tests the EntityContentBase destination. @@ -204,65 +203,4 @@ public function testEntityWithStringId() { $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 an 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); - $executable->import(); - - /** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */ - $entity = StringIdEntityTest::load('123'); - $this->assertSame('foo', $entity->version->value); - $entity = StringIdEntityTest::load('123456789012'); - $this->assertSame('bar', $entity->version->value); - - // Rerun the migration forcing the version to NULL. - $definition['process'] = [ - 'id' => 'id', - 'version' => 'constants/null', - ]; - - $migration = \Drupal::service('plugin.manager.migration') - ->createStubMigration($definition); - $executable = new MigrateExecutable($migration); - $executable->import(); - - /** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */ - $entity = StringIdEntityTest::load('123'); - $this->assertNull($entity->version->value); - $entity = StringIdEntityTest::load('123456789012'); - $this->assertNull($entity->version->value); - } - } diff --git a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php index f199562b6b3d8721adf7a9d60132691360e79885..5e7cbaca4ca0056e8065c544afd48614acd519f9 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php @@ -439,33 +439,6 @@ public function testProcessRowPipelineException() { $this->executable->processRow($row); } - /** - * Tests the processRow method. - */ - public function testProcessRowEmptyDestination() { - $expected = [ - 'test' => 'test destination', - 'test1' => 'test1 destination', - 'test2' => NULL, - ]; - $row = new Row(); - $plugins = []; - foreach ($expected as $key => $value) { - $plugin = $this->prophesize(MigrateProcessInterface::class); - $plugin->getPluginDefinition()->willReturn([]); - $plugin->transform(NULL, $this->executable, $row, $key)->willReturn($value); - $plugin->multiple()->willReturn(TRUE); - $plugins[$key][0] = $plugin->reveal(); - } - $this->migration->method('getProcessPlugins')->willReturn($plugins); - $this->executable->processRow($row); - foreach ($expected as $key => $value) { - $this->assertSame($value, $row->getDestinationProperty($key)); - } - $this->assertCount(2, $row->getDestination()); - $this->assertSame(['test2'], $row->getEmptyDestinationProperties()); - } - /** * Returns a mock migration source instance. *