Commit 0bccb26c authored by webchick's avatar webchick

Issue #2599152 by mikeryan, jhedstrom: ROLLBACK_PRESERVE is not respected

parent 23236e0f
......@@ -330,11 +330,14 @@ public function rollback() {
foreach ($id_map as $map_row) {
$destination_key = $id_map->currentDestination();
if ($destination_key) {
$this->getEventDispatcher()
->dispatch(MigrateEvents::PRE_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
$destination->rollback($destination_key);
$this->getEventDispatcher()
->dispatch(MigrateEvents::POST_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
$map_row = $id_map->getRowByDestination($destination_key);
if ($map_row['rollback_action'] == MigrateIdMapInterface::ROLLBACK_DELETE) {
$this->getEventDispatcher()
->dispatch(MigrateEvents::PRE_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
$destination->rollback($destination_key);
$this->getEventDispatcher()
->dispatch(MigrateEvents::POST_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
}
// We're now done with this row, so remove it from the map.
$id_map->deleteDestination($destination_key);
}
......
......@@ -9,6 +9,8 @@
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Row;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -112,6 +114,12 @@ public function testRollback() {
// Import and validate term entities were created.
$term_executable = new MigrateExecutable($term_migration, $this);
$term_executable->import();
// Mark one row to be preserved on rollback.
$preserved_term_id = 2;
$map_row = $term_id_map->getRowBySource(['id' => $preserved_term_id]);
$dummy_row = new Row(['id' => $preserved_term_id], $ids);
$term_id_map->saveIdMapping($dummy_row, [$map_row['destid1']],
$map_row['source_row_status'], MigrateIdMapInterface::ROLLBACK_PRESERVE);
foreach ($term_data_rows as $row) {
/** @var Term $term */
$term = Term::load($row['id']);
......@@ -124,7 +132,12 @@ public function testRollback() {
$term_executable->rollback();
foreach ($term_data_rows as $row) {
$term = Term::load($row['id']);
$this->assertNull($term);
if ($row['id'] == $preserved_term_id) {
$this->assertNotNull($term);
}
else {
$this->assertNull($term);
}
$map_row = $term_id_map->getRowBySource(['id' => $row['id']]);
$this->assertFalse($map_row);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment