You are here

public function Sql::delete in Drupal 10

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

Deletes the map and message entries for a given source record.

Parameters

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

bool $messages_only: (optional) TRUE to only delete the migrate messages. Defaults to FALSE.

Overrides MigrateIdMapInterface::delete

File

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

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

public function delete(array $source_id_values, $messages_only = FALSE) {
  if (empty($source_id_values)) {
    throw new MigrateException('Without source identifier values it is impossible to find the row to delete.');
  }
  if (!$messages_only) {
    $map_query = $this
      ->getDatabase()
      ->delete($this
      ->mapTableName());
    $map_query
      ->condition($this::SOURCE_IDS_HASH, $this
      ->getSourceIdsHash($source_id_values));

    // 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 = $this
    ->getDatabase()
    ->delete($this
    ->messageTableName());
  $message_query
    ->condition($this::SOURCE_IDS_HASH, $this
    ->getSourceIdsHash($source_id_values));
  $message_query
    ->execute();
}