diff --git a/core/modules/migrate/migrate.services.yml b/core/modules/migrate/migrate.services.yml index c4e66333fd4f27c5766f1e0e83016d20a2dcddb5..da43b38354eddc536062dc0f13ddf7e67638bf33 100644 --- a/core/modules/migrate/migrate.services.yml +++ b/core/modules/migrate/migrate.services.yml @@ -5,12 +5,6 @@ services: - { name: cache.bin } factory: cache_factory:get arguments: [migrate] - migrate.template_storage: - class: Drupal\migrate\MigrateTemplateStorage - arguments: ['@module_handler'] - migrate.migration_builder: - class: Drupal\migrate\MigrationBuilder - arguments: ['@plugin.manager.migrate.builder'] plugin.manager.migrate.source: class: Drupal\migrate\Plugin\MigratePluginManager arguments: [source, '@container.namespaces', '@cache.discovery', '@module_handler', 'Drupal\migrate\Annotation\MigrateSource'] @@ -23,9 +17,6 @@ services: plugin.manager.migrate.id_map: class: Drupal\migrate\Plugin\MigratePluginManager arguments: [id_map, '@container.namespaces', '@cache.discovery', '@module_handler'] - 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/MigrateTemplateStorage.php b/core/modules/migrate/src/MigrateTemplateStorage.php deleted file mode 100644 index 8467ad6395c821b23ccf5f07f983ff458fb7badd..0000000000000000000000000000000000000000 --- a/core/modules/migrate/src/MigrateTemplateStorage.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate\MigrateTemplateStorage. - */ - -namespace Drupal\migrate; - -use Drupal\Component\Serialization\Yaml; -use Drupal\Core\Extension\ModuleHandlerInterface; - -/** - * Storage to access migration template configuration in enabled extensions. - */ -class MigrateTemplateStorage implements MigrateTemplateStorageInterface { - /** - * Extension sub-directory containing default configuration for migrations. - */ - - const MIGRATION_TEMPLATE_DIRECTORY = 'migration_templates'; - - /** - * Template subdirectory. - * - * @var string - */ - protected $directory; - - /** - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * {@inheritdoc} - */ - public function __construct(ModuleHandlerInterface $module_handler, $directory = self::MIGRATION_TEMPLATE_DIRECTORY) { - $this->moduleHandler = $module_handler; - $this->directory = $directory; - } - - /** - * {@inheritdoc} - */ - public function findTemplatesByTag($tag) { - $templates = $this->getAllTemplates(); - $matched_templates = []; - foreach ($templates as $template_name => $template) { - if (!empty($template['migration_tags'])) { - if (in_array($tag, $template['migration_tags'])) { - $matched_templates[$template_name] = $template; - } - } - } - return $matched_templates; - } - - /** - * {@inheritdoc} - */ - public function getTemplateByName($name) { - $templates = $this->getAllTemplates(); - return isset($templates[$name]) ? $templates[$name] : NULL; - } - - /** - * {@inheritdoc} - */ - public function getAllTemplates() { - $templates = []; - foreach ($this->moduleHandler->getModuleDirectories() as $directory) { - $full_directory = $directory . '/' . $this->directory; - if (file_exists($full_directory)) { - $files = scandir($full_directory); - foreach ($files as $file) { - if ($file[0] !== '.' && preg_match('/\.yml$/', $file)) { - $templates[basename($file, '.yml')] = Yaml::decode(file_get_contents("$full_directory/$file")); - } - } - } - } - - return $templates; - } - -} diff --git a/core/modules/migrate/src/MigrateTemplateStorageInterface.php b/core/modules/migrate/src/MigrateTemplateStorageInterface.php deleted file mode 100644 index dc9372e0d8b6592b53941ad2eb23be2ba8f4b74b..0000000000000000000000000000000000000000 --- a/core/modules/migrate/src/MigrateTemplateStorageInterface.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate\MigrateTemplateStorageInterface. - */ - -namespace Drupal\migrate; - -/** - * The MigrateTemplateStorageInterface interface. - */ -interface MigrateTemplateStorageInterface { - - /** - * Find all migration templates with the specified tag. - * - * @param $tag - * The tag to match. - * - * @return array - * Any templates (parsed YAML config) that matched, keyed by the ID. - */ - public function findTemplatesByTag($tag); - - /** - * Retrieve a template given a specific name. - * - * @param string $name - * A migration template name. - * - * @return NULL|array - * A parsed migration template, or NULL if it doesn't exist. - */ - public function getTemplateByName($name); - - /** - * Retrieves all migration templates belonging to enabled extensions. - * - * @return array - * Array of parsed templates, keyed by the fully-qualified id. - */ - public function getAllTemplates(); - -} diff --git a/core/modules/migrate/src/MigrationBuilder.php b/core/modules/migrate/src/MigrationBuilder.php deleted file mode 100644 index 1123b8d309166b8a79769bc7ece726ac9fc26cf6..0000000000000000000000000000000000000000 --- a/core/modules/migrate/src/MigrationBuilder.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate\MigrationBuilder. - */ - -namespace Drupal\migrate; - -use Drupal\migrate\Plugin\MigratePluginManager; - -/** - * Builds migration entities from migration templates. - */ -class MigrationBuilder implements MigrationBuilderInterface { - - /** - * The builder plugin manager. - * - * @var \Drupal\migrate\Plugin\MigratePluginManager - */ - protected $builderManager; - - /** - * Constructs a MigrationBuilder. - * - * @param \Drupal\migrate\Plugin\MigratePluginManager $builder_manager - * The builder plugin manager. - */ - public function __construct(MigratePluginManager $builder_manager) { - $this->builderManager = $builder_manager; - } - - /** - * {@inheritdoc} - */ - public function createMigrations(array $templates) { - /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */ - $migrations = []; - - foreach ($templates as $template_id => $template) { - if (isset($template['builder'])) { - $variants = $this->builderManager - ->createInstance($template['builder']['plugin'], $template['builder']) - ->buildMigrations($template); - } - else { - $variants = array(Migration::create($template)); - } - - /** @var \Drupal\migrate\Entity\MigrationInterface[] $variants */ - foreach ($variants as $variant) { - $variant->set('template', $template_id); - } - $migrations = array_merge($migrations, $variants); - } - - return $migrations; - } - -} diff --git a/core/modules/migrate/src/MigrationBuilderInterface.php b/core/modules/migrate/src/MigrationBuilderInterface.php deleted file mode 100644 index 66f3078e53df59d41343f7a17be083ef479f1f33..0000000000000000000000000000000000000000 --- a/core/modules/migrate/src/MigrationBuilderInterface.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate\MigrationBuilderInterface. - */ - -namespace Drupal\migrate; - -/** - * The migration builder interface. - */ -interface MigrationBuilderInterface { - - /** - * Builds migration entities from templates. - * - * @param array $templates - * The parsed templates (each of which is an array parsed from YAML), keyed - * by ID. - * - * @return \Drupal\migrate\Entity\MigrationInterface[] - * The migration entities derived from the templates. - */ - public function createMigrations(array $templates); - -} diff --git a/core/modules/migrate/src/Plugin/MigrateBuilderInterface.php b/core/modules/migrate/src/Plugin/MigrateBuilderInterface.php deleted file mode 100644 index 511af1ba3a2eb5d26be61e31a0675b4fe53d574c..0000000000000000000000000000000000000000 --- a/core/modules/migrate/src/Plugin/MigrateBuilderInterface.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate\Plugin\MigrateBuilderInterface. - */ - -namespace Drupal\migrate\Plugin; - -/** - * Defines the builder plugin type. - * - * Builder plugins implement custom logic to generate migration entities from - * migration templates. For example, a migration may need to be customized based - * on data that's present in the source database; such customization is - * implemented by builders. - */ -interface MigrateBuilderInterface { - - /** - * Builds migration entities based on a template. - * - * @param array $template - * The parsed template. - * - * @return \Drupal\migrate\Entity\MigrationInterface[] - * The unsaved migrations generated from the template. - */ - public function buildMigrations(array $template); - -} diff --git a/core/modules/migrate/src/Plugin/migrate/builder/BuilderBase.php b/core/modules/migrate/src/Plugin/migrate/builder/BuilderBase.php deleted file mode 100644 index 70c6094640802f2588912280fe6e962041b8499f..0000000000000000000000000000000000000000 --- a/core/modules/migrate/src/Plugin/migrate/builder/BuilderBase.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate\Plugin\migrate\builder\BuilderBase. - */ - -namespace Drupal\migrate\Plugin\migrate\builder; - -use Drupal\Core\Plugin\PluginBase; -use Drupal\migrate\Plugin\MigrateBuilderInterface; - -/** - * Provides abstract base class for builder plugins. - */ -abstract class BuilderBase extends PluginBase implements MigrateBuilderInterface { - - /** - * Returns a fully initialized instance of a source plugin. - * - * @param string $plugin_id - * The plugin ID. - * @param array $configuration - * (optional) Additional configuration for the plugin. Defaults to an empty - * array. - * - * @return \Drupal\migrate\Plugin\MigrateSourceInterface|\Drupal\migrate\Plugin\RequirementsInterface - * The fully initialized source plugin. - */ - protected function getSourcePlugin($plugin_id, array $configuration = []) { - $configuration['plugin'] = $plugin_id; - // By default, SqlBase subclasses will try to join on a map table. But in - // this case we're trying to use the source plugin as a detached iterator - // over the source data, so we don't want to join on (or create) the map - // table. - // @see SqlBase::initializeIterator() - $configuration['ignore_map'] = TRUE; - // Source plugins are tightly coupled to migration entities, so we need - // to create a fake migration in order to properly initialize the plugin. - $values = [ - 'id' => uniqid(), - 'source' => $configuration, - // Since this isn't a real migration, we don't want a real destination -- - // the 'null' destination is perfect for this. - 'destination' => [ - 'plugin' => 'null', - ], - ]; - return Migration::create($values)->getSourcePlugin(); - } - -} diff --git a/core/modules/migrate/src/Tests/TemplateTest.php b/core/modules/migrate/src/Tests/TemplateTest.php deleted file mode 100644 index eb22b640d23d0c920af81909e3aeabfb5bc47a33..0000000000000000000000000000000000000000 --- a/core/modules/migrate/src/Tests/TemplateTest.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate\Tests\TemplateTest. - */ - -namespace Drupal\migrate\Tests; - -/** - * Tests the migration template functionality. - * - * @group migrate - */ -class TemplateTest extends MigrateTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('template_test'); - - /** - * Tests different connection types. - */ - public function testTemplates() { - $migration_templates = \Drupal::service('migrate.template_storage')->findTemplatesByTag("Template Test"); - $expected_url = [ - 'id' => 'url_template', - 'label' => 'Template test - URL', - 'migration_tags' => ['Template Test'], - 'source' => ['plugin' => 'empty'], - 'process' => ['src' => 'foobar'], - 'destination' => ['plugin' => 'url_alias'], - ]; - $expected_node = [ - 'id' => 'node_template', - 'label' => 'Template test - node', - 'migration_tags' => ['Template Test'], - 'source' => ['plugin' => 'empty'], - 'process' => ['src' => 'barfoo'], - 'destination' => ['plugin' => 'entity:node'], - ]; - $this->assertIdentical($migration_templates['migrate.migration.url_template'], $expected_url); - $this->assertIdentical($migration_templates['migrate.migration.node_template'], $expected_node); - $this->assertFalse(isset($migration_templates['migrate.migration.other_template'])); - } - - /** - * Tests retrieving a template by name. - */ - public function testGetTemplateByName() { - /** @var \Drupal\migrate\MigrateTemplateStorageInterface $template_storage */ - $template_storage = \Drupal::service('migrate.template_storage'); - - $expected_url = [ - 'id' => 'url_template', - 'label' => 'Template test - URL', - 'migration_tags' => ['Template Test'], - 'source' => ['plugin' => 'empty'], - 'process' => ['src' => 'foobar'], - 'destination' => ['plugin' => 'url_alias'], - ]; - $expected_node = [ - 'id' => 'node_template', - 'label' => 'Template test - node', - 'migration_tags' => ['Template Test'], - 'source' => ['plugin' => 'empty'], - 'process' => ['src' => 'barfoo'], - 'destination' => ['plugin' => 'entity:node'], - ]; - $this->assertIdentical($template_storage->getTemplateByName('migrate.migration.url_template'), $expected_url); - $this->assertIdentical($template_storage->getTemplateByName('migrate.migration.node_template'), $expected_node); - $this->assertNull($template_storage->getTemplateByName('migrate.migration.dne')); - } - -} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/builder/CckBuilder.php b/core/modules/migrate_drupal/src/Plugin/migrate/builder/CckBuilder.php deleted file mode 100644 index 50b1fcd6dd9b30284b666eccab3a1bef9afb815b..0000000000000000000000000000000000000000 --- a/core/modules/migrate_drupal/src/Plugin/migrate/builder/CckBuilder.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder. - */ - -namespace Drupal\migrate_drupal\Plugin\migrate\builder; - -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\Entity\MigrationInterface; -use Drupal\migrate\Plugin\migrate\builder\BuilderBase; -use Drupal\migrate\Plugin\MigratePluginManager; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Base class for builders which leverage cckfield plugins. - */ -abstract class CckBuilder extends BuilderBase implements ContainerFactoryPluginInterface { - - /** - * The cckfield plugin manager. - * - * @var \Drupal\migrate\Plugin\MigratePluginManager - */ - protected $cckPluginManager; - - /** - * Already-instantiated cckfield plugins, keyed by ID. - * - * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[] - */ - protected $cckPluginCache = []; - - /** - * Constructs a CckBuilder. - * - * @param array $configuration - * Plugin configuration. - * @param string $plugin_id - * The plugin ID. - * @param mixed $plugin_definition - * The plugin definition. - * @param \Drupal\migrate\Plugin\MigratePluginManager $cck_manager - * The cckfield plugin manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigratePluginManager $cck_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->cckPluginManager = $cck_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') - ); - } - - /** - * Gets a cckfield plugin instance. - * - * @param string $field_type - * The field type (plugin ID). - * @param \Drupal\migrate\Entity\MigrationInterface|NULL $migration - * The migration, if any. - * - * @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface - * The cckfield plugin instance. - */ - protected function getCckPlugin($field_type, MigrationInterface $migration = NULL) { - if (empty($this->cckPluginCache[$field_type])) { - $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $migration); - } - return $this->cckPluginCache[$field_type]; - } - -} 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 eba6dbb49cfe4f04dc95bdb80f5b2c40f0d1c24c..0000000000000000000000000000000000000000 --- a/core/modules/migrate_drupal/src/Plugin/migrate/builder/d6/CckMigration.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate_drupal\Plugin\migrate\builder\d6\CckMigration. - */ - -namespace Drupal\migrate_drupal\Plugin\migrate\builder\d6; - -use Drupal\migrate\Exception\RequirementsException; -use Drupal\migrate\Plugin\RequirementsInterface; -use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder; - -/** - * @PluginID("d6_cck_migration") - */ -class CckMigration extends CckBuilder { - - /** - * List of cckfield plugin IDs which have already run. - * - * @var string[] - */ - protected $processedFieldTypes = []; - - /** - * {@inheritdoc} - */ - public function buildMigrations(array $template) { - $migration = Migration::create($template); - - $source_plugin = $migration->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/Tests/MigrateDrupalTestBase.php b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php index 485eeb0e524c1df4efc11ea00a56fa44cd972dc3..032837c8f098aff5210d8af574b614909c98b531 100644 --- a/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php +++ b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php @@ -50,29 +50,4 @@ protected function loadFixture($path) { Database::setActiveConnection($default_db); } - /** - * Turn all the migration templates for the specified drupal version into - * real migration entities so we can test them. - * - * @param string $version - * Drupal version as provided in migration_tags - e.g., 'Drupal 6'. - */ - protected function installMigrations($version) { - // @TODO https://www.drupal.org/node/2668436 - return; - $migration_templates = \Drupal::service('migrate.template_storage')->findTemplatesByTag($version); - $migrations = \Drupal::service('migrate.migration_builder')->createMigrations($migration_templates); - foreach ($migrations as $migration) { - try { - $migration->save(); - } - catch (PluginNotFoundException $e) { - // Migrations requiring modules not enabled will throw an exception. - // Ignoring this exception is equivalent to placing config in the - // optional subdirectory - the migrations we require for the test will - // be successfully saved. - } - } - } - } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php index 750f5c190e0074991c457ad20283177496c4d045..f9b7950afa93d245383a42e460588f40c2410c27 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6TestBase.php @@ -6,6 +6,7 @@ */ namespace Drupal\migrate_drupal\Tests\d6; + use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; /** @@ -33,7 +34,6 @@ abstract class MigrateDrupal6TestBase extends MigrateDrupalTestBase { protected function setUp() { parent::setUp(); $this->loadFixture( __DIR__ . '/../../../tests/fixtures/drupal6.php'); - $this->installMigrations('Drupal 6'); } /** diff --git a/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php index 63e8e67180499a499e31cc10a8c07be21e38e99c..f4c8e88e0c447db6af9db842e6b214df0a8a9dc1 100644 --- a/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php +++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateDrupal7TestBase.php @@ -20,7 +20,6 @@ abstract class MigrateDrupal7TestBase extends MigrateDrupalTestBase { protected function setUp() { parent::setUp(); $this->loadFixture(__DIR__ . '/../../../tests/fixtures/drupal7.php'); - $this->installMigrations('Drupal 7'); } } diff --git a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php index de3ed1bbd99b9bd90ba0bcf3b2a9315944544482..5749a5f724051e1495d737513945ee33942080be 100644 --- a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php +++ b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php @@ -32,8 +32,8 @@ public function testMigrateDependenciesOrder() { $expected_order = array('d6_filter_format', 'd6_node:page', 'd6_comment'); $this->assertIdentical(array_keys($migrations), $expected_order); $expected_requirements = array( - // d6_comment depends on d6_node:*, which the storage controller expands - // into every variant of d6_node created by the MigrationBuilder. + // d6_comment depends on d6_node:*, which the deriver expands into every + // variant of d6_node. 'd6_node:article', 'd6_node:company', 'd6_node:employee', 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 5e574567e3c2b1f9d38cdec73d3cae2fa478ee10..0000000000000000000000000000000000000000 --- a/core/modules/node/src/Plugin/migrate/builder/d6/Node.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\node\Plugin\migrate\builder\d6\Node. - */ - -namespace Drupal\node\Plugin\migrate\builder\d6; - -use Drupal\migrate\Exception\RequirementsException; -use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder; - -/** - * @PluginID("d6_node") - */ -class Node extends CckBuilder { - - /** - * {@inheritdoc} - */ - public function buildMigrations(array $template) { - $migrations = []; - - // Read all CCK field instance definitions in the source database. - $fields = array(); - $source_plugin = $this->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/Plugin/migrate/builder/d7/Node.php b/core/modules/node/src/Plugin/migrate/builder/d7/Node.php deleted file mode 100644 index e6291fb1b3dda2e890589fe96f07bc641c29301a..0000000000000000000000000000000000000000 --- a/core/modules/node/src/Plugin/migrate/builder/d7/Node.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\node\Plugin\migrate\builder\d7\Node. - */ - -namespace Drupal\node\Plugin\migrate\builder\d7; - -use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder; - -/** - * @PluginID("d7_node") - */ -class Node extends CckBuilder { - - /** - * {@inheritdoc} - */ - public function buildMigrations(array $template) { - $migrations = []; - - // Read all field instance definitions in the source database. - $fields = array(); - foreach ($this->getSourcePlugin('d7_field_instance', $template['source']) as $field) { - $info = $field->getSource(); - $fields[$info['entity_type']][$info['bundle']][$info['field_name']] = $info; - } - - foreach ($this->getSourcePlugin('d7_node_type', $template['source']) as $node_type) { - $bundle = $node_type->getSourceProperty('type'); - $values = $template; - $values['id'] .= '__' . $bundle; - $values['label'] = $this->t('@label (@type)', ['@label' => $values['label'], '@type' => $node_type->getSourceProperty('name')]); - $values['source']['node_type'] = $bundle; - $migration = Migration::create($values); - - if (isset($fields['node'][$bundle])) { - foreach ($fields['node'][$bundle] as $field => $data) { - if ($this->cckPluginManager->hasDefinition($data['type'])) { - $this->getCckPlugin($data['type']) - ->processCckFieldValues($migration, $field, $data); - } - else { - $migration->setProcessOfProperty($field, $field); - } - } - } - - $migrations[] = $migration; - } - - return $migrations; - } - -} diff --git a/core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php b/core/modules/node/src/Tests/Migrate/d7/NodeMigrateDeriverTest.php similarity index 90% rename from core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php rename to core/modules/node/src/Tests/Migrate/d7/NodeMigrateDeriverTest.php index 08c9c0ff2c176817976904fa72029a364dddc0f5..9a05cac4d9584489d1d11125113dbd88960b197b 100644 --- a/core/modules/node/src/Tests/Migrate/d7/NodeBuilderTest.php +++ b/core/modules/node/src/Tests/Migrate/d7/NodeMigrateDeriverTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\node\Tests\Migrate\d7\NodeBuilderTest. + * Contains \Drupal\node\Tests\Migrate\d7\NodeMigrateDeriverTest. */ namespace Drupal\node\Tests\Migrate\d7; @@ -10,11 +10,11 @@ use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase; /** - * Tests the d7_node builder. + * Tests the d7_node node deriver. * * @group node */ -class NodeBuilderTest extends MigrateDrupal7TestBase { +class NodeMigrateDeriverTest extends MigrateDrupal7TestBase { public static $modules = ['node']; diff --git a/core/modules/taxonomy/src/Plugin/migrate/builder/d6/TermNode.php b/core/modules/taxonomy/src/Plugin/migrate/builder/d6/TermNode.php deleted file mode 100644 index 042e6151fd2eae1c491cd11c81a8842a722ba57c..0000000000000000000000000000000000000000 --- a/core/modules/taxonomy/src/Plugin/migrate/builder/d6/TermNode.php +++ /dev/null @@ -1,106 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\taxonomy\Plugin\migrate\builder\d6\TermNode. - */ - -namespace Drupal\taxonomy\Plugin\migrate\builder\d6; - -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\MigrateExecutable; -use Drupal\migrate\MigrateMessage; -use Drupal\migrate\MigrateTemplateStorageInterface; -use Drupal\migrate\Plugin\migrate\builder\BuilderBase; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * @PluginID("d6_term_node") - */ -class TermNode extends BuilderBase implements ContainerFactoryPluginInterface { - - /** - * The migration template storage service. - * - * @var \Drupal\migrate\MigrateTemplateStorage - */ - protected $templateStorage; - - /** - * Constructs a TermNode builder. - * - * @param array $configuration - * Plugin configuration. - * @param string $plugin_id - * The plugin ID. - * @param mixed $plugin_definition - * The plugin definition. - * @param \Drupal\migrate\MigrateTemplateStorageInterface $template_storage - * The migration template storage handler. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateTemplateStorageInterface $template_storage) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->templateStorage = $template_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('migrate.template_storage') - ); - } - - /** - * Builds a map of source vocabulary IDs to expected destination IDs. - * - * @param array $source - * Additional configuration for the d6_taxonomy_vocabulary source. - * - * @return array - * The vid map. The keys are the source IDs and the values are the - * (expected) destination IDs. - */ - protected function getVocabularyIdMap(array $source) { - $map = []; - - $template = $this->templateStorage->getTemplateByName('d6_taxonomy_vocabulary'); - $template['source'] += $source; - - $migration = Migration::create($template); - $executable = new MigrateExecutable($migration, new MigrateMessage()); - // Only process the destination ID properties. - $process = array_intersect_key($template['process'], $migration->getDestinationPlugin()->getIds()); - - foreach ($migration->getSourcePlugin() as $source_row) { - // Process the row to generate the expected destination ID. - $executable->processRow($source_row, $process); - $map[$source_row->getSourceProperty('vid')] = $source_row->getDestinationProperty('vid'); - } - - return $map; - } - - /** - * {@inheritdoc} - */ - public function buildMigrations(array $template) { - $migrations = []; - - foreach ($this->getVocabularyIdMap($template['source']) as $source_vid => $destination_vid) { - $values = $template; - $values['id'] .= '__' . $source_vid; - $values['source']['vid'] = $source_vid; - $migration = Migration::create($values); - $migration->setProcessOfProperty($destination_vid, 'tid'); - $migrations[] = $migration; - } - - return $migrations; - } - -} diff --git a/core/modules/user/src/Plugin/migrate/User.php b/core/modules/user/src/Plugin/migrate/User.php index 500b2abba20182bd5cf405bd5a89eaaf732d9255..a337358c526e9a5980b60e0552dab77d66ce51ac 100644 --- a/core/modules/user/src/Plugin/migrate/User.php +++ b/core/modules/user/src/Plugin/migrate/User.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\user\Plugin\migrate\builder\d7\User. + * Contains \Drupal\user\Plugin\migrate\User. */ namespace Drupal\user\Plugin\migrate; diff --git a/core/modules/user/src/Plugin/migrate/builder/d6/ProfileValues.php b/core/modules/user/src/Plugin/migrate/builder/d6/ProfileValues.php deleted file mode 100644 index ce61aeaf7342f513485b7c3e8aed7890c722f20c..0000000000000000000000000000000000000000 --- a/core/modules/user/src/Plugin/migrate/builder/d6/ProfileValues.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\user\Plugin\migrate\builder\d6\ProfileValues. - */ - -namespace Drupal\user\Plugin\migrate\builder\d6; - -use Drupal\migrate\Exception\RequirementsException; -use Drupal\migrate\Plugin\migrate\builder\BuilderBase; - -/** - * @PluginID("d6_profile_values") - */ -class ProfileValues extends BuilderBase { - - /** - * {@inheritdoc} - */ - public function buildMigrations(array $template) { - $migration = Migration::create($template); - - // @TODO The source plugin should accept a database connection. - // @see https://www.drupal.org/node/2552791 - $source_plugin = $this->getSourcePlugin('profile_field', $template['source']); - try { - $source_plugin->checkRequirements(); - } - catch (RequirementsException $e) { - return []; - } - - foreach ($source_plugin as $field) { - $migration->setProcessOfProperty($field->getSourceProperty('name'), $field->getSourceProperty('name')); - } - - return [$migration]; - } - -} 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 e526748b340f45df6c896ee9a9cb81e44653381b..0000000000000000000000000000000000000000 --- a/core/modules/user/src/Plugin/migrate/builder/d7/User.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\user\Plugin\migrate\builder\d7\User. - */ - -namespace Drupal\user\Plugin\migrate\builder\d7; - -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\Exception\RequirementsException; -use Drupal\migrate\Plugin\migrate\builder\BuilderBase; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * @PluginID("d7_user") - */ -class User extends BuilderBase implements ContainerFactoryPluginInterface { - - /** - * The module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * Constructs a d7_user builder plugin instance. - * - * @param array $configuration - * The plugin configuration. - * @param string $plugin_id - * The plugin ID. - * @param mixed $plugin_definition - * The plugin definition. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler service. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->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]; - } - -}