You are here

public function Sql::lookupDestinationId in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::lookupDestinationId()

Looks up the destination identifier corresponding to a source key.

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

Parameters

array $source_id_values: The source identifier keyed values of the record, e.g. ['nid' => 5].

Return value

array The destination identifier values of the record, or NULL on failure.

Overrides MigrateIdMapInterface::lookupDestinationId

File

core/modules/migrate/src/Plugin/migrate/id_map/Sql.php, line 486
Contains \Drupal\migrate\Plugin\migrate\id_map\Sql.

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

public function lookupDestinationId(array $source_id_values) {
  if (empty($source_id_values)) {
    return array();
  }
  $query = $this
    ->getDatabase()
    ->select($this
    ->mapTableName(), 'map')
    ->fields('map', $this
    ->destinationIdFields());

  // When looking up the destination ID we require an array with both the
  // source key and value, e.g. ['nid' => 41]. However, the Migration process
  // plugin doesn't currently have a way to get the source key so we presume
  // the values have been passed through in the correct order.
  $have_keys = !isset($source_id_values[0]);
  foreach ($this
    ->sourceIdFields() as $field_name => $source_id) {
    $query
      ->condition("map.{$source_id}", $have_keys ? $source_id_values[$field_name] : array_shift($source_id_values), '=');
  }
  $result = $query
    ->execute();
  $destination_id = $result
    ->fetchAssoc();
  return array_values($destination_id ?: array());
}