You are here

protected function MigrateBatchExecutable::batchOperations in Migrate Tools 8.5

Same name and namespace in other branches
  1. 8.4 src/MigrateBatchExecutable.php \Drupal\migrate_tools\MigrateBatchExecutable::batchOperations()

Helper to generate the batch operations for importing migrations.

Parameters

\Drupal\migrate\Plugin\MigrationInterface[] $migrations: The migrations.

string $operation: The batch operation to perform.

array $options: The migration options.

Return value

array The batch operations to perform.

1 call to MigrateBatchExecutable::batchOperations()
MigrateBatchExecutable::batchImport in src/MigrateBatchExecutable.php
Setup batch operations for running the migration.

File

src/MigrateBatchExecutable.php, line 138

Class

MigrateBatchExecutable
Defines a migrate executable class for batch migrations through UI.

Namespace

Drupal\migrate_tools

Code

protected function batchOperations(array $migrations, $operation, array $options = []) {
  $operations = [];
  foreach ($migrations as $id => $migration) {
    if (!empty($options['update'])) {
      $migration
        ->getIdMap()
        ->prepareUpdate();
    }
    if (!empty($options['force'])) {
      $migration
        ->set('requirements', []);
    }
    else {
      $dependencies = $migration
        ->getMigrationDependencies();
      if (!empty($dependencies['required'])) {
        $required_migrations = $this->migrationPluginManager
          ->createInstances($dependencies['required']);

        // For dependent migrations will need to be migrate all items.
        $operations = array_merge($operations, $this
          ->batchOperations($required_migrations, $operation, [
          'limit' => 0,
          'update' => $options['update'],
          'force' => $options['force'],
          'sync' => $options['sync'],
        ]));
      }
    }
    $operations[] = [
      '\\Drupal\\migrate_tools\\MigrateBatchExecutable::batchProcessImport',
      [
        $migration
          ->id(),
        $options,
      ],
    ];
  }
  return $operations;
}