diff -u b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentMaster.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentMaster.php --- b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentMaster.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentMaster.php @@ -56,8 +56,8 @@ * @param array $old_destination_id_values * The old destination IDs. * - * @return \Drupal\Core\Entity\EntityInterface|false - * The entity or false if it can not be created. + * @return \Drupal\Core\Entity\EntityInterface + * The entity. */ protected function getEntity(Row $row, array $old_destination_id_values) { $revision_id = $old_destination_id_values ? @@ -66,26 +66,24 @@ if (!empty($revision_id) && ($entity = $this->storage->loadRevision($revision_id))) { $entity->setNewRevision(FALSE); } + elseif (($entity_id = $row->getDestinationProperty($this->getKey('id'))) && ($entity = $this->storage->load($entity_id))) { + $entity->enforceIsNew(FALSE); + $entity->setNewRevision(TRUE); + } else { - if (($entity_id = $row->getDestinationProperty($this->getKey('id'))) && - ($entity = $this->storage->load($entity_id))) { - $entity->enforceIsNew(FALSE); - $entity->setNewRevision(TRUE); + // Attempt to ensure we always have a bundle. + if ($bundle = $this->getBundle($row)) { + $row->setDestinationProperty($this->getKey('bundle'), $bundle); } - else { - // Attempt to ensure we always have a bundle. - if ($bundle = $this->getBundle($row)) { - $row->setDestinationProperty($this->getKey('bundle'), $bundle); - } - // Stubs might need some required fields filled in. - if ($row->isStub()) { - $this->processStubRow($row); - } - $entity = $this->storage->create($row->getDestination()); - $entity->enforceIsNew(); + // Stubs might need some required fields filled in. + if ($row->isStub()) { + $this->processStubRow($row); } + $entity = $this->storage->create($row->getDestination()); + $entity->enforceIsNew(); } + // We need to update the entity, so that the destination row IDs are // correct. $entity = $this->updateEntity($entity, $row); diff -u b/core/modules/migrate_drupal/migrate_drupal.module b/core/modules/migrate_drupal/migrate_drupal.module --- b/core/modules/migrate_drupal/migrate_drupal.module +++ b/core/modules/migrate_drupal/migrate_drupal.module @@ -113,19 +113,24 @@ // dN_node_master migration and not any other dN_node* migration. Alter all // instances of migration_lookup in core migrations to use dN_node_master. if (_use_master_node_migration($definitions) === NODE_MIGRATE_TYPE_MASTER) { + + // Anonymous function to replace non master migration plugin IDs with the + // master plugin ID. + $replace_with_master_migrations = function (&$value) { + if (is_string($value)) { + $value = preg_replace('/d([67])_(node|node_translation|node_revision)($|:.*)/', 'd$1_node_master$3', $value); + } + return $value; + }; + foreach ($definitions as &$definition) { - if (!preg_match('/d([67])_(node|node_translation|node_revision)($|:.*)/', $definition['id'])) { - $properties = ['destination', 'migration_dependencies']; - foreach ($properties as $property) { - if (isset($definition[$property])) { - array_walk_recursive($definition[$property], function (&$value) { - if (is_string($value)) { - $value = preg_replace('/d([67])_(node|node_translation|node_revision)($|:.*)/', 'd$1_node_master$3', $value); - } - return $value; - }); - } - } + $is_non_master_node_migration = preg_match('/d([67])_(node|node_translation|node_revision)($|:.*)/', $definition['id']); + // Fix references to the non master node migrations. + if (!$is_non_master_node_migration && isset($definition['destination'])) { + array_walk_recursive($definition['destination'], $replace_with_master_migrations); + } + if (!$is_non_master_node_migration && isset($definition['migration_dependencies'])) { + array_walk_recursive($definition['migration_dependencies'], $replace_with_master_migrations); } // Pipeline does not extract the migration_lookup return value.