You are here

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

Retrieves a traversable object of messages related to source records.

Parameters

array $source_id_values: (optional) The source identifier keyed values of the record, e.g. ['nid' => 5]. If empty (the default), all messages are retrieved.

int $level: (optional) Message severity. If NULL (the default), retrieve messages of all severities.

Return value

\Traversable Retrieves a traversable object of message objects of unspecified class. Each object has the following public properties:

MigrationInterface::MESSAGE_WARNING, MigrationInterface::MESSAGE_NOTICE, MigrationInterface::MESSAGE_INFORMATIONAL.

Overrides MigrateIdMapInterface::getMessages

File

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

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

public function getMessages(array $source_id_values = [], $level = NULL) {
  $query = $this
    ->getDatabase()
    ->select($this
    ->messageTableName(), 'msg');
  $condition = sprintf('[msg].[%s] = [map].[%s]', $this::SOURCE_IDS_HASH, $this::SOURCE_IDS_HASH);
  $query
    ->addJoin('LEFT', $this
    ->mapTableName(), 'map', $condition);

  // Explicitly define the fields we want. The order will be preserved: source
  // IDs, destination IDs (if possible), and then the rest.
  foreach ($this
    ->sourceIdFields() as $id => $column_name) {
    $query
      ->addField('map', $column_name, "src_{$id}");
  }
  foreach ($this
    ->destinationIdFields() as $id => $column_name) {
    $query
      ->addField('map', $column_name, "dest_{$id}");
  }
  $query
    ->fields('msg', [
    'msgid',
    $this::SOURCE_IDS_HASH,
    'level',
    'message',
  ]);
  if ($source_id_values) {
    $query
      ->condition('msg.' . $this::SOURCE_IDS_HASH, $this
      ->getSourceIdsHash($source_id_values));
  }
  if ($level) {
    $query
      ->condition('msg.level', $level);
  }
  return $query
    ->execute();
}