You are here

public function MigrateSQLMap::lookupSourceID in Migrate 7.2

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

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

Parameters

array $destination_id: Array of destination key values.

Return value

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

Overrides MigrateMap::lookupSourceID

1 call to MigrateSQLMap::lookupSourceID()
MigrateSQLMap::deleteDestination in plugins/sources/sqlmap.inc
Delete the map entry and any message table entries for the specified destination row.

File

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

Class

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

Code

public function lookupSourceID(array $destination_id) {
  migrate_instrument_start('lookupSourceID');

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

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