supportsRollback example

'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']);
    }

    
'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']);
    }

    
'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.
Home | Imprint | This part of the site doesn't use cookies.