You are here

public function Sql::lookupSourceId in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::lookupSourceId()
  2. 10 core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::lookupSourceId()

Looks up the source identifier.

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

Parameters

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

Return value

array The source identifier keyed values of the record, e.g. ['nid' => 5], or an empty array on failure.

Overrides MigrateIdMapInterface::lookupSourceId

1 call to Sql::lookupSourceId()
Sql::deleteDestination in core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
Deletes the map and message table entries for a given destination row.

File

core/modules/migrate/src/Plugin/migrate/id_map/Sql.php, line 570

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

public function lookupSourceId(array $destination_id_values) {
  $source_id_fields = $this
    ->sourceIdFields();
  $query = $this
    ->getDatabase()
    ->select($this
    ->mapTableName(), 'map');
  foreach ($source_id_fields as $source_field_name => $idmap_field_name) {
    $query
      ->addField('map', $idmap_field_name, $source_field_name);
  }
  foreach ($this
    ->destinationIdFields() as $field_name => $destination_id) {
    $query
      ->condition("map.{$destination_id}", $destination_id_values[$field_name], '=');
  }
  $result = $query
    ->execute();
  return $result
    ->fetchAssoc() ?: [];
}