function Sql::lookupSourceId

Same name in other branches
  1. 9 core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::lookupSourceId()
  2. 8.9.x core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::lookupSourceId()
  3. 11.x core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::lookupSourceId()

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 590

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');
    // To allow source field names to be defined with spaces and special
    // characters, create an alias map of column alias to source field name,
    // since SQL column aliases do not support spaces or special characters.
    $alias_map = [];
    foreach ($source_id_fields as $source_field_name => $id_map_field_name) {
        $alias = $query->addField('map', $id_map_field_name);
        $alias_map[$alias] = $source_field_name;
    }
    foreach ($this->destinationIdFields() as $field_name => $destination_id) {
        $query->condition("map.{$destination_id}", $destination_id_values[$field_name], '=');
    }
    $result = $query->execute()
        ->fetchAssoc() ?: [];
    $source_ids = [];
    foreach ($result as $alias => $id) {
        $source_ids[$alias_map[$alias]] = $id;
    }
    return $source_ids;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.