Created
July 11, 2014 17:40
-
-
Save danalloway/526e2870af11707cf205 to your computer and use it in GitHub Desktop.
Drupal - Feeds Tamper - Legacy Import ID Swap
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 | |
/** | |
* When migrating Drupal sites using Feeds sometimes you'll need to re-map entity relationships. | |
* When importing User Accounts, I always save the legacy UID from the old system. | |
* Then while importing data that needs to re-map to the UID, I load it the legacy UID from the CSV, | |
* then swap it out with the newley created ID using Feeds Tamper PHP. | |
*/ | |
if (!empty($field)) { | |
$query = new EntityFieldQuery(); | |
$query->entityCondition('entity_type', 'user') | |
->entityCondition('bundle', 'user') | |
->fieldCondition('field_legacy_id', 'value', $field, '='); | |
$result = $query->execute(); | |
if (isset($result['user'])) { | |
$user = array_shift($result['user']); | |
return $user->uid; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment