You are here

public function MigrateSQLMap::lookupDestinationID in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/sources/sqlmap.inc \MigrateSQLMap::lookupDestinationID()

Given a (possibly multi-field) source key, return the (possibly multi-field) destination key it is mapped to.

Parameters

array $source_id: Array of source key values.

Return value

array Array of destination key values, or NULL on failure.

Overrides MigrateMap::lookupDestinationID

File

plugins/sources/sqlmap.inc, line 371
Defines a Drupal db-based implementation of MigrateMap.

Class

MigrateSQLMap
@file Defines a Drupal db-based implementation of MigrateMap.

Code

public function lookupDestinationID(array $source_id) {
  migrate_instrument_start('lookupDestinationID');

  // Try a cache lookup if enabled.
  if ($this->cacheMapLookups) {
    $cache =& drupal_static($this->mapTable . '_destinationIDCache');
    $serialized = json_encode($source_id);
    if (isset($cache[$serialized])) {
      migrate_instrument_stop('lookupDestinationID');
      return $cache[$serialized];
    }
  }
  $query = $this->connection
    ->select($this->mapTable, 'map')
    ->fields('map', $this->destinationKeyMap);
  foreach ($this->sourceKeyMap as $key_name) {
    $query = $query
      ->condition("map.{$key_name}", array_shift($source_id), '=');
  }
  $result = $query
    ->execute();
  $destination_id = $result
    ->fetchAssoc();

  // Store the id in a cache if enabled.
  if ($this->cacheMapLookups) {
    $cache[$serialized] = $destination_id;
  }
  migrate_instrument_stop('lookupDestinationID');
  return $destination_id;
}