diff -u b/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php b/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php --- b/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php +++ b/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php @@ -109,30 +109,14 @@ /** * {@inheritdoc} */ - protected function getEntity(Row $row, array $old_destination_id_values) { - if ($row->isStub()) { - $this->processStubRow($row); - } - - return parent::getEntity($row, $old_destination_id_values); - } - - /** - * Specific processing for stub rows. - * - * @param \Drupal\migrate\Row $row - * The row object. - * - * @throws \Drupal\migrate\MigrateSkipRowException - */ protected function processStubRow(Row $row) { + parent::processStubRow($row); $stub_commented_entity_type = $row->getDestinationProperty('entity_type'); // While parent::getEntity() fills the bundle property for stub entities // if it's still empty, here we must also make sure entity_id/entity_type // are filled (so $comment->getCommentedEntity() always returns a value). if (empty($this->stubCommentedEntityIds[$stub_commented_entity_type])) { - // Fill stub entity id. Any id will do, as long as it exists. $entity_type = $this->entityManager->getDefinition($stub_commented_entity_type); if ($id_key = $entity_type->getKey('id')) { @@ -142,15 +126,18 @@ ->execute(); if ($result) { $this->stubCommentedEntityIds[$stub_commented_entity_type] = array_pop($result); + $row->setSourceProperty($id_key, $this->stubCommentedEntityIds[$stub_commented_entity_type]); } } } if (empty($this->stubCommentedEntityIds[$stub_commented_entity_type])) { - throw new MigrateException(t('Could not derive commented entity for comment %id', array('%id' => implode(':', $row->getSourceIdValues()))), MigrationInterface::MESSAGE_ERROR); + throw new MigrateException(t('Could not derive commented entity for comment %id', ['%id' => implode(':', $row->getSourceIdValues())]), MigrationInterface::MESSAGE_ERROR); } $row->setDestinationProperty('entity_id', $this->stubCommentedEntityIds[$stub_commented_entity_type]); $row->setDestinationProperty('entity_type', $stub_commented_entity_type); + $row->setDestinationProperty('created', REQUEST_TIME); + $row->setDestinationProperty('changed', REQUEST_TIME); } } diff -u b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php --- b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php +++ b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php @@ -33,8 +33,12 @@ $this->installEntitySchema('node'); $this->installEntitySchema('comment'); $this->installSchema('comment', ['comment_entity_statistics']); + $this->installSchema('system', ['router']); $this->installConfig(['node', 'comment']); + // The entity.node.canonical route must exist when the RDF hook is called. + $this->container->get('router.builder')->rebuild(); + entity_create('node_type', array('type' => 'page'))->save(); entity_create('node_type', array('type' => 'story'))->save(); $this->addDefaultCommentField('node', 'story'); reverted: --- b/core/modules/migrate/src/Plugin/migrate/process/Migration.php +++ a/core/modules/migrate/src/Plugin/migrate/process/Migration.php @@ -122,14 +122,6 @@ $values[$source_id] = $source_id_values[$migration->id()][$index]; } - // If we have constants in the source then add them to the values and the - // process array. - if (isset($migration->get('source')['constants'])) { - $constants = $migration->get('source')['constants']; - $values += $constants; - $process += array_combine(array_keys($constants), array_keys($constants)); - } - $stub_row = new Row($values + $migration->get('source'), $source_ids, TRUE); // Do a normal migration with the stub row. only in patch2: unchanged: --- a/core/modules/migrate/src/Plugin/migrate/destination/Entity.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/Entity.php @@ -113,12 +113,11 @@ protected function getEntity(Row $row, array $old_destination_id_values) { $this->updateEntity($entity, $row); } else { - $values = $row->getDestination(); - // Stubs might not have the bundle specified. + // Stubs might need some required fields filled in. if ($row->isStub()) { - $values = $this->processStubValues($values); + $this->processStubRow($row); } - $entity = $this->storage->create($values); + $entity = $this->storage->create($row->getDestination()); $entity->enforceIsNew(); } return $entity; @@ -139,21 +138,14 @@ protected function getEntityId(Row $row) { /** * Process the stub values. * - * @param array $values - * An array of destination values. - * - * @return array - * The processed stub values. + * @param \Drupal\migrate\Row $row + * The row of data. */ - protected function processStubValues(array $values) { - $values = array_intersect_key($values, $this->getIds()); - + protected function processStubRow(Row $row) { $bundle_key = $this->getKey('bundle'); - if ($bundle_key && !isset($values[$bundle_key])) { - $values[$bundle_key] = reset($this->bundles); + if ($bundle_key && empty($row->getDestinationProperty($bundle_key))) { + $row->setDestinationProperty($bundle_key, reset($this->bundles)); } - - return $values; } /**