Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save junaidpv/5e44ff6d6e588d75b9698f4d940969c8 to your computer and use it in GitHub Desktop.
Save junaidpv/5e44ff6d6e588d75b9698f4d940969c8 to your computer and use it in GitHub Desktop.
Somehow the field collections migration query returns duplicate row from field_revision_ tables. Remove joining with field_revision_ and run query for each row to get parent entity type and id.
diff --git a/src/Plugin/migrate/source/d7/FieldCollectionItem.php b/src/Plugin/migrate/source/d7/FieldCollectionItem.php
index 50af07d..0dc9460 100644
--- a/src/Plugin/migrate/source/d7/FieldCollectionItem.php
+++ b/src/Plugin/migrate/source/d7/FieldCollectionItem.php
@@ -50,9 +50,6 @@ class FieldCollectionItem extends FieldableEntity {
// bundles retrieved.
if ($this->configuration['field_name']) {
$query->condition('f.field_name', $this->configuration['field_name']);
- $query->addField('fc', 'entity_type', 'parent_type');
- $query->addField('fc', 'entity_id', 'parent_id');
- $query->innerJoin('field_revision_' . $this->configuration['field_name'], 'fc', 'fc.' . $this->configuration['field_name'] . '_value = f.item_id and fc.' . $this->configuration['field_name'] . '_revision_id = f.revision_id');
}
return $query;
}
@@ -66,6 +63,18 @@ class FieldCollectionItem extends FieldableEntity {
$bundle = substr($bundle, FieldCollection::FIELD_COLLECTION_PREFIX_LENGTH);
$row->setSourceProperty('bundle', $bundle);
+ if ($this->configuration['field_name']) {
+ $query = $this->select('field_revision_' . $this->configuration['field_name'], 'fc')
+ ->fields('fc', [
+ 'entity_id',
+ 'entity_type',
+ ])
+ ->range(0, 1);
+ $parent_row = $query->execute()->fetchObject();
+ $row->setSourceProperty('parent_id', $parent_row->entity_id);
+ $row->setSourceProperty('parent_type', $parent_row->entity_type);
+ }
+
// Get Field API field values.
$field_names = array_keys($this->getFields('field_collection_item', $row->getSourceProperty('field_name')));
$item_id = $row->getSourceProperty('item_id');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment