Unverified Commit a94e3c35 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2800715 by dcam, shashikant_chauhan, mikeryan, quietone, alexpott:...

Issue #2800715 by dcam, shashikant_chauhan, mikeryan, quietone, alexpott: Reset highwater mark *before* rolling back

(cherry picked from commit 420f7b2f)
parent 335bc707
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -608,15 +608,15 @@ protected function getHighWaterField() {
   * {@inheritdoc}
   */
  public function preRollback(MigrateRollbackEvent $event) {
    // Nothing to do in this implementation.
    // Reset the high-water mark.
    $this->saveHighWater(NULL);
  }

  /**
   * {@inheritdoc}
   */
  public function postRollback(MigrateRollbackEvent $event) {
    // Reset the high-water mark.
    $this->saveHighWater(NULL);
    // Nothing to do in this implementation.
  }

  /**
+27 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\migrate\Event\MigrateRollbackEvent;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateSkipRowException;
@@ -448,6 +449,32 @@ protected function getMigrateExecutable($migration) {
    return new MigrateExecutable($migration, $message, $event_dispatcher);
  }

  /**
   * @covers ::preRollback
   */
  public function testPreRollback(): void {
    $this->migrationConfiguration['id'] = 'test_migration';
    $plugin_id = 'test_migration';
    $migration = $this->getMigration();

    // Verify that preRollback() sets the high water mark to NULL.
    $key_value = $this->createMock(KeyValueStoreInterface::class);
    $key_value->expects($this->once())
      ->method('set')
      ->with($plugin_id, NULL);
    $key_value_factory = $this->createMock(KeyValueFactoryInterface::class);
    $key_value_factory->expects($this->once())
      ->method('get')
      ->with('migrate:high_water')
      ->willReturn($key_value);
    $container = new ContainerBuilder();
    $container->set('keyvalue', $key_value_factory);
    \Drupal::setContainer($container);

    $source = new StubSourceGeneratorPlugin([], $plugin_id, [], $migration);
    $source->preRollback(new MigrateRollbackEvent($migration));
  }

}

/**