Skip to content

Instantly share code, notes, and snippets.

@danalloway
Created July 11, 2014 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danalloway/526e2870af11707cf205 to your computer and use it in GitHub Desktop.
Save danalloway/526e2870af11707cf205 to your computer and use it in GitHub Desktop.
Drupal - Feeds Tamper - Legacy Import ID Swap
<?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