Skip to content

Instantly share code, notes, and snippets.

@brooke-heaton
Last active March 3, 2017 03:02
Show Gist options
  • Save brooke-heaton/4b350fc30d2d771a161978c07dc11a4a to your computer and use it in GitHub Desktop.
Save brooke-heaton/4b350fc30d2d771a161978c07dc11a4a to your computer and use it in GitHub Desktop.
Get New Entity ID for Migrated Entity Based on Old Entity ID in Migration Map
<?php
/**
* Helper function to fetch the new Drupal 7 ID of a migrated entity
* if we know the old id
*
* @param $old_nid - old nid of biography node from legacy node ref
* @return tid of the new term
*/
function GetMigratedNodeNewNID($old_nid) {
if (NULL !== $old_nid) {
$migration = MigrationBase::getInstance('MigrationName');
$migration_table = $migration->getMap()->getMapTable();
$results = db_select($migration_table, 'mt')
->fields('mt', array('sourceid1', 'destid1'))
// In this case the $old_nid was an array and we need the
// first value
->condition('sourceid1', $old_nid[0], '=')
->execute()
->fetchAllAssoc('sourceid1');
if (NULL !== $results) {
$dest_nid = $results[$new_nid][0]->destid1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment