Unverified Commit c0e98be4 authored by alexpott's avatar alexpott
Browse files

Issue #3123095 by quietone, Neslee Canil Pinto, benjifisher, mikelutz, catch:...

Issue #3123095 by quietone, Neslee Canil Pinto, benjifisher, mikelutz, catch: Rollback of complete node migration fails

(cherry picked from commit 704745bc)
parent 0946a51c
......@@ -4,7 +4,9 @@
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\migrate\EntityFieldDefinitionTrait;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Row;
/**
......@@ -104,6 +106,18 @@ protected function getEntity(Row $row, array $old_destination_id_values) {
return $entity;
}
/**
* {@inheritdoc}
*/
protected function updateEntity(EntityInterface $entity, Row $row) {
$entity = parent::updateEntity($entity, $row);
// Always set the rollback action to delete. This is because the parent
// updateEntity will set the rollback action to preserve for the original
// language row, which is needed for the classic node migrations.
$this->setRollbackAction($row->getIdMap(), MigrateIdMapInterface::ROLLBACK_DELETE);
return $entity;
}
/**
* {@inheritdoc}
*/
......@@ -115,4 +129,14 @@ protected function save(ContentEntityInterface $entity, array $old_destination_i
];
}
/**
* {@inheritdoc}
*/
public function rollback(array $destination_identifier) {
// We want to delete the entity and all the translations so use
// Entity:rollback because EntityContentBase::rollback will not remove the
// default translation.
Entity::rollback($destination_identifier);
}
}
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Kernel\Migrate\d7;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\NodeMigrateType;
use Drupal\node\NodeInterface;
use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait;
......@@ -126,6 +127,34 @@ public function testNodeCompleteMigration() {
}
}
/**
* Tests rollback of the complete node migration.
*/
public function testRollbackNodeComplete() {
$db = \Drupal::database();
$node_types = [
'article',
'blog',
'book',
'forum',
'page',
'test_content_type',
];
foreach ($node_types as $node_type) {
// Execute the rollback.
$this->migration = $this->getMigration("d7_node_complete:$node_type");
(new MigrateExecutable($this->migration, $this))->rollback();
// Assert there are no nodes of node_type.
$count = $db->select('node_field_data')
->condition('type', $node_type)
->countQuery()
->execute()
->fetchField();
$this->assertSame($count, '0', "There are $count nodes of type $node_type");
}
}
/**
* Asserts various aspects of a node revision.
*
......
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