You are here

function drush_migrate_tools_migrate_messages in Migrate Tools 8

Same name and namespace in other branches
  1. 8.2 migrate_tools.drush.inc \drush_migrate_tools_migrate_messages()
  2. 8.3 migrate_tools.drush.inc \drush_migrate_tools_migrate_messages()
  3. 8.4 migrate_tools.drush.inc \drush_migrate_tools_migrate_messages()

Parameters

string $migration_id:

File

./migrate_tools.drush.inc, line 350
Command-line tools to aid performing and developing migrations.

Code

function drush_migrate_tools_migrate_messages($migration_id) {

  /** @var Migration $migration */
  $migration = Migration::load($migration_id);
  if ($migration) {
    $map = $migration
      ->getIdMap();
    $first = TRUE;
    $table = [];
    foreach ($map
      ->getMessageIterator() as $row) {
      unset($row->msgid);
      if ($first) {

        // @todo: Ideally, replace sourceid* with source key names. Or, should
        // getMessageIterator() do that?
        foreach ($row as $column => $value) {
          $table[0][] = $column;
        }
        $first = FALSE;
      }
      $table[] = (array) $row;
    }
    if (empty($table)) {
      drush_log(dt('No messages for this migration'), 'status');
    }
    else {
      if (drush_get_option('csv')) {
        foreach ($table as $row) {
          fputcsv(STDOUT, $row);
        }
      }
      else {
        $widths = [];
        foreach ($table[0] as $header) {
          $widths[] = strlen($header) + 1;
        }
        drush_print_table($table, TRUE, $widths);
      }
    }
  }
  else {
    drush_log(dt('Migration @id does not exist', [
      '@id' => $migration_id,
    ]), 'error');
  }
}