You are here

function drush_migrate_tools_migrate_status in Migrate Tools 8.3

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

Parameters

string $migration_names:

File

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

Code

function drush_migrate_tools_migrate_status($migration_names = '') {
  $names_only = drush_get_option('names-only');
  $migrations = drush_migrate_tools_migration_list($migration_names);
  $table = [];

  // Take it one group at a time, listing the migrations within each group.
  foreach ($migrations as $group_id => $migration_list) {
    $group = MigrationGroup::load($group_id);
    $group_name = !empty($group) ? "{$group->label()} ({$group->id()})" : $group_id;
    if ($names_only) {
      $table[] = [
        dt('Group: @name', array(
          '@name' => $group_name,
        )),
      ];
    }
    else {
      $table[] = [
        dt('Group: @name', array(
          '@name' => $group_name,
        )),
        dt('Status'),
        dt('Total'),
        dt('Imported'),
        dt('Unprocessed'),
        dt('Last imported'),
      ];
    }
    foreach ($migration_list as $migration_id => $migration) {
      try {
        $map = $migration
          ->getIdMap();
        $imported = $map
          ->importedCount();
        $source_plugin = $migration
          ->getSourcePlugin();
      } catch (Exception $e) {
        drush_log(dt('Failure retrieving information on @migration: @message', [
          '@migration' => $migration_id,
          '@message' => $e
            ->getMessage(),
        ]));
        continue;
      }
      if ($names_only) {
        $table[] = [
          $migration_id,
        ];
      }
      else {
        try {
          $source_rows = $source_plugin
            ->count();

          // -1 indicates uncountable sources.
          if ($source_rows == -1) {
            $source_rows = dt('N/A');
            $unprocessed = dt('N/A');
          }
          else {
            $unprocessed = $source_rows - $map
              ->processedCount();
          }
        } catch (Exception $e) {
          drush_print($e
            ->getMessage());
          drush_log(dt('Could not retrieve source count from @migration: @message', [
            '@migration' => $migration_id,
            '@message' => $e
              ->getMessage(),
          ]));
          $source_rows = dt('N/A');
          $unprocessed = dt('N/A');
        }
        $status = $migration
          ->getStatusLabel();
        $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported');
        $last_imported = $migrate_last_imported_store
          ->get($migration
          ->id(), FALSE);
        if ($last_imported) {

          /** @var DateFormatter $date_formatter */
          $date_formatter = \Drupal::service('date.formatter');
          $last_imported = $date_formatter
            ->format($last_imported / 1000, 'custom', 'Y-m-d H:i:s');
        }
        else {
          $last_imported = '';
        }
        $table[] = [
          $migration_id,
          $status,
          $source_rows,
          $imported,
          $unprocessed,
          $last_imported,
        ];
      }
    }
  }
  drush_print_table($table);
}