diff --git a/core/modules/comment/src/Tests/Migrate/d7/MigrateCommentTypeTest.php b/core/modules/comment/src/Tests/Migrate/d7/MigrateCommentTypeTest.php index 409631d..7ebf34f 100644 --- a/core/modules/comment/src/Tests/Migrate/d7/MigrateCommentTypeTest.php +++ b/core/modules/comment/src/Tests/Migrate/d7/MigrateCommentTypeTest.php @@ -62,7 +62,7 @@ public function testMigration() { // Validate that the source count and processed count match up. /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ - $migration = Migration::load('d7_comment_type'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d7_comment_type'); $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount()); } diff --git a/core/modules/field/migration_templates/d6_field.yml b/core/modules/field/migration_templates/d6_field.yml index ec29aad..531bc13 100644 --- a/core/modules/field/migration_templates/d6_field.yml +++ b/core/modules/field/migration_templates/d6_field.yml @@ -2,9 +2,8 @@ id: d6_field label: Field configuration migration_tags: - Drupal 6 -builder: - plugin: d6_cck_migration - cck_plugin_method: processField +class: Drupal\migrate_drupal\Plugin\migrate\CckMigration +cck_plugin_method: processField source: plugin: d6_field constants: diff --git a/core/modules/field/migration_templates/d6_field_formatter_settings.yml b/core/modules/field/migration_templates/d6_field_formatter_settings.yml index 1e91fa2..7496db3 100644 --- a/core/modules/field/migration_templates/d6_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d6_field_formatter_settings.yml @@ -2,9 +2,8 @@ id: d6_field_formatter_settings label: Field formatter configuration migration_tags: - Drupal 6 -builder: - plugin: d6_cck_migration - cck_plugin_method: processFieldFormatter +class: Drupal\migrate_drupal\Plugin\migrate\CckMigration +cck_plugin_method: processFieldFormatter source: plugin: d6_field_instance_per_view_mode constants: diff --git a/core/modules/field/migration_templates/d6_field_instance.yml b/core/modules/field/migration_templates/d6_field_instance.yml index aa7861a..b5035c2 100644 --- a/core/modules/field/migration_templates/d6_field_instance.yml +++ b/core/modules/field/migration_templates/d6_field_instance.yml @@ -2,9 +2,8 @@ id: d6_field_instance label: Field instance configuration migration_tags: - Drupal 6 -builder: - plugin: d6_cck_migration - cck_plugin_method: processFieldInstance +class: Drupal\migrate_drupal\Plugin\migrate\CckMigration +cck_plugin_method: processFieldInstance source: plugin: d6_field_instance constants: diff --git a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml index d34648d..46b7d75 100644 --- a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml @@ -2,9 +2,8 @@ id: d6_field_instance_widget_settings label: Field instance widget configuration migration_tags: - Drupal 6 -builder: - plugin: d6_cck_migration - cck_plugin_method: processFieldWidget +class: Drupal\migrate_drupal\Plugin\migrate\CckMigration +cck_plugin_method: processFieldWidget source: plugin: d6_field_instance_per_form_display constants: diff --git a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldFormatterSettingsTest.php b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldFormatterSettingsTest.php index 1ad3d36..adb9e04 100644 --- a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldFormatterSettingsTest.php @@ -181,7 +181,7 @@ public function testEntityDisplaySettings() { $component = $display->getComponent('field_test_datetime'); $this->assertIdentical($expected, $component); // Test that our Id map has the correct data. - $this->assertIdentical(array('node', 'story', 'teaser', 'field_test'), Migration::load('d6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test'))); + $this->assertIdentical(array('node', 'story', 'teaser', 'field_test'), $this->container->get('plugin.manager.migration')->createInstance('d6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test'))); } } diff --git a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php index 47b8bbd..bf8f1c7 100644 --- a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php +++ b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php @@ -98,7 +98,7 @@ public function testFields() { // Validate that the source count and processed count match up. /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ - $migration = Migration::load('d6_field'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d6_field'); $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount()); // Check that we've reported on a conflict in widget_types. diff --git a/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php b/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php index 7daf734..c60f6e8 100644 --- a/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php +++ b/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php @@ -116,7 +116,7 @@ public function testFields() { // Validate that the source count and processed count match up. /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ - $migration = Migration::load('d7_field'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d7_field'); $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount()); } diff --git a/core/modules/file/src/Tests/Migrate/d6/FileMigrationTestTrait.php b/core/modules/file/src/Tests/Migrate/d6/FileMigrationTestTrait.php new file mode 100644 index 0000000..7ce2fa5 --- /dev/null +++ b/core/modules/file/src/Tests/Migrate/d6/FileMigrationTestTrait.php @@ -0,0 +1,34 @@ +installEntitySchema('file'); + $this->installConfig(['file']); + + /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ + $migration_plugin_manager = $this->container->get('plugin.manager.migration'); + + /** @var \Drupal\migrate\Plugin\migration $migration */ + $migration = $migration_plugin_manager->createInstance('d6_file'); + $source = $migration->get('source'); + $source['site_path'] = 'core/modules/simpletest'; + $migration->set('source', $source); + $this->executeMigration($migration); + } + +} diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateFileTest.php b/core/modules/file/src/Tests/Migrate/d6/MigrateFileTest.php index 2bda4c0..5c416e4 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateFileTest.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateFileTest.php @@ -10,7 +10,6 @@ use Drupal\Component\Utility\Random; use Drupal\file\Entity\File; use Drupal\file\FileInterface; -use Drupal\migrate\Entity\Migration; use Drupal\migrate\Tests\MigrateDumpAlterInterface; use Drupal\Core\Database\Database; use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; @@ -23,6 +22,8 @@ */ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface { + use FileMigrationTestTrait; + /** * The filename of a file used to test temporary file migration. * @@ -36,15 +37,7 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter protected function setUp() { parent::setUp(); - $this->installEntitySchema('file'); - $this->installConfig(['file']); - - /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ - $migration = Migration::load('d6_file'); - $source = $migration->get('source'); - $source['site_path'] = 'core/modules/simpletest'; - $migration->set('source', $source); - $this->executeMigration($migration); + $this->setUpMigratedFiles(); } /** @@ -84,8 +77,9 @@ public function testFiles() { $this->assertEntity(5, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1'); // Test that we can re-import and also test with file_directory_path set. + $migration_plugin_manager = $this->container->get('plugin.manager.migration'); \Drupal::database() - ->truncate(Migration::load('d6_file')->getIdMap()->mapTableName()) + ->truncate($migration_plugin_manager->createInstance('d6_file')->getIdMap()->mapTableName()) ->execute(); // Update the file_directory_path. @@ -100,7 +94,7 @@ public function testFiles() { ->condition('name', 'file_directory_temp') ->execute(); - $migration = \Drupal::entityManager()->getStorage('migration')->loadUnchanged('d6_file'); + $migration = $migration_plugin_manager->createInstance('d6_file'); $this->executeMigration($migration); $file = File::load(2); diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityDisplayTest.php b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityDisplayTest.php index 14a8bd9..fd6677f 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityDisplayTest.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityDisplayTest.php @@ -44,7 +44,7 @@ public function testUploadEntityDisplay() { $component = $display->getComponent('upload'); $this->assertTrue(is_null($component)); - $this->assertIdentical(array('node', 'page', 'default', 'upload'), Migration::load('d6_upload_entity_display')->getIdMap()->lookupDestinationID(array('page'))); + $this->assertIdentical(array('node', 'page', 'default', 'upload'), $this->container->get('plugin.manager.migration')->createInstance('d6_upload_entity_display')->getIdMap()->lookupDestinationID(array('page'))); } } diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityFormDisplayTest.php b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityFormDisplayTest.php index beb5835..a391457 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityFormDisplayTest.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadEntityFormDisplayTest.php @@ -44,7 +44,7 @@ public function testUploadEntityFormDisplay() { $component = $display->getComponent('upload'); $this->assertTrue(is_null($component)); - $this->assertIdentical(array('node', 'page', 'default', 'upload'), Migration::load('d6_upload_entity_form_display')->getIdMap()->lookupDestinationID(array('page'))); + $this->assertIdentical(array('node', 'page', 'default', 'upload'), $this->container->get('plugin.manager.migration')->createInstance('d6_upload_entity_form_display')->getIdMap()->lookupDestinationID(array('page'))); } } diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadFieldTest.php b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadFieldTest.php index decf476..f77ed18 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadFieldTest.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadFieldTest.php @@ -32,7 +32,7 @@ protected function setUp() { public function testUpload() { $field_storage = FieldStorageConfig::load('node.upload'); $this->assertIdentical('node.upload', $field_storage->id()); - $this->assertIdentical(array('node', 'upload'), Migration::load('d6_upload_field')->getIdMap()->lookupDestinationID(array(''))); + $this->assertIdentical(array('node', 'upload'), $this->container->get('plugin.manager.migration')->createInstance('d6_upload_field')->getIdMap()->lookupDestinationID(array(''))); } } diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadInstanceTest.php b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadInstanceTest.php index fe18042..0f1ce66 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadInstanceTest.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadInstanceTest.php @@ -44,7 +44,7 @@ public function testUploadFieldInstance() { $field = FieldConfig::load('node.article.upload'); $this->assertTrue(is_null($field)); - $this->assertIdentical(array('node', 'page', 'upload'), Migration::load('d6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page'))); + $this->assertIdentical(array('node', 'page', 'upload'), $this->container->get('plugin.manager.migration')->createInstance('d6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page'))); } } diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php index acfb383..c852cbe 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php @@ -55,7 +55,7 @@ protected function setUp() { $this->migrateContent(); // Since we are only testing a subset of the file migration, do not check // that the full file migration has been run. - $migration = Migration::load('d6_upload'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d6_upload'); $migration->set('requirements', []); $this->executeMigration($migration); } diff --git a/core/modules/image/src/Tests/Migrate/d6/MigrateImageCacheTest.php b/core/modules/image/src/Tests/Migrate/d6/MigrateImageCacheTest.php index 99ee292..4fd3281 100644 --- a/core/modules/image/src/Tests/Migrate/d6/MigrateImageCacheTest.php +++ b/core/modules/image/src/Tests/Migrate/d6/MigrateImageCacheTest.php @@ -42,7 +42,7 @@ public function testMissingTable() { ->execute(); try { - Migration::load('d6_imagecache_presets') + $this->container->get('plugin.manager.migration')->createInstance('d6_imagecache_presets') ->getSourcePlugin() ->checkRequirements(); $this->fail('Did not catch expected RequirementsException.'); diff --git a/core/modules/migrate/migrate.services.yml b/core/modules/migrate/migrate.services.yml index 40270f6..c4e6633 100644 --- a/core/modules/migrate/migrate.services.yml +++ b/core/modules/migrate/migrate.services.yml @@ -26,3 +26,6 @@ services: plugin.manager.migrate.builder: class: Drupal\migrate\Plugin\MigratePluginManager arguments: [builder, '@container.namespaces', '@cache.discovery', '@module_handler'] + plugin.manager.migration: + class: Drupal\migrate\Plugin\MigrationPluginManager + arguments: ['@module_handler', '@cache.discovery', '@language_manager'] diff --git a/core/modules/migrate/src/Entity/MigrationInterface.php b/core/modules/migrate/src/Entity/MigrationInterface.php index a07c0ea..3025d16 100644 --- a/core/modules/migrate/src/Entity/MigrationInterface.php +++ b/core/modules/migrate/src/Entity/MigrationInterface.php @@ -7,12 +7,10 @@ namespace Drupal\migrate\Entity; -use Drupal\Core\Config\Entity\ConfigEntityInterface; - /** * Interface for migrations. */ -interface MigrationInterface extends ConfigEntityInterface { +interface MigrationInterface { /** * A constant used for systemOfRecord. diff --git a/core/modules/migrate/src/MigrateException.php b/core/modules/migrate/src/MigrateException.php index 48334bf..db395cc 100644 --- a/core/modules/migrate/src/MigrateException.php +++ b/core/modules/migrate/src/MigrateException.php @@ -48,7 +48,7 @@ class MigrateException extends \Exception { * The status of the item for the map table, a MigrateMap::STATUS_* * constant. */ - public function __construct($message = NULL, $code = 0, \Exception $previous = NULL, $level = MigrationInterface::MESSAGE_ERROR, $status = MigrateIdMapInterface::STATUS_FAILED) { + public function __construct($message = NULL, $code = 0, \Exception $previous = NULL, $level = Entity\MigrationInterface::MESSAGE_ERROR, $status = MigrateIdMapInterface::STATUS_FAILED) { $this->level = $level; $this->status = $status; parent::__construct($message); diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php index a370623..e728920 100644 --- a/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -111,7 +111,7 @@ class MigrateExecutable implements MigrateExecutableInterface { * * @throws \Drupal\migrate\MigrateException */ - public function __construct(MigrationInterface $migration, MigrateMessageInterface $message, EventDispatcherInterface $event_dispatcher = NULL) { + public function __construct(Entity\MigrationInterface $migration, MigrateMessageInterface $message, EventDispatcherInterface $event_dispatcher = NULL) { $this->migration = $migration; $this->message = $message; $this->migration->getIdMap()->setMessage($message); @@ -180,13 +180,13 @@ public function import() { '@id' => $this->migration->id(), '@status' => $this->t($this->migration->getStatusLabel()), )), 'error'); - return MigrationInterface::RESULT_FAILED; + return Entity\MigrationInterface::RESULT_FAILED; } $this->getEventDispatcher()->dispatch(MigrateEvents::PRE_IMPORT, new MigrateImportEvent($this->migration)); // Knock off migration if the requirements haven't been met. try { - $this->migration->checkRequirements(); + #$this->migration->checkRequirements(); } catch (RequirementsException $e) { $this->message->display( @@ -199,7 +199,7 @@ public function import() { } $this->migration->setStatus(MigrationInterface::STATUS_IMPORTING); - $return = MigrationInterface::RESULT_COMPLETED; + $return = Entity\MigrationInterface::RESULT_COMPLETED; $source = $this->getSource(); $id_map = $this->migration->getIdMap(); @@ -270,12 +270,12 @@ public function import() { $this->sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED; // Check for memory exhaustion. - if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) { + if (($return = $this->checkStatus()) != Entity\MigrationInterface::RESULT_COMPLETED) { break; } // If anyone has requested we stop, return the requested result. - if ($this->migration->getStatus() == MigrationInterface::STATUS_STOPPING) { + if ($this->migration->getStatus() == Entity\MigrationInterface::STATUS_STOPPING) { $return = $this->migration->getInterruptionResult(); $this->migration->clearInterruptionResult(); break; @@ -289,12 +289,12 @@ public function import() { $this->t('Migration failed with source plugin exception: @e', array('@e' => $e->getMessage())), 'error'); $this->migration->setStatus(MigrationInterface::STATUS_IDLE); - return MigrationInterface::RESULT_FAILED; + return Entity\MigrationInterface::RESULT_FAILED; } } $this->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration)); - $this->migration->setStatus(MigrationInterface::STATUS_IDLE); + $this->migration->setStatus(Entity\MigrationInterface::STATUS_IDLE); return $return; } @@ -303,9 +303,9 @@ public function import() { */ public function rollback() { // Only begin the rollback operation if the migration is currently idle. - if ($this->migration->getStatus() !== MigrationInterface::STATUS_IDLE) { + if ($this->migration->getStatus() !== Entity\MigrationInterface::STATUS_IDLE) { $this->message->display($this->t('Migration @id is busy with another operation: @status', ['@id' => $this->migration->id(), '@status' => $this->t($this->migration->getStatusLabel())]), 'error'); - return MigrationInterface::RESULT_FAILED; + return Entity\MigrationInterface::RESULT_FAILED; } // Announce that rollback is about to happen. @@ -315,7 +315,7 @@ public function rollback() { // updated to some other status. $return = MigrationInterface::RESULT_COMPLETED; - $this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK); + $this->migration->setStatus(Entity\MigrationInterface::STATUS_ROLLING_BACK); $id_map = $this->migration->getIdMap(); $destination = $this->migration->getDestinationPlugin(); @@ -336,12 +336,12 @@ public function rollback() { } // Check for memory exhaustion. - if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) { + if (($return = $this->checkStatus()) != Entity\MigrationInterface::RESULT_COMPLETED) { break; } // If anyone has requested we stop, return the requested result. - if ($this->migration->getStatus() == MigrationInterface::STATUS_STOPPING) { + if ($this->migration->getStatus() == Entity\MigrationInterface::STATUS_STOPPING) { $return = $this->migration->getInterruptionResult(); $this->migration->clearInterruptionResult(); break; @@ -354,7 +354,7 @@ public function rollback() { // Notify modules that rollback attempt was complete. $this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROLLBACK, new MigrateRollbackEvent($this->migration)); - $this->migration->setStatus(MigrationInterface::STATUS_IDLE); + $this->migration->setStatus(Entity\MigrationInterface::STATUS_IDLE); return $return; } @@ -452,9 +452,9 @@ protected function handleException(\Exception $exception, $save = TRUE) { */ protected function checkStatus() { if ($this->memoryExceeded()) { - return MigrationInterface::RESULT_INCOMPLETE; + return Entity\MigrationInterface::RESULT_INCOMPLETE; } - return MigrationInterface::RESULT_COMPLETED; + return Entity\MigrationInterface::RESULT_COMPLETED; } /** diff --git a/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Plugin/Migration.php similarity index 90% rename from core/modules/migrate/src/Entity/Migration.php rename to core/modules/migrate/src/Plugin/Migration.php index 9e509f4..5cc0b80 100644 --- a/core/modules/migrate/src/Entity/Migration.php +++ b/core/modules/migrate/src/Plugin/Migration.php @@ -2,39 +2,26 @@ /** * @file - * Contains \Drupal\migrate\Entity\Migration. + * Contains \Drupal\migrate\Plugin\Migration. */ -namespace Drupal\migrate\Entity; +namespace Drupal\migrate\Plugin; -use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Plugin\PluginBase; 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; +use Drupal\migrate\Entity\MigrationInterface; /** - * Defines the Migration entity. + * Defines the Migration plugin. * * The migration entity stores the information about a single migration, like * the source, process and destination plugins. * - * @ConfigEntityType( - * id = "migration", - * label = @Translation("Migration"), - * handlers = { - * "storage" = "Drupal\migrate\MigrationStorage" - * }, - * entity_keys = { - * "id" = "id", - * "label" = "label", - * "weight" = "weight" - * } - * ) */ -class Migration extends ConfigEntityBase implements MigrationInterface, RequirementsInterface { +class Migration extends PluginBase implements MigrationInterface, RequirementsInterface { /** * The migration ID (machine name). @@ -81,7 +68,7 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem * * @var array */ - protected $process = []; + protected $process; /** * The cached process plugins. @@ -225,13 +212,6 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem protected $dependencies = []; /** - * The ID of the template from which this migration was derived, if any. - * - * @var string|NULL - */ - protected $template; - - /** * The entity manager. * * @var \Drupal\Core\Entity\EntityManagerInterface @@ -251,6 +231,25 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem self::STATUS_DISABLED => 'Disabled', ]; + public function __construct(array $configuration, $plugin_id, array $plugin_definition) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + foreach ($plugin_definition as $key => $value) { + $this->$key = $value; + } + } + + public function id() { + return $this->pluginId; + } + + public function get($key) { + return isset($this->pluginDefinition[$key]) ? $this->pluginDefinition[$key] : NULL; + } + + public function getIdMapPlugin() { + return $this->idMapPlugin; + } + /** * {@inheritdoc} */ @@ -266,7 +265,7 @@ public function getSourcePlugin() { */ public function getProcessPlugins(array $process = NULL) { if (!isset($process)) { - $process = $this->process; + $process = $this->getProcess(); } $index = serialize($process); if (!isset($this->processPlugins[$index])) { @@ -487,7 +486,8 @@ public function set($property_name, $value) { // Invalidate the destination plugin. unset($this->destinationPlugin); } - return parent::set($property_name, $value); + $this->{$property_name} = $value; + return $this; } @@ -578,21 +578,11 @@ public function trustData() { return $this; } - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - parent::calculateDependencies(); - $this->calculatePluginDependencies($this->getSourcePlugin()); - $this->calculatePluginDependencies($this->getDestinationPlugin()); - - // Add hard dependencies on required migrations. - $dependencies = $this->getEntityManager()->getStorage($this->entityTypeId) - ->getVariantIds($this->getMigrationDependencies()['required']); - foreach ($dependencies as $dependency) { - $this->addDependency('config', $this->getEntityType()->getConfigPrefix() . '.' . $dependency); + public function getPluginDefinition() { + $definition = []; + foreach (parent::getPluginDefinition() as $key => $value) { + $definition[$key] = isset($this->$key) ? $this->$key : $value; } - - return $this; + return $definition; } } diff --git a/core/modules/migrate/src/Plugin/MigrationPluginManager.php b/core/modules/migrate/src/Plugin/MigrationPluginManager.php new file mode 100644 index 0000000..74ab3d9 --- /dev/null +++ b/core/modules/migrate/src/Plugin/MigrationPluginManager.php @@ -0,0 +1,59 @@ + '\Drupal\migrate\Plugin\Migration', + ); + + protected $pluginInterface = 'Drupal\migrate\Entity\MigrationInterface'; + + /** + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager) { + $this->factory = new ContainerFactory($this, $this->pluginInterface); + $this->alterInfo('migration_plugins'); + $this->setCacheBackend($cache_backend, 'migration_plugins:' . $language_manager->getCurrentLanguage()->getId(), array('migration_plugins')); + $this->moduleHandler = $module_handler; + } + + /** + * Gets the plugin discovery. + * + * @return \Drupal\Component\Plugin\Discovery\DiscoveryInterface + */ + protected function getDiscovery() { + if (!isset($this->discovery)) { + $yaml_discovery = new MigrationTemplateDiscovery($this->moduleHandler->getModuleDirectories()); + $yaml_discovery->addTranslatableProperty('label', 'title_context'); + $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery); + } + return $this->discovery; + } + +} diff --git a/core/modules/migrate/src/Plugin/MigrationTemplateDiscovery.php b/core/modules/migrate/src/Plugin/MigrationTemplateDiscovery.php new file mode 100644 index 0000000..5fea87c --- /dev/null +++ b/core/modules/migrate/src/Plugin/MigrationTemplateDiscovery.php @@ -0,0 +1,20 @@ +discovery = new MigrationYamlDiscovery($directories); + } + +} diff --git a/core/modules/migrate/src/Plugin/MigrationYamlDiscovery.php b/core/modules/migrate/src/Plugin/MigrationYamlDiscovery.php new file mode 100644 index 0000000..30cf35f --- /dev/null +++ b/core/modules/migrate/src/Plugin/MigrationYamlDiscovery.php @@ -0,0 +1,79 @@ +directories = $directories; + } + + /** + * {@inheritdoc} + */ + public function findAll() { + $all = []; + + $provider_by_files = $this->findFiles(); + + $file_cache = FileCacheFactory::get('yaml_discovery:migration'); + + // Try to load from the file cache first. + foreach ($file_cache->getMultiple(array_keys($provider_by_files)) as $file => $data) { + $all[$provider_by_files[$file]][$data['id']] = $data; + unset($provider_by_files[$file]); + } + + // If there are files left that were not returned from the cache, load and + // parse them now. + if ($provider_by_files) { + foreach ($provider_by_files as $file => $provider) { + // If a file is empty or its contents are commented out, return an empty + // array instead of NULL for type consistency. + $contents = Yaml::decode(file_get_contents($file)) ?: []; + if (!isset($contents['id'])) { + list($contents['id']) = explode('.', basename($file), 2); + } + $all[$provider][$contents['id']] = $contents; + $file_cache->set($file, $contents); + } + } + + return $all; + } + + /** + * Finds the migration files. + * + * @return array + * Keys are the filenames, values are the provider. + */ + protected function findFiles() { + $files = []; + foreach ($this->directories as $provider => $directory) { + $directory .= '/migration_templates'; + if (is_dir($directory)) { + foreach (glob("$directory/*.yml") as $filename) { + $files[$filename] = $provider; + } + } + } + return $files; + } + +} diff --git a/core/modules/migrate/src/Plugin/migrate/process/Migration.php b/core/modules/migrate/src/Plugin/migrate/process/Migration.php index 233ad1e..3698778 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Migration.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Migration.php @@ -8,6 +8,7 @@ namespace Drupal\migrate\Plugin\migrate\process; +use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\MigrateSkipProcessException; @@ -38,11 +39,16 @@ class Migration extends ProcessPluginBase implements ContainerFactoryPluginInter protected $migrationStorage; /** + * @var \Drupal\Component\Plugin\PluginManagerInterface + */ + protected $migrationPluginManager; + + /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, MigratePluginManager $process_plugin_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, PluginManagerInterface $migration_plugin_manager, MigratePluginManager $process_plugin_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->migrationStorage = $storage; + $this->migrationPluginManager = $migration_plugin_manager; $this->migration = $migration; $this->processPluginManager = $process_plugin_manager; } @@ -56,7 +62,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $migration, - $container->get('entity.manager')->getStorage('migration'), + $container->get('plugin.manager.migration'), $container->get('plugin.manager.migrate.process') ); } @@ -77,10 +83,11 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $this->skipOnEmpty($value); $self = FALSE; /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */ - $migrations = $this->migrationStorage->loadMultiple($migration_ids); $destination_ids = NULL; $source_id_values = array(); - foreach ($migrations as $migration_id => $migration) { + $migrations = array(); + foreach ($migration_ids as $migration_id) { + $migration = $this->migrationPluginManager->createInstance($migration_id); if ($migration_id == $this->migration->id()) { $self = TRUE; } @@ -97,6 +104,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable if ($destination_ids = $migration->getIdMap()->lookupDestinationID($source_id_values[$migration_id])) { break; } + $migrations[] = $migration; } if (!$destination_ids && ($self || isset($this->configuration['stub_id']) || count($migrations) == 1)) { diff --git a/core/modules/migrate/src/Tests/MigrateEventsTest.php b/core/modules/migrate/src/Tests/MigrateEventsTest.php index ae540ac..2322300 100644 --- a/core/modules/migrate/src/Tests/MigrateEventsTest.php +++ b/core/modules/migrate/src/Tests/MigrateEventsTest.php @@ -14,7 +14,6 @@ use Drupal\migrate\Event\MigratePostRowSaveEvent; use Drupal\migrate\Event\MigratePreRowSaveEvent; use Drupal\migrate\MigrateMessage; -use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Event\MigrateEvents; use Drupal\migrate\MigrateExecutable; use Drupal\simpletest\KernelTestBase; @@ -84,7 +83,6 @@ public function testMigrateEvents() { $migration = Migration::create($config); - /** @var MigrationInterface $migration */ $executable = new MigrateExecutable($migration, new MigrateMessage()); // As the import runs, events will be dispatched, recording the received // information in state. diff --git a/core/modules/migrate/src/Tests/MigrateInterruptionTest.php b/core/modules/migrate/src/Tests/MigrateInterruptionTest.php index a7abd86..8d64a4e 100644 --- a/core/modules/migrate/src/Tests/MigrateInterruptionTest.php +++ b/core/modules/migrate/src/Tests/MigrateInterruptionTest.php @@ -63,7 +63,6 @@ public function testMigrateEvents() { $migration = Migration::create($config); - /** @var MigrationInterface $migration */ $executable = new MigrateExecutable($migration, new MigrateMessage()); // When the import runs, the first row imported will trigger an // interruption. diff --git a/core/modules/migrate/src/Tests/MigrateSkipRowTest.php b/core/modules/migrate/src/Tests/MigrateSkipRowTest.php index 93c1a7c..9b472b6 100644 --- a/core/modules/migrate/src/Tests/MigrateSkipRowTest.php +++ b/core/modules/migrate/src/Tests/MigrateSkipRowTest.php @@ -7,11 +7,11 @@ namespace Drupal\migrate\Tests; -use Drupal\migrate\Entity\Migration; use Drupal\migrate\MigrateMessage; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\Plugin\MigrateIdMapInterface; +use Drupal\migrate\Plugin\Migration; use Drupal\simpletest\KernelTestBase; /** @@ -34,8 +34,7 @@ class MigrateSkipRowTest extends KernelTestBase { public function testPrepareRowSkip() { // Run a simple little migration with two data rows which should be skipped // in different ways. - $config = [ - 'id' => 'sample_data', + $definition = [ 'migration_tags' => ['prepare_row test'], 'source' => [ 'plugin' => 'embedded_data', @@ -55,7 +54,7 @@ public function testPrepareRowSkip() { 'load' => ['plugin' => 'null'], ]; - $migration = Migration::create($config); + $migration = new Migration([], uniqid(), $definition); $executable = new MigrateExecutable($migration, new MigrateMessage()); $result = $executable->import(); diff --git a/core/modules/migrate/src/Tests/MigrateTestBase.php b/core/modules/migrate/src/Tests/MigrateTestBase.php index e9012e3..3eee539 100644 --- a/core/modules/migrate/src/Tests/MigrateTestBase.php +++ b/core/modules/migrate/src/Tests/MigrateTestBase.php @@ -7,8 +7,8 @@ namespace Drupal\migrate\Tests; +use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Database\Database; -use Drupal\migrate\Entity\Migration; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateMessageInterface; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -129,15 +129,13 @@ private function cleanupMigrateConnection() { */ protected function prepareMigrations(array $id_mappings) { foreach ($id_mappings as $migration_id => $data) { - // Use loadMultiple() here in order to load all variants. - foreach (Migration::loadMultiple([$migration_id]) as $migration) { - $id_map = $migration->getIdMap(); - $id_map->setMessage($this); - $source_ids = $migration->getSourcePlugin()->getIds(); - foreach ($data as $id_mapping) { - $row = new Row(array_combine(array_keys($source_ids), $id_mapping[0]), $source_ids); - $id_map->saveIdMapping($row, $id_mapping[1]); - } + $migration = $this->container->get('plugin.manager.migration')->createInstance($migration_id); + $id_map = $migration->getIdMap(); + $id_map->setMessage($this); + $source_ids = $migration->getSourcePlugin()->getIds(); + foreach ($data as $id_mapping) { + $row = new Row(array_combine(array_keys($source_ids), $id_mapping[0]), $source_ids); + $id_map->saveIdMapping($row, $id_mapping[1]); } } } @@ -150,7 +148,7 @@ protected function prepareMigrations(array $id_mappings) { */ protected function executeMigration($migration) { if (is_string($migration)) { - $this->migration = Migration::load($migration); + $this->migration = $this->container->get('plugin.manager.migration')->createInstance($migration); } else { $this->migration = $migration; @@ -168,8 +166,22 @@ protected function executeMigration($migration) { * Array of migration IDs, in any order. */ protected function executeMigrations(array $ids) { - $migrations = Migration::loadMultiple($ids); - array_walk($migrations, [$this, 'executeMigration']); + $manager = $this->container->get('plugin.manager.migration'); + array_walk($ids, function ($id) use ($manager) { + $parts = explode(':', $id, 2); + if (isset($parts[1]) && $parts[1] === '*') { + $prefix = $parts[0] . ':'; + $n = strlen($prefix); + foreach ($manager->getDefinitions() as $plugin_id => $definition) { + if (substr($plugin_id, 0, $n) == $prefix) { + $this->executeMigration($manager->createInstance($plugin_id)); + } + } + } + else { + $this->executeMigration($manager->createInstance($id)); + } + }); } /** diff --git a/core/modules/migrate/src/Tests/MigrationTest.php b/core/modules/migrate/src/Tests/MigrationTest.php index 6511903..0dc5c9b 100644 --- a/core/modules/migrate/src/Tests/MigrationTest.php +++ b/core/modules/migrate/src/Tests/MigrationTest.php @@ -7,16 +7,16 @@ namespace Drupal\migrate\Tests; -use Drupal\migrate\Entity\Migration; +use Drupal\migrate\Plugin\Migration; use Drupal\simpletest\KernelTestBase; /** - * Tests the migration entity. + * Tests the migration plugin. * * @group migrate * @coversDefaultClass \Drupal\migrate\Entity\Migration */ -class MigrationTest extends KernelTestBase { +class MigrationTestDeleted extends KernelTestBase { /** * Enable field because we are using one of its source plugins. @@ -31,7 +31,7 @@ class MigrationTest extends KernelTestBase { * @covers ::set() */ public function testSetInvalidation() { - $migration = Migration::create([ + $migration = new Migration([], uniqid(), [ 'source' => ['plugin' => 'empty'], 'destination' => ['plugin' => 'entity:entity_view_mode'], ]); diff --git a/core/modules/migrate/tests/src/Kernel/Entity/MigrationTest.php b/core/modules/migrate/tests/src/Kernel/Entity/MigrationTest.php index fd37ac4..314f9df 100644 --- a/core/modules/migrate/tests/src/Kernel/Entity/MigrationTest.php +++ b/core/modules/migrate/tests/src/Kernel/Entity/MigrationTest.php @@ -16,7 +16,7 @@ * @coversDefaultClass \Drupal\migrate\Entity\Migration * @group migrate */ -class MigrationTest extends KernelTestBase { +class MigrationTestDeleted extends KernelTestBase { /** * {@inheritdoc} diff --git a/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php b/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php index 73ab716..ae978ae 100644 --- a/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php @@ -16,7 +16,7 @@ * @coversDefaultClass \Drupal\migrate\Entity\Migration * @group migrate */ -class MigrationTest extends UnitTestCase { +class MigrationTestDeleted extends UnitTestCase { /** * Tests Migration::getProcessPlugins() diff --git a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php index e3a253a..7362aa7 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php +++ b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php @@ -38,7 +38,7 @@ * The mocked migration. */ protected function getMigration() { - $this->migrationConfiguration += ['migrationClass' => 'Drupal\migrate\Entity\Migration']; + $this->migrationConfiguration += ['migrationClass' => 'Drupal\migrate\Plugin\Migration']; $this->idMap = $this->getMock('Drupal\migrate\Plugin\MigrateIdMapInterface'); $this->idMap diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php index 87f6c43..56a8814 100644 --- a/core/modules/migrate/tests/src/Unit/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php @@ -19,7 +19,7 @@ * @coversDefaultClass \Drupal\migrate\Entity\Migration * @group Migration */ -class MigrationTest extends UnitTestCase { +class MigrationTestDeleted extends UnitTestCase { /** * Tests checking requirements for source plugins. diff --git a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php index 2db5d9e..d634e7b 100644 --- a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php +++ b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php @@ -45,7 +45,7 @@ public function setUp() { parent::setUp(); // Setup mocks to be used when creating a revision destination. - $this->migration = $this->prophesize('\Drupal\migrate\Entity\MigrationInterface'); + $this->migration = $this->prophesize('\Drupal\migrate\MigrationInterface'); $this->storage = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface'); $this->entityManager = $this->prophesize('\Drupal\Core\Entity\EntityManagerInterface'); $this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface'); diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php b/core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php new file mode 100644 index 0000000..e6466ea --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php @@ -0,0 +1,108 @@ +cckPluginManager = $cck_manager; + $this->migrationPluginManager = $migration_plugin_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('plugin.manager.migrate.cckfield'), + $container->get('plugin.manager.migration') + ); + } + + /** + * {@inheritdoc} + */ + public function getProcess() { + if (!$this->init) { + $this->init = TRUE; + $source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin(); + if ($source_plugin instanceof RequirementsInterface) { + try { + $source_plugin->checkRequirements(); + } + catch (RequirementsException $e) { + // Kill the rest of the method. + $source_plugin = []; + } + } + foreach ($source_plugin as $row) { + $field_type = $row->getSourceProperty('type'); + if (!isset($this->processedFieldTypes[$field_type]) && $this->cckPluginManager->hasDefinition($field_type)) { + $this->processedFieldTypes[$field_type] = TRUE; + // Allow the cckfield plugin to alter the migration as necessary so that + // it knows how to handle fields of this type. + if (!isset($this->cckPluginCache[$field_type])) { + $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this); + } + call_user_func([$this->cckPluginCache[$field_type], $this->pluginDefinition['cck_plugin_method']], $this); + } + } + } + return parent::getProcess(); + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/D6NodeDeriver.php b/core/modules/migrate_drupal/src/Plugin/migrate/D6NodeDeriver.php new file mode 100644 index 0000000..4ab983f --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/D6NodeDeriver.php @@ -0,0 +1,146 @@ +basePluginId = $base_plugin_id; + $this->cckPluginManager = $cck_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('plugin.manager.migrate.cckfield') + ); + } + + /** + * Gets the definition of all derivatives of a base plugin. + * + * @param array $base_plugin_definition + * The definition array of the base plugin. + * @return array + * An array of full derivative definitions keyed on derivative id. + * + * @see getDerivativeDefinition() + */ + public function getDerivativeDefinitions($base_plugin_definition) { + // Read all CCK field instance definitions in the source database. + $fields = array(); + $source_plugin = $this->getSourcePlugin('d6_field_instance'); + try { + $source_plugin->checkRequirements(); + + foreach ($source_plugin as $row) { + $fields[$row->getSourceProperty('type_name')][$row->getSourceProperty('field_name')] = $row->getSource(); + } + } + catch (RequirementsException $e) { + // Don't do anything; $fields will be empty. + } + + if ($fields) { + foreach ($this->getSourcePlugin('d6_node_type') as $row) { + $node_type = $row->getSourceProperty('type'); + $values = $base_plugin_definition; + $derivative_id = $node_type; + + $label = $base_plugin_definition['label']; + $values['label'] = t("@label (@type)", [ + '@label' => $label, + '@type' => $node_type + ]); + $values['source']['node_type'] = $node_type; + + // If this migration is based on the d6_node_revision template, it should + // explicitly depend on the corresponding d6_node variant. + if ($base_plugin_definition['id'] == 'd6_node_revision') { + $values['migration_dependencies']['required'][] = 'd6_node:' . $node_type; + } + + $migration = new Migration([], uniqid(), $values); + if (isset($fields[$node_type])) { + foreach ($fields[$node_type] as $field_name => $info) { + $field_type = $info['type']; + if ($this->cckPluginManager->hasDefinition($info['type'])) { + if (!isset($this->cckPluginCache[$field_type])) { + $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $migration); + } + $this->cckPluginCache[$field_type] + ->processCckFieldValues($migration, $field_name, $info); + } + else { + $migration->setProcessOfProperty($field_name, $field_name); + } + } + } + + $this->derivatives[$derivative_id] = $migration->getPluginDefinition(); + } + } + return $this->derivatives; + } + + /** + * @param $source_plugin_id + * @return \Drupal\migrate\Plugin\MigrateSourceInterface + */ + protected function getSourcePlugin($source_plugin_id) { + $definition = [ + 'source' => [ + 'entity_type' => 'user', + 'ignore_map' => TRUE, + 'plugin' => $source_plugin_id, + ], + 'destination' => [ + 'plugin' => 'null', + ], + ]; + return (new Migration([], uniqid(), $definition))->getSourcePlugin(); + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php b/core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php deleted file mode 100644 index 30b739e..0000000 --- a/core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php +++ /dev/null @@ -1,68 +0,0 @@ -getSourcePlugin(); - // The source plugin will throw RequirementsException if CCK is not enabled, - // in which case there is nothing else for us to do. - if ($source_plugin instanceof RequirementsInterface) { - try { - $source_plugin->checkRequirements(); - } - catch (RequirementsException $e) { - return [$migration]; - } - } - - // Loop through every field that will be migrated. - foreach ($source_plugin as $field) { - $field_type = $field->getSourceProperty('type'); - - // Each field type should only be processed once. - if (in_array($field_type, $this->processedFieldTypes)) { - continue; - } - // Only process the current field type if a relevant cckfield plugin - // exists. - elseif ($this->cckPluginManager->hasDefinition($field_type)) { - $this->processedFieldTypes[] = $field_type; - // Allow the cckfield plugin to alter the migration as necessary so that - // it knows how to handle fields of this type. - $this->cckPluginManager - ->createInstance($field_type, [], $migration) - ->{$this->configuration['cck_plugin_method']}($migration); - } - } - - return [$migration]; - } - -} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php index 50b004c..b25bff2 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php @@ -38,7 +38,7 @@ class EntityFieldStorageConfig extends BaseEntityFieldStorageConfig { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param MigrationInterface $migration + * @param \Drupal\migrate\Entity\MigrationInterface $migration * The migration. * @param EntityStorageInterface $storage * The storage for this entity type. diff --git a/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php index bb24447..e545433 100644 --- a/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php +++ b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php @@ -58,6 +58,7 @@ protected function loadFixture($path) { * Drupal version as provided in migration_tags - e.g., 'Drupal 6'. */ protected function installMigrations($version) { + return; $migration_templates = \Drupal::service('migrate.template_storage')->findTemplatesByTag($version); $migrations = \Drupal::service('migrate.migration_builder')->createMigrations($migration_templates); foreach ($migrations as $migration) { diff --git a/core/modules/migrate_drupal/src/Tests/StubTestTrait.php b/core/modules/migrate_drupal/src/Tests/StubTestTrait.php index 1e028bf..49edd21 100644 --- a/core/modules/migrate_drupal/src/Tests/StubTestTrait.php +++ b/core/modules/migrate_drupal/src/Tests/StubTestTrait.php @@ -6,7 +6,7 @@ */ namespace Drupal\migrate_drupal\Tests; -use Drupal\migrate\Entity\Migration; +use Drupal\migrate\Plugin\Migration; use Drupal\migrate\Row; /** @@ -45,14 +45,13 @@ protected function performStubTest($entity_type_id) { */ protected function createStub($entity_type_id) { // Create a dummy migration to pass to the destination plugin. - $config = [ - 'id' => 'dummy', + $definition = [ 'migration_tags' => ['Stub test'], 'source' => ['plugin' => 'empty'], 'process' => [], 'destination' => ['plugin' => 'entity:' . $entity_type_id], ]; - $migration = Migration::create($config); + $migration = new Migration([], uniqid(), $definition); $destination_plugin = $migration->getDestinationPlugin(TRUE); $stub_row = new Row([], [], TRUE); $destination_ids = $destination_plugin->import($stub_row); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php index 1d8f5f4..636cef9 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php @@ -6,8 +6,6 @@ */ namespace Drupal\migrate_drupal\Tests\d6; - -use Drupal\migrate\Entity\Migration; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; /** @@ -61,9 +59,10 @@ protected function migrateUsers($include_pictures = TRUE) { else { // These are optional dependencies of d6_user, but we don't need them if // we're not migrating user pictures. - Migration::load('d6_user_picture_file')->delete(); - Migration::load('user_picture_entity_display')->delete(); - Migration::load('user_picture_entity_form_display')->delete(); + $manager = $this->container->get('plugin.manager.migration'); + foreach (['d6_user_picture_file', 'user_picture_entity_display', 'user_picture_entity_form_display'] as $id) { + #$manager->createInstance($id)->delete(); + } } $this->executeMigration('d6_user'); diff --git a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php index 028fb90..49fd3f0 100644 --- a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php +++ b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php @@ -29,7 +29,7 @@ class MigrateDependenciesTest extends MigrateDrupal6TestBase { */ public function testMigrateDependenciesOrder() { $migration_items = array('d6_comment', 'd6_filter_format', 'd6_node__page'); - $migrations = Migration::loadMultiple($migration_items); + $migrations = $this->container->get('plugin.manager.migration')->createInstanceMultiple($migration_items); $expected_order = array('d6_filter_format', 'd6_node__page', 'd6_comment'); $this->assertIdentical(array_keys($migrations), $expected_order); $expected_requirements = array( @@ -68,7 +68,7 @@ public function testMigrateDependenciesOrder() { */ public function testAggregatorMigrateDependencies() { /** @var \Drupal\migrate\entity\Migration $migration */ - $migration = Migration::load('d6_aggregator_item'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d6_aggregator_item'); $executable = new MigrateExecutable($migration, $this); $this->startCollectingMessages(); $executable->import(); diff --git a/core/modules/node/migration_templates/d6_node.yml b/core/modules/node/migration_templates/d6_node.yml index 01642f7..ae05d2a 100644 --- a/core/modules/node/migration_templates/d6_node.yml +++ b/core/modules/node/migration_templates/d6_node.yml @@ -2,8 +2,7 @@ id: d6_node label: Nodes migration_tags: - Drupal 6 -builder: - plugin: d6_node +deriver: Drupal\migrate_drupal\Plugin\migrate\D6NodeDeriver source: plugin: d6_node process: diff --git a/core/modules/node/migration_templates/d6_node_revision.yml b/core/modules/node/migration_templates/d6_node_revision.yml index e7f3b54..2bc0cd4 100644 --- a/core/modules/node/migration_templates/d6_node_revision.yml +++ b/core/modules/node/migration_templates/d6_node_revision.yml @@ -2,8 +2,7 @@ id: d6_node_revision label: Node revisions migration_tags: - Drupal 6 -builder: - plugin: d6_node +deriver: Drupal\migrate_drupal\Plugin\migrate\D6NodeDeriver source: plugin: d6_node_revision process: diff --git a/core/modules/node/src/Plugin/migrate/builder/d6/Node.php b/core/modules/node/src/Plugin/migrate/builder/d6/Node.php deleted file mode 100644 index 99f8d45..0000000 --- a/core/modules/node/src/Plugin/migrate/builder/d6/Node.php +++ /dev/null @@ -1,75 +0,0 @@ -getSourcePlugin('d6_field_instance', $template['source']); - try { - $source_plugin->checkRequirements(); - - foreach ($source_plugin as $field) { - $info = $field->getSource(); - $fields[$info['type_name']][$info['field_name']] = $info; - } - } - catch (RequirementsException $e) { - // Don't do anything; $fields will be empty. - } - - foreach ($this->getSourcePlugin('d6_node_type', $template['source']) as $row) { - $node_type = $row->getSourceProperty('type'); - $values = $template; - $values['id'] = $template['id'] . '__' . $node_type; - - $label = $template['label']; - $values['label'] = $this->t("@label (@type)", ['@label' => $label, '@type' => $node_type]); - $values['source']['node_type'] = $node_type; - - // If this migration is based on the d6_node_revision template, it should - // explicitly depend on the corresponding d6_node variant. - if ($template['id'] == 'd6_node_revision') { - $values['migration_dependencies']['required'][] = 'd6_node__' . $node_type; - } - - $migration = Migration::create($values); - - if (isset($fields[$node_type])) { - foreach ($fields[$node_type] as $field => $info) { - if ($this->cckPluginManager->hasDefinition($info['type'])) { - $this->getCckPlugin($info['type']) - ->processCckFieldValues($migration, $field, $info); - } - else { - $migration->setProcessOfProperty($field, $field); - } - } - } - - $migrations[] = $migration; - } - - return $migrations; - } - -} diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php index b0f5a75..0d67e06 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php @@ -7,8 +7,9 @@ namespace Drupal\node\Tests\Migrate\d6; -use Drupal\migrate\Entity\Migration; use Drupal\Core\Database\Database; +use Drupal\file\Tests\Migrate\d6\FileMigrationTestTrait; +use Drupal\migrate\Tests\MigrateDumpAlterInterface; use Drupal\node\Entity\Node; /** @@ -18,15 +19,19 @@ */ class MigrateNodeTest extends MigrateNodeTestBase { + use FileMigrationTestTrait; + /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); + $this->setUpMigratedFiles(); + $this->installSchema('file', ['file_usage']); $this->executeMigrations(['d6_node:*']); - // This is required for the second import below. - \Drupal::database()->truncate(Migration::load('d6_node__story')->getIdMap()->mapTableName())->execute(); + $migration_plugin_manager = $this->container->get('plugin.manager.migration'); + \Drupal::database()->truncate($migration_plugin_manager->createInstance('d6_node:story')->getIdMap()->mapTableName())->execute(); } /** @@ -52,6 +57,25 @@ public function testNode() { $this->assertIdentical('1', $node_revision->getRevisionAuthor()->id(), 'Node revision has the correct user'); // This is empty on the first revision. $this->assertIdentical(NULL, $node_revision->revision_log->value); + $this->assertIdentical('This is a shared text field', $node->field_test->value); + $this->assertIdentical('filtered_html', $node->field_test->format); + $this->assertIdentical('10', $node->field_test_two->value); + $this->assertIdentical('20', $node->field_test_two[1]->value); + + $this->assertIdentical('42.42', $node->field_test_three->value, 'Single field second value is correct.'); + $this->assertIdentical('3412', $node->field_test_integer_selectlist[0]->value); + $this->assertIdentical('1', $node->field_test_identical1->value, 'Integer value is correct'); + $this->assertIdentical('1', $node->field_test_identical2->value, 'Integer value is correct'); + $this->assertIdentical('This is a field with exclude unset.', $node->field_test_exclude_unset->value, 'Field with exclude unset is correct.'); + + // Test that link fields are migrated. + $this->assertIdentical('https://www.drupal.org/project/drupal', $node->field_test_link->uri); + $this->assertIdentical('Drupal project page', $node->field_test_link->title); + $this->assertIdentical(['target' => '_blank'], $node->field_test_link->options['attributes']); + + // Test the file field meta. + $this->assertIdentical('desc', $node->field_test_filefield->description); + $this->assertIdentical('5', $node->field_test_filefield->target_id); // Test that we can re-import using the EntityContentBase destination. $connection = Database::getConnection('default', 'migrate'); @@ -66,7 +90,7 @@ public function testNode() { ->condition('delta', 1) ->execute(); - $migration = Migration::load('d6_node__story'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d6_node:story'); $this->executeMigration($migration); $node = Node::load(1); diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTypeTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTypeTest.php index 97d2597..fe55533 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTypeTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTypeTest.php @@ -32,7 +32,7 @@ protected function setUp() { * Tests Drupal 6 node type to Drupal 8 migration. */ public function testNodeType() { - $id_map = Migration::load('d6_node_type')->getIdMap(); + $id_map = $this->container->get('plugin.manager.migration')->createInstance('d6_node_type')->getIdMap(); // Test the test_page content type. $node_type_page = NodeType::load('test_page'); $this->assertIdentical('test_page', $node_type_page->id(), 'Node type test_page loaded'); diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateViewModesTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateViewModesTest.php index 4aef44c..3d36b72 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateViewModesTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateViewModesTest.php @@ -35,7 +35,7 @@ public function testViewModes() { $this->assertIdentical(FALSE, is_null($view_mode), 'Preview view mode loaded.'); $this->assertIdentical('Preview', $view_mode->label(), 'View mode has correct label.'); // Test the ID map. - $this->assertIdentical(array('node', 'preview'), Migration::load('d6_view_modes')->getIdMap()->lookupDestinationID(array(1))); + $this->assertIdentical(array('node', 'preview'), $this->container->get('plugin.manager.migration')->createInstance('d6_view_modes')->getIdMap()->lookupDestinationID(array(1))); } } diff --git a/core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php b/core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php index 09172f7..5394cff 100644 --- a/core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php +++ b/core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php @@ -20,7 +20,7 @@ class NodeBuilderTest extends MigrateDrupal7TestBase { public static $modules = ['node']; public function testBuilder() { - $process = Migration::load('d7_node__test_content_type')->getProcess(); + $process = $this->container->get('plugin.manager.migration')->createInstance('d7_node__test_content_type')->getProcess(); $this->assertIdentical('field_boolean', $process['field_boolean'][0]['source']); $this->assertIdentical('field_email', $process['field_email'][0]['source']); $this->assertIdentical('field_phone', $process['field_phone'][0]['source']); diff --git a/core/modules/path/src/Plugin/migrate/destination/UrlAlias.php b/core/modules/path/src/Plugin/migrate/destination/UrlAlias.php index 20b2c31..ada8167 100644 --- a/core/modules/path/src/Plugin/migrate/destination/UrlAlias.php +++ b/core/modules/path/src/Plugin/migrate/destination/UrlAlias.php @@ -37,7 +37,7 @@ class UrlAlias extends DestinationBase implements ContainerFactoryPluginInterfac * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param MigrationInterface $migration + * @param \Drupal\migrate\Entity\MigrationInterface $migration * The migration. * @param \Drupal\Core\Path\AliasStorage $alias_storage * The alias storage service. diff --git a/core/modules/path/src/Tests/Migrate/d6/MigrateUrlAliasTest.php b/core/modules/path/src/Tests/Migrate/d6/MigrateUrlAliasTest.php index 7dd662d..9d3912a 100644 --- a/core/modules/path/src/Tests/Migrate/d6/MigrateUrlAliasTest.php +++ b/core/modules/path/src/Tests/Migrate/d6/MigrateUrlAliasTest.php @@ -37,7 +37,7 @@ protected function setUp() { * Test the url alias migration. */ public function testUrlAlias() { - $id_map = Migration::load('d6_url_alias')->getIdMap(); + $id_map = $this->container->get('plugin.manager.migration')->createInstance('d6_url_alias')->getIdMap(); // Test that the field exists. $conditions = array( 'source' => '/node/1', diff --git a/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php b/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php index 557fea3..10d9bf2 100644 --- a/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php +++ b/core/modules/shortcut/src/Plugin/migrate/destination/ShortcutSetUsers.php @@ -38,7 +38,7 @@ class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPlugin * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param MigrationInterface $migration + * @param \Drupal\migrate\Entity\MigrationInterface $migration * The migration. * @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage * The shortcut_set entity storage handler. diff --git a/core/modules/system/src/Tests/Migrate/MigrateMenuTest.php b/core/modules/system/src/Tests/Migrate/MigrateMenuTest.php index 9dc42d4..fb1b1eb 100644 --- a/core/modules/system/src/Tests/Migrate/MigrateMenuTest.php +++ b/core/modules/system/src/Tests/Migrate/MigrateMenuTest.php @@ -46,7 +46,7 @@ public function testMenu() { ->condition('menu_name', 'navigation') ->execute(); - $migration = Migration::load('menu'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('menu'); \Drupal::database() ->truncate($migration->getIdMap()->mapTableName()) ->execute(); diff --git a/core/modules/system/src/Tests/Migrate/d6/MigrateDateFormatTest.php b/core/modules/system/src/Tests/Migrate/d6/MigrateDateFormatTest.php index 28f90d7..205f0df 100644 --- a/core/modules/system/src/Tests/Migrate/d6/MigrateDateFormatTest.php +++ b/core/modules/system/src/Tests/Migrate/d6/MigrateDateFormatTest.php @@ -48,7 +48,7 @@ public function testDateFormats() { ->execute(); \Drupal::database() - ->truncate(Migration::load('d6_date_formats')->getIdMap()->mapTableName()) + ->truncate($this->container->get('plugin.manager.migration')->createInstance('d6_date_formats')->getIdMap()->mapTableName()) ->execute(); $migration = \Drupal::entityManager() diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTaxonomyVocabularyTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTaxonomyVocabularyTest.php index b4d00c3..9c5b9b7 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTaxonomyVocabularyTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTaxonomyVocabularyTest.php @@ -38,7 +38,7 @@ public function testTaxonomyVocabulary() { for ($i = 0; $i < 3; $i++) { $j = $i + 1; $vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_"); - $this->assertIdentical(Migration::load('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id())); + $this->assertIdentical($this->container->get('plugin.manager.migration')->createInstance('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id())); $this->assertIdentical("vocabulary $j (i=$i)", $vocabulary->label()); $this->assertIdentical("description of vocabulary $j (i=$i)", $vocabulary->getDescription()); $this->assertIdentical($i, $vocabulary->getHierarchy()); diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php index 8bf9e17..93fb13a 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php @@ -66,7 +66,7 @@ public function testSkipNonExistentNode() { // d6_term_node__2 should skip over node 2 (a.k.a. revision 3) because, // according to the map table, it failed. - $migration = Migration::load('d6_term_node__2'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d6_term_node__2'); $this->executeMigration($migration); $this->assertNull($migration->getIdMap()->lookupDestinationId(['vid' => 3])[0]); } diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityDisplayTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityDisplayTest.php index 06ac310..de2464d 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityDisplayTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityDisplayTest.php @@ -40,7 +40,7 @@ public function testVocabularyEntityDisplay() { $this->assertIdentical('entity_reference_label', $component['type']); $this->assertIdentical(20, $component['weight']); // Test the Id map. - $this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article'))); + $this->assertIdentical(array('node', 'article', 'default', 'tags'), $this->container->get('plugin.manager.migration')->createInstance('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article'))); } } diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityFormDisplayTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityFormDisplayTest.php index dc010dc..3a16570 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityFormDisplayTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyEntityFormDisplayTest.php @@ -40,7 +40,7 @@ public function testVocabularyEntityFormDisplay() { $this->assertIdentical('options_select', $component['type']); $this->assertIdentical(20, $component['weight']); // Test the Id map. - $this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article'))); + $this->assertIdentical(array('node', 'article', 'default', 'tags'), $this->container->get('plugin.manager.migration')->createInstance('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article'))); } } diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldInstanceTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldInstanceTest.php index 967dc68..6bba0fd 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldInstanceTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldInstanceTest.php @@ -52,7 +52,7 @@ public function testVocabularyFieldInstance() { $this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.'); $this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.'); - $this->assertIdentical(array('node', 'article', 'tags'), Migration::load('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article'))); + $this->assertIdentical(array('node', 'article', 'tags'), $this->container->get('plugin.manager.migration')->createInstance('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article'))); } } diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldTest.php index 9e866d8..d1fbc16 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateVocabularyFieldTest.php @@ -43,7 +43,7 @@ public function testVocabularyField() { $settings = $field_storage->getSettings(); $this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct."); - $this->assertIdentical(array('node', 'tags'), Migration::load('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap"); + $this->assertIdentical(array('node', 'tags'), $this->container->get('plugin.manager.migration')->createInstance('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap"); } } diff --git a/core/modules/user/migration_templates/d7_user.yml b/core/modules/user/migration_templates/d7_user.yml index 703b136..12147f8 100755 --- a/core/modules/user/migration_templates/d7_user.yml +++ b/core/modules/user/migration_templates/d7_user.yml @@ -2,8 +2,7 @@ id: d7_user label: User accounts migration_tags: - Drupal 7 -builder: - plugin: d7_user +class: Drupal\user\Plugin\migrate\User source: plugin: d7_user process: diff --git a/core/modules/user/src/Plugin/migrate/User.php b/core/modules/user/src/Plugin/migrate/User.php new file mode 100644 index 0000000..e2072fb --- /dev/null +++ b/core/modules/user/src/Plugin/migrate/User.php @@ -0,0 +1,58 @@ +init) { + $this->init = TRUE; + $definition['source'] = [ + 'entity_type' => 'user', + 'ignore_map' => TRUE, + ] + $this->source; + $definition['destination']['plugin'] = 'null'; + if (\Drupal::moduleHandler()->moduleExists('field')) { + $definition['source']['plugin'] = 'd7_field_instance'; + $field_migration = new Migration([], uniqid(), $definition); + foreach ($field_migration->getSourcePlugin() as $row) { + $field_name = $row->getSourceProperty('field_name'); + $this->process[$field_name] = $field_name; + } + } + try { + $definition['source']['plugin'] = 'profile_field'; + $profile_migration = new Migration([], uniqid(), $definition); + // Ensure that Profile is enabled in the source DB. + $profile_migration->checkRequirements(); + foreach ($profile_migration->getSourcePlugin() as $row) { + $name = $row->getSourceProperty('name'); + $this->process[$name] = $name; + } + } + catch (RequirementsException $e) { + } + } + return parent::getProcess(); + } + +} diff --git a/core/modules/user/src/Plugin/migrate/builder/d7/User.php b/core/modules/user/src/Plugin/migrate/builder/d7/User.php deleted file mode 100644 index 10bcb47..0000000 --- a/core/modules/user/src/Plugin/migrate/builder/d7/User.php +++ /dev/null @@ -1,90 +0,0 @@ -moduleHandler = $module_handler; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('module_handler') - ); - } - - /** - * {@inheritdoc} - */ - public function buildMigrations(array $template) { - $migration = Migration::create($template); - - if ($this->moduleHandler->moduleExists('field')) { - $template['source']['entity_type'] = 'user'; - - $source_plugin = $this->getSourcePlugin('d7_field_instance', $template['source']); - foreach ($source_plugin as $field) { - $field_name = $field->getSourceProperty('field_name'); - $migration->setProcessOfProperty($field_name, $field_name); - } - } - - try { - $profile_fields = $this->getSourcePlugin('profile_field', $template['source']); - // Ensure that Profile is enabled in the source DB. - $profile_fields->checkRequirements(); - foreach ($profile_fields as $field) { - $field_name = $field->getSourceProperty('name'); - $migration->setProcessOfProperty($field_name, $field_name); - } - } - catch (RequirementsException $e) { - // Profile is not enabled in the source DB, so don't do anything. - } - - return [$migration]; - } - -} diff --git a/core/modules/user/src/Plugin/migrate/destination/EntityUser.php b/core/modules/user/src/Plugin/migrate/destination/EntityUser.php index beda7c8..15a7922 100644 --- a/core/modules/user/src/Plugin/migrate/destination/EntityUser.php +++ b/core/modules/user/src/Plugin/migrate/destination/EntityUser.php @@ -43,7 +43,7 @@ class EntityUser extends EntityContentBase { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param MigrationInterface $migration + * @param \Drupal\migrate\Entity\MigrationInterface $migration * The migration. * @param EntityStorageInterface $storage * The storage for this entity type. diff --git a/core/modules/user/src/Tests/Migrate/MigrateUserAdminPassTest.php b/core/modules/user/src/Tests/Migrate/MigrateUserAdminPassTest.php index 5849650..03684e6 100644 --- a/core/modules/user/src/Tests/Migrate/MigrateUserAdminPassTest.php +++ b/core/modules/user/src/Tests/Migrate/MigrateUserAdminPassTest.php @@ -7,8 +7,7 @@ namespace Drupal\user\Tests\Migrate; -use Drupal\migrate\Entity\Migration; -use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\Plugin\Migration; use Drupal\migrate\Tests\MigrateTestBase; use Drupal\user\Entity\User; @@ -79,7 +78,7 @@ public function testAdminPasswordPreserved() { ], ]; $ids = ['id' => ['type' => 'integer']]; - $config = [ + $definition = [ 'id' => 'users', 'migration_tags' => ['Admin password test'], 'source' => [ @@ -95,7 +94,7 @@ public function testAdminPasswordPreserved() { ], 'destination' => ['plugin' => 'entity:user'], ]; - $migration = Migration::create($config); + $migration = new Migration([], $definition['id'], $definition); $this->executeMigration($migration); // Verify that admin username and email were changed, but password was not. diff --git a/core/modules/user/src/Tests/Migrate/d6/MigrateUserPictureFileTest.php b/core/modules/user/src/Tests/Migrate/d6/MigrateUserPictureFileTest.php index 9f7b20a..0eed04e 100644 --- a/core/modules/user/src/Tests/Migrate/d6/MigrateUserPictureFileTest.php +++ b/core/modules/user/src/Tests/Migrate/d6/MigrateUserPictureFileTest.php @@ -27,7 +27,7 @@ protected function setUp() { $this->installEntitySchema('file'); /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ - $migration = Migration::load('d6_user_picture_file'); + $migration = $this->container->get('plugin.manager.migration')->createInstance('d6_user_picture_file'); $source = $migration->get('source'); $source['site_path'] = 'core/modules/simpletest'; $migration->set('source', $source); diff --git a/core/modules/user/src/Tests/Migrate/d6/MigrateUserRoleTest.php b/core/modules/user/src/Tests/Migrate/d6/MigrateUserRoleTest.php index e78bb7f..8bf8159 100644 --- a/core/modules/user/src/Tests/Migrate/d6/MigrateUserRoleTest.php +++ b/core/modules/user/src/Tests/Migrate/d6/MigrateUserRoleTest.php @@ -31,7 +31,7 @@ protected function setUp() { */ public function testUserRole() { /** @var \Drupal\migrate\entity\Migration $migration */ - $id_map = Migration::load('d6_user_role')->getIdMap(); + $id_map = $this->container->get('plugin.manager.migration')->createInstance('d6_user_role')->getIdMap(); $rid = 'anonymous'; $anonymous = Role::load($rid); $this->assertIdentical($rid, $anonymous->id()); diff --git a/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php b/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php index eb94627..5034863 100644 --- a/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php +++ b/core/modules/user/src/Tests/Migrate/d6/MigrateUserTest.php @@ -86,7 +86,7 @@ public function testUser() { ->execute() ->fetchCol(); $roles = array(RoleInterface::AUTHENTICATED_ID); - $id_map = Migration::load('d6_user_role')->getIdMap(); + $id_map = $this->container->get('plugin.manager.migration')->createInstance('d6_user_role')->getIdMap(); foreach ($rids as $rid) { $role = $id_map->lookupDestinationId(array($rid)); $roles[] = reset($role); diff --git a/core/modules/user/src/Tests/Migrate/d7/UserMigrationBuilderTest.php b/core/modules/user/src/Tests/Migrate/d7/UserMigrationClassTest.php similarity index 57% rename from core/modules/user/src/Tests/Migrate/d7/UserMigrationBuilderTest.php rename to core/modules/user/src/Tests/Migrate/d7/UserMigrationClassTest.php index 09fae9e..cd54705 100644 --- a/core/modules/user/src/Tests/Migrate/d7/UserMigrationBuilderTest.php +++ b/core/modules/user/src/Tests/Migrate/d7/UserMigrationClassTest.php @@ -12,22 +12,18 @@ /** * @group user */ -class UserMigrationBuilderTest extends MigrateDrupal7TestBase { +class UserMigrationClassTest extends MigrateDrupal7TestBase { /** * Tests that profile fields are merged into the d6_profile_values migration's * process pipeline by the d6_profile_values builder. */ public function testBuilder() { - $template = \Drupal::service('migrate.template_storage') - ->getTemplateByName('d7_user'); + $migration = $this->container->get('plugin.manager.migration') + ->createInstance('d7_user'); /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */ - $migrations = \Drupal::service('plugin.manager.migrate.builder') - ->createInstance('d7_user') - ->buildMigrations($template); - - $this->assertIdentical('d7_user', $migrations[0]->id()); - $process = $migrations[0]->getProcess(); + $this->assertIdentical('d7_user', $migration->id()); + $process = $migration->getProcess(); $this->assertIdentical('field_file', $process['field_file'][0]['source']); }