summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-09-28 12:06:41 (GMT)
committerNathaniel Catchpole2017-09-28 12:06:41 (GMT)
commitc783750b204cfe3ba9f5d51a59a0823be73db512 (patch)
treeb96184ad27e2deb5387df9e58901176ec7a6ab1f
parent3d524aaae56b67e74e873b8c024a70e5ff2f60d2 (diff)
Revert "Issue #2711353 by rakesh.gectcr, Jo Fitzgerald, quietone, chx, Yogesh Pawar, Pavan B S, biguzis, phenaproxima, mikeryan, vasi, iMiksu, Berdir, dawehner, benjy: Migrate never unsets existing data for content entitites"
This reverts commit 3d524aaae56b67e74e873b8c024a70e5ff2f60d2.
-rw-r--r--core/modules/migrate/src/MigrateExecutable.php11
-rw-r--r--core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php5
-rw-r--r--core/modules/migrate/src/Row.php27
-rw-r--r--core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php62
-rw-r--r--core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php27
5 files changed, 3 insertions, 129 deletions
diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php
index cbe5f2f..94075b7 100644
--- a/core/modules/migrate/src/MigrateExecutable.php
+++ b/core/modules/migrate/src/MigrateExecutable.php
@@ -386,14 +386,9 @@ class MigrateExecutable implements MigrateExecutableInterface {
$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 cf3ae1d..d4f9bd7 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 @@ class EntityContentBase extends Entity {
* 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 @@ class EntityContentBase extends Entity {
// 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 @@ class EntityContentBase extends Entity {
$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 83e97b1..95e7f28 100644
--- a/core/modules/migrate/src/Row.php
+++ b/core/modules/migrate/src/Row.php
@@ -78,13 +78,6 @@ class Row {
protected $isStub = FALSE;
/**
- * The empty destination properties.
- *
- * @var array
- */
- protected $emptyDestinationProperties = [];
-
- /**
* Constructs a \Drupal\Migrate\Row object.
*
* @param array $values
@@ -237,26 +230,6 @@ class Row {
}
/**
- * 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.
*
* @return array
diff --git a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php
index e2f02ae..54c60ba 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\migrate\destination\EntityContentBase;
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 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
$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 f199562..5e7cbac 100644
--- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
@@ -440,33 +440,6 @@ class MigrateExecutableTest extends MigrateTestCase {
}
/**
- * 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.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface|\PHPUnit_Framework_MockObject_MockObject