getDestinationPlugin example

public function testCreateStub() {
    $destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
    $destination_plugin->import(Argument::type(Row::class))->willReturn(['id' => 2]);

    $source_plugin = $this->prophesize(MigrateSourceInterface::class);
    $source_plugin->getIds()->willReturn(['id' => ['type' => 'integer']]);

    $id_map = $this->prophesize(MigrateIdMapInterface::class);

    $migration = $this->prophesize(MigrationInterface::class);
    $migration->getIdMap()->willReturn($id_map->reveal());
    $migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
    $migration->getProcessPlugins([])->willReturn([]);
    $migration->getProcess()->willReturn([]);
    $migration->getSourceConfiguration()->willReturn([]);
    $migration->getSourcePlugin()->willReturn($source_plugin->reveal());

    $this->migrationPluginManager->createInstances(['test_migration'])->willReturn([$migration->reveal()]);

    $stub = new MigrateStub($this->migrationPluginManager->reveal());

    $this->assertSame(['id' => 2]$stub->createStub('test_migration', ['id' => 1][]));
  }

  
$migrationState = new MigrationState($fieldPluginManager->reveal()$moduleHandler->reveal()$this->createMock(MessengerInterface::class)$this->getStringTranslationStub());

    $all_migrations = [];
    foreach ($migrations as $name => $values) {
      $migration = $this->prophesize(MigrationInterface::class);
      $source = $this->prophesize(MigrateSourceInterface::class);
      $destination = $this->prophesize(MigrateDestinationInterface::class);
      $source->getSourceModule()->willReturn($values['source_module']);
      $destination->getDestinationModule()
        ->willReturn($values['destination_module']);
      $migration->getSourcePlugin()->willReturn($source->reveal());
      $migration->getDestinationPlugin()->willReturn($destination->reveal());
      $migration->getPluginId()->willReturn($name);
      $migration->label()->willReturn($name);
      $all_migrations[] = $migration->reveal();
    }

    // Tests Drupal 7 states.     $states = $migrationState->getUpgradeStates(7, $source_system_data$all_migrations);
    $this->assertEquals($expected_7$states);
    $source_system_data['module']['content'] = [
      'name' => 'content',
      'status' => TRUE,
    ];


  /** * Tests Migration::getDestinationPlugin() * * @covers ::getDestinationPlugin */
  public function testGetDestinationPlugin() {
    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration(['destination' => ['no_stub' => TRUE]]);
    $this->expectException(MigrateSkipRowException::class);
    $this->expectExceptionMessage("Stub requested but not made because no_stub configuration is set.");
    $migration->getDestinationPlugin(TRUE);
  }

}
      if (!empty(array_intersect($migration->getMigrationTags()$this->getFollowUpMigrationTags()))) {
        continue;
      }

      try {
        // @todo https://drupal.org/node/2681867 We should be able to validate         // the entire migration at this point.         $source_plugin = $migration->getSourcePlugin();
        if ($source_plugin instanceof RequirementsInterface) {
          $source_plugin->checkRequirements();
        }
        $destination_plugin = $migration->getDestinationPlugin();
        if ($destination_plugin instanceof RequirementsInterface) {
          $destination_plugin->checkRequirements();
        }
        $migrations[] = $migration;
      }
      catch (RequirementsException $e) {
        // Migrations which are not applicable given the source and destination         // site configurations (e.g., what modules are enabled) will be silently         // ignored.       }
    }

    
/** * The destination ID fields. * * @return array * The destination ID fields. */
  protected function destinationIdFields() {
    if (!isset($this->destinationIdFields)) {
      $this->destinationIdFields = [];
      $count = 1;
      foreach ($this->migration->getDestinationPlugin()->getIds() as $field => $schema) {
        $this->destinationIdFields[$field] = 'destid' . $count++;
      }
    }
    return $this->destinationIdFields;
  }

  /** * The name of the database map table. * * @return string * The map table name. */

  protected function mockFailure($migration, array $row$status = MigrateIdMapInterface::STATUS_FAILED) {
    if (is_string($migration)) {
      $migration = $this->getMigration($migration);
    }
    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $destination = array_map(function D) {
      return NULL;
    }$migration->getDestinationPlugin()->getIds());
    $row = new Row($row$migration->getSourcePlugin()->getIds());
    $migration->getIdMap()->saveIdMapping($row$destination$status);
  }

  /** * Gets the migration plugin. * * @param $plugin_id * The plugin ID of the migration to get. * * @return \Drupal\migrate\Plugin\Migration * The migration plugin. */
/** @var \Drupal\migrate\Plugin\Migration $migration */
    foreach ($migrations as $migration) {
      $definition = $migration->getPluginDefinition();
      if (is_array($definition['provider'])) {
        $provider = reset($definition['provider']);
      }
      else {
        $provider = $definition['provider'];
      }

      $source_module = $migration->getSourcePlugin()->getSourceModule();
      $destination_module = $migration->getDestinationPlugin()
        ->getDestinationModule();

      $discovered[] = implode($separator[
        $provider,
        $source_module,
        $destination_module,
      ]);
    }

    // Add the field migrations.     /** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
    
'process' => [
        'vid' => 'id',
        'name' => 'name',
        'weight' => 'weight',
      ],
      'destination' => ['plugin' => 'entity:taxonomy_vocabulary'],
    ];

    $vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
    $vocabulary_id_map = $vocabulary_migration->getIdMap();

    $this->assertTrue($vocabulary_migration->getDestinationPlugin()->supportsRollback());

    // Import and validate vocabulary config entities were created.     $vocabulary_executable = new MigrateExecutable($vocabulary_migration$this);
    $vocabulary_executable->import();
    foreach ($vocabulary_data_rows as $row) {
      /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
      $vocabulary = Vocabulary::load($row['id']);
      $this->assertNotEmpty($vocabulary);
      $map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
      $this->assertNotNull($map_row['destid1']);
    }

    

  protected function doLookup(MigrationInterface $migration, array $source_id_values) {
    $destination_keys = array_keys($migration->getDestinationPlugin()->getIds());
    $indexed_ids = $migration->getIdMap()
      ->lookupDestinationIds($source_id_values);
    $keyed_ids = [];
    foreach ($indexed_ids as $id) {
      $keyed_ids[] = array_combine($destination_keys$id);
    }
    return $keyed_ids;
  }

}
'name' => 'name',
        'weight' => 'weight',
      ],
      'destination' => ['plugin' => 'entity:taxonomy_vocabulary'],
    ];

    /** @var \Drupal\migrate\Plugin\Migration $vocabulary_migration */
    $vocabulary_migration = \Drupal::service('plugin.manager.migration')
      ->createStubMigration($definition);
    $vocabulary_id_map = $vocabulary_migration->getIdMap();

    $this->assertTrue($vocabulary_migration->getDestinationPlugin()
      ->supportsRollback());

    // Import and validate vocabulary config entities were created.     $vocabulary_executable = new MigrateExecutable($vocabulary_migration$this);
    $vocabulary_executable->import();
    foreach ($vocabulary_data_rows as $row) {
      /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
      $vocabulary = Vocabulary::load($row['id']);
      $this->assertNotEmpty($vocabulary);
      $map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
      $this->assertNotNull($map_row['destid1']);
    }
'plugin' => 'config',
        'config_name' => 'system.site',
      ],
    ];

    /** @var \Drupal\migrate\Plugin\Migration $config_migration */
    $config_migration = \Drupal::service('plugin.manager.migration')
      ->createStubMigration($definition);
    $config_id_map = $config_migration->getIdMap();

    // Rollback is not enabled for configuration translations.     $this->assertFalse($config_migration->getDestinationPlugin()->supportsRollback());

    // Import and validate config entities were created.     $config_executable = new MigrateExecutable($config_migration$this);
    $config_executable->import();
    $config = $this->config('system.site');
    $this->assertSame('Some site', $config->get('name'));
    $this->assertSame('Awesome slogan', $config->get('slogan'));
    $map_row = $config_id_map->getRowBySource(['id' => $variable[0]['id']]);
    $this->assertNotNull($map_row['destid1']);

    // Rollback and verify the configuration changes are still there.
catch (MigrateException $e) {
        $row = $source->current();
        $this->sourceIdValues = $row->getSourceIdValues();
        $this->getIdMap()->saveIdMapping($row[]$e->getStatus());
        $this->saveMessage($e->getMessage()$e->getLevel());
      }
    }

    $return = MigrationInterface::RESULT_COMPLETED;
    if ($pipeline) {
      $id_map = $this->getIdMap();
      $destination = $this->migration->getDestinationPlugin();
      while ($source->valid()) {
        $row = $source->current();
        $this->sourceIdValues = $row->getSourceIdValues();

        try {
          foreach ($pipeline as $destination_property_name => $plugins) {
            $this->processPipeline($row$destination_property_name$plugins, NULL);
          }
          $save = TRUE;
        }
        catch (MigrateException $e) {
          


  /** * {@inheritdoc} */
  public function checkRequirements() {
    // Check whether the current migration source and destination plugin     // requirements are met or not.     if ($this->getSourcePlugin() instanceof RequirementsInterface) {
      $this->getSourcePlugin()->checkRequirements();
    }
    if ($this->getDestinationPlugin() instanceof RequirementsInterface) {
      $this->getDestinationPlugin()->checkRequirements();
    }

    if (empty($this->requirements)) {
      // There are no requirements to check.       return;
    }
    /** @var \Drupal\migrate\Plugin\MigrationInterface[] $required_migrations */
    $required_migrations = $this->getMigrationPluginManager()->createInstances($this->requirements);

    $missing_migrations = array_diff($this->requirements, array_keys($required_migrations));
    
// Ensure the migration plugin manager returns our migration.     $migration_plugin_manager->createInstances(Argument::exact(['destination_migration']))
      ->willReturn(['destination_migration' => $destination_migration->reveal()]);

    $configuration = [
      'no_stub' => TRUE,
      'migration' => 'destination_migration',
    ];

    $migration_plugin->id()->willReturn('actual_migration');
    $destination_migration->getDestinationPlugin(TRUE)->shouldNotBeCalled();

    $migration = MigrationLookup::create($this->prepareContainer()$configuration, '', []$migration_plugin->reveal());
    $result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
    $this->assertNull($result);
  }

  /** * @covers ::transform */
  public function testTransformWithStubbing() {
    $migration_plugin = $this->prophesize(MigrationInterface::class);
    

  protected function buildDiscoveredDestinationsBySource($version, array $migrations, array $source_system_data) {
    $discovered_upgrade_paths = [];
    $table_data = [];
    foreach ($migrations as $migration) {
      $migration_id = $migration->getPluginId();
      $source_module = $migration->getSourcePlugin()->getSourceModule();
      if (!$source_module) {
        $this->messenger()
          ->addError($this->t('Source module not found for @migration_id.', ['@migration_id' => $migration_id]));
      }
      $destination_module = $migration->getDestinationPlugin()
        ->getDestinationModule();
      if (!$destination_module) {
        $this->messenger()
          ->addError($this->t('Destination module not found for @migration_id.', ['@migration_id' => $migration_id]));
      }

      if ($source_module && $destination_module) {
        $discovered_upgrade_paths[$source_module][] = $destination_module;
        $table_data[$source_module][$destination_module][$migration_id] = $migration->label();
      }
    }

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