buildDependencyMigration example

/** * Tests building dependencies for multiple migrations. * * @dataProvider dependencyProvider */
  public function testDependencyBuilding($migrations_data$result_ids) {
    $migrations = [];
    foreach ($migrations_data as $migration_id => $migration_data) {
      $migrations[$migration_id] = new TestMigrationMock($migration_id$migration_data['migration_dependencies']);
    }

    $ordered_migrations = $this->pluginManager->buildDependencyMigration($migrations[]);

    // Verify results.     $this->assertEquals($result_idsarray_keys($ordered_migrations));
    foreach ($migrations_data as $migration_id => $migration_data) {
      $migration = $migrations[$migration_id];

      $requirements = $migration_data['result_requirements'];
      if (empty($requirements)) {
        $this->assertEquals([]$migration->set);
      }
      else {
        
'd6_user_profile_field_instance_translation',
      'language',
    ];

    /** @var \Drupal\migrate\Plugin\MigrationPluginManager $migration_plugin_manager */
    $migration_plugin_manager = \Drupal::service('plugin.manager.migration');

    $migrations = [];
    foreach ($migration_ids as $migration_id) {
      $migrations[$migration_id] = $migration_plugin_manager->createInstance($migration_id[]);
    }
    $migrations = $migration_plugin_manager->buildDependencyMigration($migrations[]);

    // Execute the import.     $ids = array_keys($migrations);
    $this->executeMigrations($ids);

    // Execute the rollback.     $ids = array_reverse($ids);
    try {
      foreach ($ids as $id) {
        // Language rollback tries to rollback the default language so skip it.         if ($id == 'language') {
          
foreach ($plugin_ids as $plugin_id) {
      $instances[$plugin_id] = $factory->createInstance($plugin_id$configuration[$plugin_id] ?? []);
    }

    // @todo Remove loop when the ability to call ::getMigrationDependencies()     // without expanding plugins is removed.     foreach ($instances as $migration) {
      $migration->set('migration_dependencies', $migration->getMigrationDependencies(TRUE));
    }

    // Sort the migrations based on their dependencies.     return $this->buildDependencyMigration($instances[]);
  }

  /** * {@inheritdoc} */
  public function createInstancesByTag($tag) {
    $migrations = array_filter($this->getDefinitions()function D$migration) use ($tag) {
      return !empty($migration['migration_tags']) && in_array($tag$migration['migration_tags']);
    });
    return $migrations ? $this->createInstances(array_keys($migrations)) : [];
  }

  
Home | Imprint | This part of the site doesn't use cookies.