You are here

public function Sql::getRowByDestination 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::getRowByDestination()
  2. 10 core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::getRowByDestination()

Retrieves a row by the destination identifiers.

Parameters

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

Return value

array The row(s) of data.

Overrides MigrateIdMapInterface::getRowByDestination

File

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

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

public function getRowByDestination(array $destination_id_values) {
  $query = $this
    ->getDatabase()
    ->select($this
    ->mapTableName(), 'map')
    ->fields('map');
  foreach ($this
    ->destinationIdFields() as $field_name => $destination_id) {
    if (!isset($destination_id_values[$field_name])) {
      return [];
    }
    $query
      ->condition("map.{$destination_id}", $destination_id_values[$field_name], '=');
  }
  $result = $query
    ->execute()
    ->fetchAssoc();
  return $result ? $result : [];
}