currentDestination example


  public function testRollback(array $id_map_records, bool $rollback_called = TRUE, array $source_id_keys = ['source'], array $destination_id_keys = ['destination'], int $expected_result = MigrationInterface::RESULT_COMPLETED) {
    $id_map = $this
      ->getTestRollbackIdMap($id_map_records$source_id_keys$destination_id_keys)
      ->reveal();

    $migration = $this->getMigration($id_map);
    $destination = $this->prophesize(MigrateDestinationInterface::class);
    if ($rollback_called) {
      $destination->rollback($id_map->currentDestination())->shouldBeCalled();
    }
    else {
      $destination->rollback()->shouldNotBeCalled();
    }
    $migration
      ->method('getDestinationPlugin')
      ->willReturn($destination->reveal());

    $executable = new TestMigrateExecutable($migration$this->message, $this->eventDispatcher);

    $this->assertEquals($expected_result$executable->rollback());
  }
$version = $this->getLegacyDrupalVersion($this->sourceDatabase);
    /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
    $all_migrations = $plugin_manager->createInstancesByTag('Drupal ' . $version);
    foreach ($all_migrations as $migration) {
      $id_map = $migration->getIdMap();
      foreach ($id_map as $source_id => $map) {
        // Convert $source_id into a keyless array so that         // \Drupal\migrate\Plugin\migrate\id_map\Sql::getSourceHash() works as         // expected.         $source_id_values = array_values(unserialize($source_id));
        $row = $id_map->getRowBySource($source_id_values);
        $destination = serialize($id_map->currentDestination());
        $message = "Migration of $source_id to $destination as part of the {$migration->id()} migration. The source row status is " . $row['source_row_status'];
        // A completed migration should have maps with         // MigrateIdMapInterface::STATUS_IGNORED or         // MigrateIdMapInterface::STATUS_IMPORTED.         $this->assertNotSame(MigrateIdMapInterface::STATUS_FAILED, $row['source_row_status']$message);
        $this->assertNotSame(MigrateIdMapInterface::STATUS_NEEDS_UPDATE, $row['source_row_status']$message);
      }
    }
  }

  /** * Creates an array of credentials for the Credential form. * * Before submitting to the Credential form the array must be processed by * BrowserTestBase::translatePostValues() before submitting. * * @return array * An array of values suitable for BrowserTestBase::translatePostValues(). * * @see \Drupal\migrate_drupal_ui\Form\CredentialForm */
// Simple map with one source and one destination ID.     $id_map = $this->setupRows(['nid']['nid'][
      [1, 101],
      [2, 102],
      [3, 103],
      // Mock a failed row by setting the destination ID to NULL.       [4, NULL],
    ]);

    // The rows are ordered by destination ID so the failed row should be first.     $id_map->rewind();
    $this->assertEquals([]$id_map->currentDestination());
    $this->assertEquals(['nid' => 4]$id_map->currentSource());
    $id_map->next();
    $this->assertEquals(['nid' => 101]$id_map->currentDestination());
    $this->assertEquals(['nid' => 1]$id_map->currentSource());
    $id_map->next();
    $this->assertEquals(['nid' => 102]$id_map->currentDestination());
    $this->assertEquals(['nid' => 2]$id_map->currentSource());
    $id_map->next();
    $this->assertEquals(['nid' => 103]$id_map->currentDestination());
    $this->assertEquals(['nid' => 3]$id_map->currentSource());
    $id_map->next();
  }
// Optimistically assume things are going to work out; if not, $return will be     // updated to some other status.     $return = MigrationInterface::RESULT_COMPLETED;

    $this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK);
    $id_map = $this->getIdMap();
    $destination = $this->migration->getDestinationPlugin();

    // Loop through each row in the map, and try to roll it back.     $id_map->rewind();
    while ($id_map->valid()) {
      $destination_key = $id_map->currentDestination();
      if ($destination_key) {
        $map_row = $id_map->getRowByDestination($destination_key);
        if (!isset($map_row['rollback_action']) || $map_row['rollback_action'] == MigrateIdMapInterface::ROLLBACK_DELETE) {
          $this->getEventDispatcher()
            ->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::PRE_ROW_DELETE);
          $destination->rollback($destination_key);
          $this->getEventDispatcher()
            ->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::POST_ROW_DELETE);
        }
        // We're now done with this row, so remove it from the map.         $id_map->deleteDestination($destination_key);
      }
Home | Imprint | This part of the site doesn't use cookies.