You are here

public function MigrationCommands::migrate in Lightning Workflow 8.3

Same name and namespace in other branches
  1. 8.2 modules/lightning_scheduler/src/Commands/MigrationCommands.php \Drupal\lightning_scheduler\Commands\MigrationCommands::migrate()

Migrates scheduled transition data to the new base fields.

@command lightning:scheduler:migrate

Parameters

string $entity_type_id: (optional) The entity type ID to migrate.

File

modules/lightning_scheduler/src/Commands/MigrationCommands.php, line 45

Class

MigrationCommands
Provides Drush commands for migrating scheduler data to the new base fields.

Namespace

Drupal\lightning_scheduler\Commands

Code

public function migrate($entity_type_id = NULL) {
  $out = $this
    ->output();
  $entity_types = $this->migrator
    ->getEntityTypesToMigrate((array) $entity_type_id);
  if (empty($entity_types)) {
    if ($entity_type_id) {
      $out
        ->writeln("The {$entity_type_id} entity type does not need to be migrated.");
    }
    else {
      $out
        ->writeln('All migrations are complete.');
    }
    return;
  }
  $message = $this->migrator
    ->generatePreMigrationMessage($entity_types, FALSE);
  $out
    ->writeln((string) $message);
  $continue = $this
    ->confirm('Continue?');
  if (empty($continue)) {
    return;
  }
  foreach ($entity_types as $entity_type_id => $entity_type) {

    // Create a progress callback which will output a message for every ten
    // items migrated.
    $callback = function ($entity_type_id, $count) use ($entity_type, $out) {
      if ($count % 10 === 0) {
        $variables = [
          '@singular' => $entity_type
            ->getSingularLabel(),
          '@plural' => $entity_type
            ->getPluralLabel(),
        ];
        $message = new PluralTranslatableMarkup($count, '1 @singular migrated.', '@count @plural migrated.', $variables);
        $out
          ->writeln((string) $message);
      }
    };
    $this->migrator
      ->migrateAll($entity_type_id, $callback);
  }
}