You are here

public function Sql::deleteDestination 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::deleteDestination()

Deletes the map and message table entries for a given destination row.

Parameters

array $destination_id_values: The destination identifier key value pairs we should do the deletes for.

Overrides MigrateIdMapInterface::deleteDestination

File

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

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

public function deleteDestination(array $destination_id_values) {
  $map_query = $this
    ->getDatabase()
    ->delete($this
    ->mapTableName());
  $message_query = $this
    ->getDatabase()
    ->delete($this
    ->messageTableName());
  $source_id_values = $this
    ->lookupSourceId($destination_id_values);
  if (!empty($source_id_values)) {
    foreach ($this
      ->destinationIdFields() as $field_name => $destination_id) {
      $map_query
        ->condition($destination_id, $destination_id_values[$field_name]);
    }

    // Notify anyone listening of the map row we're about to delete.
    $this->eventDispatcher
      ->dispatch(new MigrateMapDeleteEvent($this, $source_id_values), MigrateEvents::MAP_DELETE);
    $map_query
      ->execute();
    $message_query
      ->condition($this::SOURCE_IDS_HASH, $this
      ->getSourceIdsHash($source_id_values));
    $message_query
      ->execute();
  }
}