You are here

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

Saves a message related to a source record in the migration message table.

Parameters

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

string $message: The message to record.

int $level: (optional) The message severity. Defaults to MigrationInterface::MESSAGE_ERROR.

Overrides MigrateIdMapInterface::saveMessage

File

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

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

public function saveMessage(array $source_id_values, $message, $level = MigrationInterface::MESSAGE_ERROR) {
  foreach ($this
    ->sourceIdFields() as $field_name => $source_id) {

    // If any key value is not set, we can't save.
    if (!isset($source_id_values[$field_name])) {
      return;
    }
  }
  $fields[$this::SOURCE_IDS_HASH] = $this
    ->getSourceIdsHash($source_id_values);
  $fields['level'] = $level;
  $fields['message'] = $message;
  $this
    ->getDatabase()
    ->insert($this
    ->messageTableName())
    ->fields($fields)
    ->execute();

  // Notify anyone listening of the message we've saved.
  $this->eventDispatcher
    ->dispatch(new MigrateIdMapMessageEvent($this->migration, $source_id_values, $message, $level), MigrateEvents::IDMAP_MESSAGE);
}