Last active
March 3, 2017 03:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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