You are here

public function Sql::deleteDestination 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::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 689
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 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(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
    $map_query
      ->execute();
    $count = 1;
    foreach ($this
      ->sourceIdFields() as $field_name => $source_id) {
      $message_query
        ->condition($source_id, $source_id_values[$field_name]);
      $count++;
    }
    $message_query
      ->execute();
  }
}