Skip to content
Snippets Groups Projects
Unverified Commit 704745bc authored by Alex Pott's avatar Alex Pott
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
parent 75d67d4c
No related branches found
No related tags found
8 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards,!16Draft: Resolve #2081585 "History storage",!13Resolve #2903456
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\migrate\EntityFieldDefinitionTrait; use Drupal\migrate\EntityFieldDefinitionTrait;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Row; use Drupal\migrate\Row;
/** /**
...@@ -104,6 +106,18 @@ protected function getEntity(Row $row, array $old_destination_id_values) { ...@@ -104,6 +106,18 @@ protected function getEntity(Row $row, array $old_destination_id_values) {
return $entity; 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} * {@inheritdoc}
*/ */
...@@ -115,4 +129,14 @@ protected function save(ContentEntityInterface $entity, array $old_destination_i ...@@ -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 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Kernel\Migrate\d7; namespace Drupal\Tests\node\Kernel\Migrate\d7;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\NodeMigrateType; use Drupal\migrate_drupal\NodeMigrateType;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait; use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait;
...@@ -126,6 +127,34 @@ public function testNodeCompleteMigration() { ...@@ -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. * Asserts various aspects of a node revision.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment