diff --git a/core/modules/aggregator/src/Tests/Migrate/MigrateAggregatorStubTest.php b/core/modules/aggregator/src/Tests/Migrate/MigrateAggregatorStubTest.php index d620259..32f4670 100644 --- a/core/modules/aggregator/src/Tests/Migrate/MigrateAggregatorStubTest.php +++ b/core/modules/aggregator/src/Tests/Migrate/MigrateAggregatorStubTest.php @@ -42,6 +42,13 @@ public function testFeedStub() { } /** + * Tests suppression of aggregator feed stubs. + */ + public function testNoFeedStub() { + $this->performStubTest('aggregator_feed', TRUE); + } + + /** * Tests creation of aggregator feed items. */ public function testItemStub() { @@ -60,4 +67,11 @@ public function testItemStub() { $this->performStubTest('aggregator_item'); } + /** + * Tests suppression of aggregator item stubs. + */ + public function testNoItemStub() { + $this->performStubTest('aggregator_item', TRUE); + } + } diff --git a/core/modules/block_content/src/Tests/Migrate/MigrateBlockContentStubTest.php b/core/modules/block_content/src/Tests/Migrate/MigrateBlockContentStubTest.php index 1971a9d..e6913bc 100644 --- a/core/modules/block_content/src/Tests/Migrate/MigrateBlockContentStubTest.php +++ b/core/modules/block_content/src/Tests/Migrate/MigrateBlockContentStubTest.php @@ -57,4 +57,11 @@ public function testStubSuccess() { $this->performStubTest('block_content'); } + /** + * Tests suppression of block content stubs. + */ + public function testNoStub() { + $this->performStubTest('block_content', TRUE); + } + } diff --git a/core/modules/comment/src/Tests/Migrate/MigrateCommentStubTest.php b/core/modules/comment/src/Tests/Migrate/MigrateCommentStubTest.php index 22818f5..7ee8d0c 100644 --- a/core/modules/comment/src/Tests/Migrate/MigrateCommentStubTest.php +++ b/core/modules/comment/src/Tests/Migrate/MigrateCommentStubTest.php @@ -75,4 +75,11 @@ public function testStub() { $this->performStubTest('comment'); } + /** + * Tests suppression of comment stubs. + */ + public function testNoStub() { + $this->performStubTest('comment', TRUE); + } + } diff --git a/core/modules/file/src/Tests/Migrate/MigrateFileStubTest.php b/core/modules/file/src/Tests/Migrate/MigrateFileStubTest.php index ae7446c..bab728b 100644 --- a/core/modules/file/src/Tests/Migrate/MigrateFileStubTest.php +++ b/core/modules/file/src/Tests/Migrate/MigrateFileStubTest.php @@ -39,4 +39,11 @@ public function testStub() { $this->performStubTest('file'); } + /** + * Tests suppression of file stubs. + */ + public function testNoStub() { + $this->performStubTest('file', TRUE); + } + } diff --git a/core/modules/menu_link_content/src/Tests/Migrate/MigrateMenuLinkContentStubTest.php b/core/modules/menu_link_content/src/Tests/Migrate/MigrateMenuLinkContentStubTest.php index 47e94d1..995b346 100644 --- a/core/modules/menu_link_content/src/Tests/Migrate/MigrateMenuLinkContentStubTest.php +++ b/core/modules/menu_link_content/src/Tests/Migrate/MigrateMenuLinkContentStubTest.php @@ -39,4 +39,11 @@ public function testStub() { $this->performStubTest('menu_link_content'); } + /** + * Tests suppression of menu link content stubs. + */ + public function testNoStub() { + $this->performStubTest('menu_link_content', TRUE); + } + } diff --git a/core/modules/migrate/config/schema/migrate.data_types.schema.yml b/core/modules/migrate/config/schema/migrate.data_types.schema.yml index 60dd519..02bd699 100644 --- a/core/modules/migrate/config/schema/migrate.data_types.schema.yml +++ b/core/modules/migrate/config/schema/migrate.data_types.schema.yml @@ -17,6 +17,10 @@ migrate_destination: sequence: type: string label: 'Property' + no_stub: + type: boolean + label: 'Whether stubbing is allowed.' + default: false migrate_source: type: migrate_plugin diff --git a/core/modules/migrate/config/schema/migrate.destination.schema.yml b/core/modules/migrate/config/schema/migrate.destination.schema.yml index b295741..65f5bdb 100644 --- a/core/modules/migrate/config/schema/migrate.destination.schema.yml +++ b/core/modules/migrate/config/schema/migrate.destination.schema.yml @@ -3,11 +3,6 @@ migrate.destination.*: type: migrate_destination label: 'Default destination' - mapping: - no_stub: - type: boolean - label: 'Whether stubbing is allowed.' - default: false migrate.destination.config: type: migrate_destination diff --git a/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Entity/Migration.php index 094713d..d305635 100644 --- a/core/modules/migrate/src/Entity/Migration.php +++ b/core/modules/migrate/src/Entity/Migration.php @@ -10,7 +10,6 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\MigrateException; -use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\RequirementsInterface; use Drupal\Component\Utility\NestedArray; @@ -319,11 +318,8 @@ protected function getProcessNormalized(array $process) { /** * {@inheritdoc} */ - public function getDestinationPlugin($stub_being_requested = FALSE) { + public function getDestinationPlugin() { if (!isset($this->destinationPlugin)) { - if ($stub_being_requested && !empty($this->destination['no_stub'])) { - throw new MigrateSkipRowException; - } $this->destinationPlugin = \Drupal::service('plugin.manager.migrate.destination')->createInstance($this->destination['plugin'], $this->destination, $this); } return $this->destinationPlugin; diff --git a/core/modules/migrate/src/Entity/MigrationInterface.php b/core/modules/migrate/src/Entity/MigrationInterface.php index a07c0ea..e5ff0e9 100644 --- a/core/modules/migrate/src/Entity/MigrationInterface.php +++ b/core/modules/migrate/src/Entity/MigrationInterface.php @@ -128,7 +128,7 @@ public function getProcessPlugins(array $process = NULL); * @return \Drupal\migrate\Plugin\MigrateDestinationInterface * The destination plugin. */ - public function getDestinationPlugin($stub_being_requested = FALSE); + public function getDestinationPlugin(); /** * Returns the initialized id_map plugin. diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index ff7b258..8f002c6 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -88,6 +88,9 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { + if ($row->isStub() && !empty($this->configuration['no_stub'])) { + return []; + } $this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE; $entity = $this->getEntity($row, $old_destination_id_values); if (!$entity) { diff --git a/core/modules/migrate/src/Plugin/migrate/process/Migration.php b/core/modules/migrate/src/Plugin/migrate/process/Migration.php index a60e773..1b24a83 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Migration.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Migration.php @@ -111,7 +111,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable else { $migration = reset($migrations); } - $destination_plugin = $migration->getDestinationPlugin(TRUE); + $destination_plugin = $migration->getDestinationPlugin(); // Only keep the process necessary to produce the destination ID. $process = $migration->get('process'); diff --git a/core/modules/migrate_drupal/src/Tests/StubTestTrait.php b/core/modules/migrate_drupal/src/Tests/StubTestTrait.php index 1e028bf..d976594 100644 --- a/core/modules/migrate_drupal/src/Tests/StubTestTrait.php +++ b/core/modules/migrate_drupal/src/Tests/StubTestTrait.php @@ -7,6 +7,8 @@ namespace Drupal\migrate_drupal\Tests; use Drupal\migrate\Entity\Migration; +use Drupal\migrate\MigrateSkipProcessException; +use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\Row; /** @@ -20,18 +22,26 @@ * * @param string $entity_type_id * The entity type we are stubbing. + * @param boolean $no_stub + * TRUE to prevent stub creation. */ - protected function performStubTest($entity_type_id) { - $entity_id = $this->createStub($entity_type_id); - $this->assertTrue($entity_id, 'Stub successfully created'); - if ($entity_id) { - $violations = $this->validateStub($entity_type_id, $entity_id); - if (!$this->assertIdentical(count($violations), 0, 'Stub is a valid entity')) { - foreach ($violations as $violation) { - $this->fail((string) $violation->getMessage()); + protected function performStubTest($entity_type_id, $no_stub = FALSE) { + $entity_id = $this->createStub($entity_type_id, $no_stub); + if ($no_stub) { + $this->assertFalse($entity_id, 'Stub creation suppressed'); + } + else { + $this->assertTrue($entity_id, 'Stub successfully created'); + if ($entity_id) { + $violations = $this->validateStub($entity_type_id, $entity_id); + if (!$this->assertIdentical(count($violations), 0, 'Stub is a valid entity')) { + foreach ($violations as $violation) { + $this->fail((string) $violation->getMessage()); + } } } } + } /** @@ -39,11 +49,13 @@ protected function performStubTest($entity_type_id) { * * @param string $entity_type_id * The entity type we are stubbing. + * @param boolean $no_stub + * TRUE to prevent stub creation. * * @return int * ID of the created entity. */ - protected function createStub($entity_type_id) { + protected function createStub($entity_type_id, $no_stub = FALSE) { // Create a dummy migration to pass to the destination plugin. $config = [ 'id' => 'dummy', @@ -52,8 +64,11 @@ protected function createStub($entity_type_id) { 'process' => [], 'destination' => ['plugin' => 'entity:' . $entity_type_id], ]; + if ($no_stub) { + $config['destination']['no_stub'] = TRUE; + } $migration = Migration::create($config); - $destination_plugin = $migration->getDestinationPlugin(TRUE); + $destination_plugin = $migration->getDestinationPlugin(); $stub_row = new Row([], [], TRUE); $destination_ids = $destination_plugin->import($stub_row); return reset($destination_ids); diff --git a/core/modules/node/src/Tests/Migrate/MigrateNodeStubTest.php b/core/modules/node/src/Tests/Migrate/MigrateNodeStubTest.php index 22d140b..8127942 100644 --- a/core/modules/node/src/Tests/Migrate/MigrateNodeStubTest.php +++ b/core/modules/node/src/Tests/Migrate/MigrateNodeStubTest.php @@ -45,4 +45,11 @@ public function testStub() { $this->performStubTest('node'); } + /** + * Tests suppression of node stubs. + */ + public function testNoStub() { + $this->performStubTest('node', TRUE); + } + } diff --git a/core/modules/shortcut/src/Tests/Migrate/MigrateShortcutStubTest.php b/core/modules/shortcut/src/Tests/Migrate/MigrateShortcutStubTest.php index ba9a000..15a4c78 100644 --- a/core/modules/shortcut/src/Tests/Migrate/MigrateShortcutStubTest.php +++ b/core/modules/shortcut/src/Tests/Migrate/MigrateShortcutStubTest.php @@ -41,4 +41,11 @@ public function testStub() { $this->performStubTest('shortcut'); } + /** + * Tests suppression of shortcut stubs. + */ + public function testNoStub() { + $this->performStubTest('shortcut', TRUE); + } + } diff --git a/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php b/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php index a7cd9ca..2ddefba 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php @@ -48,6 +48,13 @@ public function testStub() { } /** + * Tests suppression of taxonomy term stubs. + */ + public function testNoStub() { + $this->performStubTest('taxonomy_term', TRUE); + } + + /** * Tests creation of stubs when weight is mapped. */ public function testStubWithWeightMapping() { diff --git a/core/modules/user/migration_templates/d6_user_picture_file.yml b/core/modules/user/migration_templates/d6_user_picture_file.yml index e4d572a..c1497ee 100644 --- a/core/modules/user/migration_templates/d6_user_picture_file.yml +++ b/core/modules/user/migration_templates/d6_user_picture_file.yml @@ -19,6 +19,7 @@ process: destination: plugin: entity:file source_path_property: picture + no_stub: true migration_dependencies: # Every migration that saves into {file_managed} must have the d6_file # migration as an optional dependency to ensure it runs first. diff --git a/core/modules/user/src/Tests/Migrate/MigrateUserStubTest.php b/core/modules/user/src/Tests/Migrate/MigrateUserStubTest.php index 0a65ddf..318ea16 100644 --- a/core/modules/user/src/Tests/Migrate/MigrateUserStubTest.php +++ b/core/modules/user/src/Tests/Migrate/MigrateUserStubTest.php @@ -40,4 +40,11 @@ public function testStub() { $this->performStubTest('user'); } + /** + * Tests suppression of user stubs. + */ + public function testNoStub() { + $this->performStubTest('user', TRUE); + } + }