getSourceConfiguration example


  protected function doCreateStub(MigrationInterface $migration, array $source_ids, array $default_values = []) {
    $destination = $migration->getDestinationPlugin(TRUE);
    $process = $migration->getProcess();
    $id_map = $migration->getIdMap();
    $migrate_executable = new MigrateExecutable($migration);
    $row = new Row($source_ids + $migration->getSourceConfiguration()$migration->getSourcePlugin()->getIds(), TRUE);
    $migrate_executable->processRow($row$process);
    foreach ($default_values as $key => $value) {
      $row->setDestinationProperty($key$value);
    }
    $destination_ids = [];
    try {
      $destination_ids = $destination->import($row);
    }
    catch (\Exception $e) {
      $id_map->saveMessage($row->getSourceIdValues()$e->getMessage());
    }
    
/** * Helper method to check if we are migrating translated nodes. * * @param \Drupal\migrate\Event\EventBase $event * The migrate event. * * @return bool * True if we are migrating translated nodes, false otherwise. */
  protected function isNodeTranslationsMigration(EventBase $event) {
    $migration = $event->getMigration();
    $source_configuration = $migration->getSourceConfiguration();
    $destination_configuration = $migration->getDestinationConfiguration();
    return !empty($source_configuration['translations']) && $destination_configuration['plugin'] === 'entity:node';
  }

  /** * Maps the old nid to the new one in the key value collection. * * @param \Drupal\migrate\Event\MigratePostRowSaveEvent $event * The migrate post row save event. */
  public function onPostRowSave(MigratePostRowSaveEvent $event) {
    
$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][]));
  }

  /** * Tests that an error is logged if the plugin manager throws an exception. */


  /** * {@inheritdoc} */
  protected function prepareMigration(MigrationInterface $migration) {
    // File migrations need a source_base_path.     // @see MigrateUpgradeRunBatch::run     $destination = $migration->getDestinationConfiguration();
    if ($destination['plugin'] === 'entity:file') {
      // Make sure we have a single trailing slash.       $source = $migration->getSourceConfiguration();
      $source['site_path'] = 'core/tests/fixtures';
      $source['constants']['source_base_path'] = $this->root . '/';
      $migration->set('source', $source);
    }
  }

}


  /** * Tests merging configuration into a plugin through the plugin manager. * * @dataProvider mergeProvider */
  public function testConfigurationMerge($id$configuration$expected) {
    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->container->get('plugin.manager.migration')
      ->createInstance($id$configuration);
    $source_configuration = $migration->getSourceConfiguration();
    $this->assertEquals($expected$source_configuration);
  }

  /** * Provide configuration data for testing. */
  public function mergeProvider() {
    return [
      // Tests adding new configuration to a migration.       [
        // New configuration.
$info = $this->getFileMigrationInfo();
    $fs = $this->container->get('file_system');
    // Ensure that the files directory exists.     $fs->mkdir(dirname($info['path']), NULL, TRUE);
    // Put test file in the source directory.     file_put_contents($info['path']str_repeat('*', $info['size']));

    /** @var \Drupal\migrate\Plugin\Migration $migration */
    $migration = $this->getMigration($info['plugin_id']);
    // Set the source plugin's source_base_path configuration value, which     // would normally be set by the user running the migration.     $source = $migration->getSourceConfiguration();
    $source['constants']['source_base_path'] = $fs->realpath($info['base_path']);
    $migration->set('source', $source);
    $this->executeMigration($migration);
  }

  /** * Tests a single file entity. * * @param int $id * The file ID. * @param string $name * The expected file name. * @param string $uri * The expected URI. * @param string $mime * The expected MIME type. * @param string $size * The expected file size. * @param string $created * The expected creation time. * @param string $changed * The expected modification time. * @param string $uid * The expected owner ID. */
Home | Imprint | This part of the site doesn't use cookies.