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 @@ -13,7 +13,6 @@ use Drupal\Core\State\StateInterface; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateException; -use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Row; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -40,7 +39,7 @@ protected $entityQuery; /** - * An array of entity Ids for the 'commented entity' keyed by entity type. + * An array of entity IDs for the 'commented entity' keyed by entity type. * * @var array */ @@ -119,19 +118,18 @@ 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')) { - $result = $this->entityQuery - ->get($stub_commented_entity_type) - ->range(0, 1) - ->execute(); - if ($result) { - $this->stubCommentedEntityIds[$stub_commented_entity_type] = array_pop($result); - $row->setSourceProperty($id_key, $this->stubCommentedEntityIds[$stub_commented_entity_type]); - } + $id_key = $entity_type->getKey('id'); + $result = $this->entityQuery + ->get($stub_commented_entity_type) + ->range(0, 1) + ->execute(); + if ($result) { + $this->stubCommentedEntityIds[$stub_commented_entity_type] = array_pop($result); + $row->setSourceProperty($id_key, $this->stubCommentedEntityIds[$stub_commented_entity_type]); + } + else { + throw new MigrateException(t('Could not find parent entity to use for comment %id', ['%id' => implode(':', $row->getSourceIdValues())]), MigrationInterface::MESSAGE_ERROR); } - } - if (empty($this->stubCommentedEntityIds[$stub_commented_entity_type])) { - 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]); 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 @@ -20,8 +20,8 @@ use CommentTestTrait; // Directly testing that comments' entity_id is populated upon importing is - // not straightforward, but RDF module serves as an implicit test; - // its hook_comment_storage_load() references $comment->getCommentedEntity(). + // not straightforward, but RDF module serves as an implicit test - + // its hook_comment_storage_load() references a stubbed comment. static $modules = ['node', 'comment', 'text', 'filter', 'rdf']; /**