You are here

public function MigrationDrushCommandProgress::initializeProgress in Migrate Tools 8.5

Same name and namespace in other branches
  1. 8.4 src/EventSubscriber/MigrationDrushCommandProgress.php \Drupal\migrate_tools\EventSubscriber\MigrationDrushCommandProgress::initializeProgress()

Initializes the progress bar.

This must be called before the progress bar can be used.

Parameters

\Symfony\Component\Console\Output\OutputInterface $output: The output.

\Drupal\migrate\Plugin\MigrationInterface $migration: The migration.

File

src/EventSubscriber/MigrationDrushCommandProgress.php, line 63

Class

MigrationDrushCommandProgress
Import and rollback progress bar.

Namespace

Drupal\migrate_tools\EventSubscriber

Code

public function initializeProgress(OutputInterface $output, MigrationInterface $migration) {

  // Don't display progress bar if explicitly disabled.
  if (!empty($migration->skipProgressBar)) {
    return;
  }

  // If the source is configured to skip counts, a progress bar is not
  // possible.
  if (!empty($migration
    ->getSourceConfiguration()['skip_count'])) {
    return;
  }
  try {

    // Clone so that any generators aren't initialized prematurely.
    $source = clone $migration
      ->getSourcePlugin();
    $this->symfonyProgressBar = new ProgressBar($output, $source
      ->count());
  } catch (\Exception $exception) {
    if (!empty($migration->continueOnFailure)) {
      $this->logger
        ->error($exception
        ->getMessage());
    }
    else {
      throw $exception;
    }
  }
}