diff --git a/core/modules/book/src/Tests/Migrate/d6/MigrateBookTest.php b/core/modules/book/src/Tests/Migrate/d6/MigrateBookTest.php index 2ae4a28..6f57fe2 100644 --- a/core/modules/book/src/Tests/Migrate/d6/MigrateBookTest.php +++ b/core/modules/book/src/Tests/Migrate/d6/MigrateBookTest.php @@ -29,7 +29,15 @@ protected function setUp() { $this->installSchema('book', array('book')); $this->installSchema('node', array('node_access')); - $id_mappings = array(); + // Create a default bogus mapping for all variants of d6_node. + $id_mappings = array( + 'd6_node:*' => array( + array( + array(0), + array(0), + ), + ), + ); for ($i = 4; $i <= 8; $i++) { $entity = entity_create('node', array( 'type' => 'story', @@ -39,7 +47,7 @@ protected function setUp() { )); $entity->enforceIsNew(); $entity->save(); - $id_mappings['d6_node'][] = array(array($i), array($i)); + $id_mappings['d6_node__story'][] = array(array($i), array($i)); } $this->prepareMigrations($id_mappings); $this->executeMigration('d6_book'); diff --git a/core/modules/comment/migration_templates/d6_comment.yml b/core/modules/comment/migration_templates/d6_comment.yml index 1a41ec7..0275d1c 100644 --- a/core/modules/comment/migration_templates/d6_comment.yml +++ b/core/modules/comment/migration_templates/d6_comment.yml @@ -37,7 +37,7 @@ destination: plugin: entity:comment migration_dependencies: required: - - d6_node + - d6_node:* - d6_comment_type - d6_user - d6_comment_entity_display diff --git a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php index d81bbe2..0458c54 100644 --- a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php +++ b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php @@ -51,7 +51,7 @@ protected function setUp() { $node->save(); $id_mappings = array( 'd6_filter_format' => array(array(array(1), array('filtered_html'))), - 'd6_node' => array(array(array(1), array(1))), + 'd6_node:*' => array(array(array(1), array(1))), 'd6_user' => array(array(array(0), array(0))), 'd6_comment_type' => array(array(array('comment'), array('comment_no_subject'))), 'd6_comment_entity_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))), diff --git a/core/modules/file/src/Plugin/migrate/cckfield/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/FileField.php index 95d0b4d..d275dcf 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/FileField.php @@ -44,11 +44,7 @@ public function getFieldFormatterMap() { public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { $process = [ 'plugin' => 'd6_cck_file', - 'source' => [ - $field_name, - $field_name . '_list', - $field_name . '_data', - ], + 'source' => $field_name, ]; $migration->mergeProcessOfProperty($field_name, $process); } diff --git a/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php b/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php index 363b499..15be985 100644 --- a/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php +++ b/core/modules/file/src/Plugin/migrate/process/d6/CckFile.php @@ -8,40 +8,84 @@ namespace Drupal\file\Plugin\migrate\process\d6; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\Plugin\MigrateProcessInterface; +use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; -use Drupal\migrate\Plugin\migrate\process\Route; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @MigrateProcessPlugin( * id = "d6_cck_file" * ) */ -class CckFile extends Route implements ContainerFactoryPluginInterface { +class CckFile extends ProcessPluginBase implements ContainerFactoryPluginInterface { + + protected $migrationPlugin; + + /** + * Constructs a CckFile plugin instance. + * + * @param array $configuration + * The plugin configuration. + * @param string $plugin_id + * The plugin ID. + * @param mixed $plugin_definition + * The plugin definition. + * @param \Drupal\migrate\Entity\MigrationInterface $migration + * The current migration. + * @param \Drupal\migrate\Plugin\MigrateProcessInterface $migration_plugin + * An instance of the 'migration' process plugin. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->migration = $migration; + $this->migrationPlugin = $migration_plugin; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + // Configure the migration process plugin to look up migrated IDs from + // the d6_file migration. + $migration_plugin_configuration = [ + 'source' => ['fid'], + 'migration' => 'd6_file', + ]; + + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration) + ); + } /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - list($fid, $list, $data) = $value; + $options = unserialize($value['data']); - // If $fid is still an array at this point, that's because we have a file - // attachment as per D6 core. If not, then we have a filefield from contrib. - if (is_array($fid)) { - $list = $fid['list']; - $fid = $fid['fid']; + // Try to look up the ID of the migrated file. If one cannot be found, it + // means the file referenced by the current field item did not migrate for + // some reason -- file migration is notoriously brittle -- and we do NOT + // want to send invalid file references into the field system (it causes + // fatals), so return an empty item instead. + $fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property); + if ($fid) { + return [ + 'target_id' => $fid, + 'display' => $value['list'], + 'description' => isset($options['description']) ? $options['description'] : '', + ]; } else { - $options = unserialize($data); + return []; } - - $file = [ - 'target_id' => $fid, - 'display' => isset($list) ? $list : 0, - 'description' => isset($options['description']) ? $options['description'] : '', - ]; - - return $file; } } diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php index 11e91b1..c18a8a9 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php @@ -21,6 +21,15 @@ class MigrateUploadTest extends MigrateUploadBase { */ protected function setUp() { parent::setUp(); + $id_mappings = array( + 'd6_node:*' => array( + array( + array(0), + array(0), + ), + ), + ); + $this->prepareMigrations($id_mappings); $this->executeMigration('d6_upload'); } diff --git a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php index f407782..394dc43 100644 --- a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php @@ -39,11 +39,7 @@ public function getFieldFormatterMap() { public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { $process = [ 'plugin' => 'd6_cck_link', - 'source' => [ - $field_name, - $field_name . '_title', - $field_name . '_attributes', - ], + 'source' => $field_name, ]; $migration->mergeProcessOfProperty($field_name, $process); } diff --git a/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php b/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php index 2b3b932..becf88c 100644 --- a/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php +++ b/core/modules/link/src/Plugin/migrate/process/d6/CckLink.php @@ -45,15 +45,13 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - list($url, $title, $attributes) = $value; - // Drupal 6 link attributes are double serialized. - $attributes = unserialize(unserialize($attributes)); + $attributes = unserialize(unserialize($value['attributes'])); // Massage the values into the correct form for the link. - $route['uri'] = $url; + $route['uri'] = $value['url']; $route['options']['attributes'] = $attributes; - $route['title'] = $title; + $route['title'] = $value['title']; return $route; } diff --git a/core/modules/migrate/config/schema/migrate.load.schema.yml b/core/modules/migrate/config/schema/migrate.load.schema.yml deleted file mode 100644 index aab9469..0000000 --- a/core/modules/migrate/config/schema/migrate.load.schema.yml +++ /dev/null @@ -1,21 +0,0 @@ -# Schema for the migrate load plugins. - -migrate.load.*: - type: migrate_load - label: 'Default load' - -migrate.load.drupal_entity: - type: migrate_load - label: 'Default source' - mapping: - bundle_migration: - type: string - label: 'Bundle migration' - -migrate.load.d6_term_node: - type: migrate_load - label: 'Default source' - mapping: - bundle_migration: - type: string - label: 'Bundle migration' diff --git a/core/modules/migrate/config/schema/migrate.schema.yml b/core/modules/migrate/config/schema/migrate.schema.yml index 88681c8..fcadda9 100644 --- a/core/modules/migrate/config/schema/migrate.schema.yml +++ b/core/modules/migrate/config/schema/migrate.schema.yml @@ -16,9 +16,6 @@ migrate.migration.*: label: type: label label: 'Label' - load: - type: migrate.load.[plugin] - label: 'Source' source: type: migrate.source.[plugin] label: 'Source' diff --git a/core/modules/migrate/src/MigrationStorage.php b/core/modules/migrate/src/MigrationStorage.php index ccb188f..93c371b 100644 --- a/core/modules/migrate/src/MigrationStorage.php +++ b/core/modules/migrate/src/MigrationStorage.php @@ -64,52 +64,54 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * {@inheritdoc} */ public function loadMultiple(array $ids = NULL) { + if ($ids) { + $ids = $this->getVariantIds($ids); + } /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */ $migrations = parent::loadMultiple($ids); foreach ($migrations as $migration) { - $migration->set('migration_dependencies', $this->expandDependencies($migration->getMigrationDependencies())); + $dependencies = array_map([$this, 'getVariantIds'], $migration->getMigrationDependencies()); + $migration->set('migration_dependencies', $dependencies); } - return $migrations; + + // Build an array of dependencies and set the order of the migrations. + return $this->buildDependencyMigration($migrations, []); } /** - * Expands template dependencies. + * Splices variant IDs into a list of migration IDs. * - * Migration dependencies which match the template_id:* pattern are a signal - * that the migration depends on every variant of template_id. This method - * queries for those variant IDs and splices them into the list of - * dependencies. + * IDs which match the template_id:* pattern are shorthand for every variant + * of template_id. This method queries for those variant IDs and splices them + * into the original list. * - * @param array $dependencies - * The original migration dependencies (with template IDs), organized by - * group (required, optional, etc.) + * @param string[] $ids + * A set of migration IDs. * - * @return array - * The expanded list of dependencies, organized by group. + * @return string[] + * The expanded list of IDs. */ - protected function expandDependencies(array $dependencies) { - $expanded_dependencies = []; - - foreach (array_keys($dependencies) as $group) { - $expanded_dependencies[$group] = []; - - foreach ($dependencies[$group] as $dependency_id) { - if (substr($dependency_id, -2) == ':*') { - $template_id = substr($dependency_id, 0, -2); - $variants = $this->queryFactory->get($this->entityType, 'OR') - ->condition('id', $template_id) - ->condition('template', $template_id) - ->execute(); - $expanded_dependencies[$group] = array_merge($expanded_dependencies[$group], $variants); - } - else { - $expanded_dependencies[$group][] = $dependency_id; - } + protected function getVariantIds(array $ids) { + // Re-index the array numerically, since we need to limit the loop by size. + $ids = array_values($ids); + + $index = 0; + while ($index < count($ids)) { + if (substr($ids[$index], -2) == ':*') { + $template_id = substr($ids[$index], 0, -2); + $variants = $this->queryFactory->get($this->entityType, 'OR') + ->condition('id', $template_id) + ->condition('template', $template_id) + ->execute(); + array_splice($ids, $index, 1, $variants); + $index += count($variants); + } + else { + $index++; } } - - return $expanded_dependencies; + return $ids; } /** diff --git a/core/modules/migrate/src/Plugin/SourceEntityInterface.php b/core/modules/migrate/src/Plugin/SourceEntityInterface.php deleted file mode 100644 index 8379f6a..0000000 --- a/core/modules/migrate/src/Plugin/SourceEntityInterface.php +++ /dev/null @@ -1,32 +0,0 @@ -get('path.validator') ); } + /** * {@inheritdoc} * diff --git a/core/modules/migrate/src/Tests/MigrateTestBase.php b/core/modules/migrate/src/Tests/MigrateTestBase.php index 67210f7..b0abea8 100644 --- a/core/modules/migrate/src/Tests/MigrateTestBase.php +++ b/core/modules/migrate/src/Tests/MigrateTestBase.php @@ -116,20 +116,19 @@ protected function loadDumps(array $files, $method = 'load') { * ids. */ protected function prepareMigrations(array $id_mappings) { - /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */ - $migrations = entity_load_multiple('migration', array_keys($id_mappings)); foreach ($id_mappings as $migration_id => $data) { - $migration = $migrations[$migration_id]; - - // Mark the dependent migrations as complete. - $migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED); - - $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]); + // Use loadMultiple() here in order to load all variants. + foreach (Migration::loadMultiple([$migration_id]) as $migration) { + // Mark the dependent migrations as complete. + $migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED); + + $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]); + } } } } diff --git a/core/modules/migrate/tests/src/Unit/MigrationStorageTest.php b/core/modules/migrate/tests/src/Unit/MigrationStorageTest.php index 9b27bbc..93cf301 100644 --- a/core/modules/migrate/tests/src/Unit/MigrationStorageTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrationStorageTest.php @@ -54,61 +54,43 @@ public function setUp() { } /** - * Tests expandDependencies() when variants exist. + * Tests getVariantIds() when variants exist. * - * @covers ::expandDependencies + * @covers ::getVariantIds */ - public function testExpandDependenciesWithVariants() { + public function testGetVariantIdsWithVariants() { $this->query->method('execute') ->willReturn(['d6_node__page', 'd6_node__article']); - $dependencies = [ - 'required' => [ - 'd6_node:*', - 'd6_user', - ], - ]; - $dependencies = $this->storage->expandDependencies($dependencies); - $this->assertSame(['d6_node__page', 'd6_node__article', 'd6_user'], $dependencies['required']); + $ids = $this->storage->getVariantIds(['d6_node:*', 'd6_user']); + $this->assertSame(['d6_node__page', 'd6_node__article', 'd6_user'], $ids); } /** - * Tests expandDependencies() when no variants exist. + * Tests getVariantIds() when no variants exist. * - * @covers ::expandDependencies + * @covers ::getVariantIds */ - public function testExpandDependenciesNoVariants() { + public function testGetVariantIdsNoVariants() { $this->query->method('execute') ->willReturn([]); - $dependencies = [ - 'required' => [ - 'd6_node:*', - 'd6_user', - ], - ]; - $dependencies = $this->storage->expandDependencies($dependencies); - $this->assertSame(['d6_user'], $dependencies['required']); + $ids = $this->storage->getVariantIds(['d6_node:*', 'd6_user']); + $this->assertSame(['d6_user'], $ids); } /** - * Tests expandDependencies() when no variants exist and there are no static + * Tests getVariantIds() when no variants exist and there are no static * (non-variant) dependencies. * - * @covers ::expandDependencies + * @covers ::getVariantIds */ - public function testExpandDependenciesNoVariantsOrStaticDependencies() { + public function testGetVariantIdsNoVariantsOrStaticDependencies() { $this->query->method('execute') ->willReturn([]); - $dependencies = [ - 'required' => [ - 'd6_node:*', - 'd6_node_revision:*', - ], - ]; - $dependencies = $this->storage->expandDependencies($dependencies); - $this->assertSame([], $dependencies['required']); + $ids = $this->storage->getVariantIds(['d6_node:*', 'd6_node_revision:*']); + $this->assertSame([], $ids); } } @@ -123,8 +105,8 @@ class TestMigrationStorage extends MigrationStorage { /** * {@inheritdoc} */ - public function expandDependencies(array $dependencies) { - return parent::expandDependencies($dependencies); + public function getVariantIds(array $ids) { + return parent::getVariantIds($ids); } } diff --git a/core/modules/migrate_drupal/migrate_drupal.module b/core/modules/migrate_drupal/migrate_drupal.module index fd4ccbc..88ceba9 100644 --- a/core/modules/migrate_drupal/migrate_drupal.module +++ b/core/modules/migrate_drupal/migrate_drupal.module @@ -8,16 +8,6 @@ use Drupal\Core\Routing\RouteMatchInterface; /** - * Implements hook_entity_type_alter(). - */ -function migrate_drupal_entity_type_alter(array &$entity_types) { - /** @var \Drupal\Core\Config\Entity\ConfigEntityType[] $entity_types */ - $entity_types['migration'] - ->setClass('Drupal\migrate_drupal\Entity\Migration') - ->setHandlerClass('storage', 'Drupal\migrate_drupal\MigrationStorage'); -} - -/** * Implements hook_help(). */ function migrate_drupal_help($route_name, RouteMatchInterface $route_match) { diff --git a/core/modules/migrate_drupal/migrate_drupal.services.yml b/core/modules/migrate_drupal/migrate_drupal.services.yml index 684ecb8..00730b4 100644 --- a/core/modules/migrate_drupal/migrate_drupal.services.yml +++ b/core/modules/migrate_drupal/migrate_drupal.services.yml @@ -1,7 +1,4 @@ services: - plugin.manager.migrate.load: - class: Drupal\migrate\Plugin\MigratePluginManager - arguments: [load, '@container.namespaces', '@cache.discovery', '@module_handler'] plugin.manager.migrate.cckfield: class: Drupal\migrate\Plugin\MigratePluginManager arguments: [cckfield, '@container.namespaces', '@cache.discovery', '@module_handler'] diff --git a/core/modules/migrate_drupal/src/Entity/Migration.php b/core/modules/migrate_drupal/src/Entity/Migration.php deleted file mode 100644 index 4a34c16..0000000 --- a/core/modules/migrate_drupal/src/Entity/Migration.php +++ /dev/null @@ -1,38 +0,0 @@ -load && !$this->loadPlugin) { - $this->loadPlugin = \Drupal::service('plugin.manager.migrate.load')->createInstance($this->load['plugin'], $this->load, $this); - } - return $this->loadPlugin; - } - -} diff --git a/core/modules/migrate_drupal/src/Entity/MigrationInterface.php b/core/modules/migrate_drupal/src/Entity/MigrationInterface.php deleted file mode 100644 index 4690c3c..0000000 --- a/core/modules/migrate_drupal/src/Entity/MigrationInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -cckPluginManager = $cck_plugin_manager; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('config.factory'), - $container->get('uuid'), - $container->get('language_manager'), - $container->get('entity.query.config'), - $container->get('plugin.manager.migrate.cckfield') - ); - } - - /** - * {@inheritdoc} - */ - public function loadMultiple(array $ids = NULL) { - $ids_to_load = array(); - $dynamic_ids = array(); - if (isset($ids)) { - foreach ($ids as $id) { - // Evaluate whether or not this migration is dynamic in the form of - // migration_id:* to load all the additional migrations. - if (($n = strpos($id, ':')) !== FALSE) { - $base_id = substr($id, 0, $n); - $ids_to_load[] = $base_id; - // Get the ids of the additional migrations. - $sub_id = substr($id, $n + 1); - if ($sub_id == '*') { - // If the id of the additional migration is '*', get all of them. - $dynamic_ids[$base_id] = NULL; - } - elseif (!isset($dynamic_ids[$base_id]) || is_array($dynamic_ids[$base_id])) { - $dynamic_ids[$base_id][] = $sub_id; - } - } - else { - $ids_to_load[] = $id; - } - } - $ids = array_flip($ids); - } - else { - $ids_to_load = NULL; - } - - /** @var \Drupal\migrate_drupal\Entity\MigrationInterface[] $entities */ - $entities = parent::loadMultiple($ids_to_load); - if (!isset($ids)) { - // Changing the array being foreach()'d is not a good idea. - $return = array(); - foreach ($entities as $entity_id => $entity) { - if ($plugin = $entity->getLoadPlugin()) { - $new_entities = $plugin->loadMultiple($this); - $this->postLoad($new_entities); - $this->getDynamicIds($dynamic_ids, $new_entities); - $return += $new_entities; - } - else { - $return[$entity_id] = $entity; - } - } - $entities = $return; - } - else { - foreach ($dynamic_ids as $base_id => $sub_ids) { - $entity = $entities[$base_id]; - if ($plugin = $entity->getLoadPlugin()) { - unset($entities[$base_id]); - $new_entities = $plugin->loadMultiple($this, $sub_ids); - $this->postLoad($new_entities); - if (!isset($sub_ids)) { - unset($dynamic_ids[$base_id]); - $this->getDynamicIds($dynamic_ids, $new_entities); - } - $entities += $new_entities; - } - } - } - - // Allow modules providing cck field plugins to alter the required - // migrations to assist with the migration a custom field type. - $this->applyCckFieldProcessors($entities); - - // Build an array of dependencies and set the order of the migrations. - return $this->buildDependencyMigration($entities, $dynamic_ids); - } - - /** - * Extract the dynamic id mapping from entities loaded by plugin. - * - * @param array $dynamic_ids - * Get the dynamic migration ids. - * @param array $entities - * An array of entities. - */ - protected function getDynamicIds(array &$dynamic_ids, array $entities) { - foreach (array_keys($entities) as $new_id) { - list($base_id, $sub_id) = explode(':', $new_id, 2); - $dynamic_ids[$base_id][] = $sub_id; - } - } - - /** - * {@inheritdoc} - */ - public function save(EntityInterface $entity) { - if (strpos($entity->id(), ':') !== FALSE) { - throw new EntityStorageException("Dynamic migration '{$entity->id()}' can't be saved"); - } - return parent::save($entity); - } - - /** - * Allow any field type plugins to adjust the migrations as required. - * - * @param \Drupal\migrate\Entity\Migration[] $entities - * An array of migration entities. - */ - protected function applyCckFieldProcessors(array $entities) { - $method_map = $this->getMigrationPluginMethodMap(); - - foreach ($entities as $entity_id => $migration) { - // Allow field plugins to process the required migrations. - if (isset($method_map[$entity_id])) { - $method = $method_map[$entity_id]; - $cck_plugins = $this->getCckFieldPlugins(); - - array_walk($cck_plugins, function ($plugin) use ($method, $migration) { - $plugin->$method($migration); - }); - } - - // If this is a CCK bundle migration, allow the cck field plugins to add - // any field type processing. - $source_plugin = $migration->getSourcePlugin(); - if ($source_plugin instanceof CckFieldMigrateSourceInterface && strpos($entity_id, SourcePluginBase::DERIVATIVE_SEPARATOR)) { - $plugins = $this->getCckFieldPlugins(); - foreach ($source_plugin->fieldData() as $field_name => $data) { - if (isset($plugins[$data['type']])) { - $plugins[$data['type']]->processCckFieldValues($migration, $field_name, $data); - } - } - } - } - } - - /** - * Get an array of loaded cck field plugins. - * - * @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[] - * An array of cck field process plugins. - */ - protected function getCckFieldPlugins() { - if (!isset($this->cckFieldPlugins)) { - $this->cckFieldPlugins = []; - foreach ($this->cckPluginManager->getDefinitions() as $definition) { - $this->cckFieldPlugins[$definition['id']] = $this->cckPluginManager->createInstance($definition['id']); - } - } - return $this->cckFieldPlugins; - } - - /** - * Provides a map between migration ids and the cck field plugin method. - * - * @return array - * The map between migrations and cck field plugin processing methods. - */ - protected function getMigrationPluginMethodMap() { - return [ - 'd6_field' => 'processField', - 'd6_field_instance' => 'processFieldInstance', - 'd6_field_instance_widget_settings' => 'processFieldWidget', - 'd6_field_formatter_settings' => 'processFieldFormatter', - ]; - } - -} diff --git a/core/modules/migrate_drupal/src/Plugin/CckFieldMigrateSourceInterface.php b/core/modules/migrate_drupal/src/Plugin/CckFieldMigrateSourceInterface.php deleted file mode 100644 index 469d29f..0000000 --- a/core/modules/migrate_drupal/src/Plugin/CckFieldMigrateSourceInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -migration = $migration; - $source_plugin = $this->migration->getSourcePlugin(); - if (!$source_plugin instanceof SourceEntityInterface) { - throw new MigrateException('Migrations with a load plugin using LoadEntity should have an entity as source.'); - } - if ($source_plugin->bundleMigrationRequired() && empty($configuration['bundle_migration'])) { - throw new MigrateException("Source plugin '{$source_plugin->getPluginId()}' requires the bundle_migration key to be set."); - } - } - - /** - * {@inheritdoc} - */ - public function load(EntityStorageInterface $storage, $sub_id) { - $entities = $this->loadMultiple($storage, array($sub_id)); - return isset($entities[$sub_id]) ? $entities[$sub_id] : FALSE; - } - - /** - * {@inheritdoc} - */ - public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = NULL) { - if (isset($this->configuration['bundle_migration'])) { - /** @var \Drupal\migrate\Entity\MigrationInterface $bundle_migration */ - $bundle_migration = $storage->load($this->configuration['bundle_migration']); - $source_id = array_keys($bundle_migration->getSourcePlugin()->getIds())[0]; - $this->bundles = array(); - foreach ($bundle_migration->getSourcePlugin()->getIterator() as $row) { - $this->bundles[] = $row[$source_id]; - } - } - else { - // This entity type has no bundles ('user', 'feed', etc). - $this->bundles = array($this->migration->getSourcePlugin()->entityTypeId()); - } - $sub_ids_to_load = isset($sub_ids) ? array_intersect($this->bundles, $sub_ids) : $this->bundles; - $migrations = array(); - foreach ($sub_ids_to_load as $id) { - $values = $this->migration->toArray(); - $values['id'] = $this->migration->id() . ':' . $id; - $values['source']['bundle'] = $id; - /** @var \Drupal\migrate_drupal\Entity\MigrationInterface $migration */ - $migration = $storage->create($values); - try { - $migration->getSourcePlugin()->checkRequirements(); - $source_plugin = $migration->getSourcePlugin(); - - if ($source_plugin instanceof CckFieldMigrateSourceInterface) { - foreach ($source_plugin->fieldData() as $field_name => $data) { - $migration->setProcessOfProperty($field_name, $field_name); - } - } - else { - $fields = array_keys($migration->getSourcePlugin()->fields()); - $migration->setProcess($migration->getProcess() + array_combine($fields, $fields)); - } - $migrations[$migration->id()] = $migration; - } - catch (RequirementsException $e) { - - } - } - - return $migrations; - } - -} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/EmptySource.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/EmptySource.php index 47e7c82..60a8843 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/EmptySource.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/EmptySource.php @@ -10,7 +10,7 @@ use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Entity\DependencyTrait; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\migrate_drupal\Entity\MigrationInterface; +use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Plugin\migrate\source\EmptySource as BaseEmptySource; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; diff --git a/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php index f007b31..3f468ec 100644 --- a/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php +++ b/core/modules/migrate_drupal/src/Tests/MigrateDrupalTestBase.php @@ -56,9 +56,9 @@ protected function getDumpDirectory() { */ protected function installMigrations($version) { $migration_templates = \Drupal::service('migrate.template_storage')->findTemplatesByTag($version); - foreach ($migration_templates as $template) { + $migrations = \Drupal::service('migrate.migration_builder')->createMigrations($migration_templates); + foreach ($migrations as $migration) { try { - $migration = Migration::create($template); $migration->save(); } catch (PluginNotFoundException $e) { diff --git a/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php b/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php index bccd740..1cb07d6 100644 --- a/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php +++ b/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php @@ -7,7 +7,7 @@ namespace Drupal\migrate_drupal\Tests; -use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\Entity\Migration; use Drupal\simpletest\TestBase; /** @@ -59,9 +59,9 @@ public function testDrupal() { } // Run every migration in the order specified by the storage controller. - foreach (entity_load_multiple('migration', static::$migrations) as $migration) { - (new MigrateExecutable($migration, $this))->import(); - } + $migrations = Migration::loadMultiple(static::$migrations); + array_walk($migrations, [$this, 'executeMigration']); + foreach ($classes as $class) { $test_object = new $class($this->testId); $test_object->databasePrefix = $this->databasePrefix; diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php index 48f1d6e..6f08cfc 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php @@ -101,14 +101,14 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase { 'd6_menu_settings', 'd6_menu', 'd6_menu_links', - 'd6_node_revision', + 'd6_node_revision:*', 'd6_node_setting_promote', 'd6_node_setting_status', 'd6_node_setting_sticky', - 'd6_node', + 'd6_node:*', 'd6_node_settings', 'd6_node_type', - 'd6_profile_values:user', + 'd6_profile_values', 'd6_search_page', 'd6_search_settings', 'd6_simpletest_settings', diff --git a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php index d4b3a53..59caa80 100644 --- a/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php +++ b/core/modules/migrate_drupal/src/Tests/dependencies/MigrateDependenciesTest.php @@ -8,6 +8,7 @@ namespace Drupal\migrate_drupal\Tests\dependencies; use Drupal\Component\Utility\SafeMarkup; +use Drupal\migrate\Entity\Migration; use Drupal\migrate\MigrateExecutable; use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; @@ -15,8 +16,6 @@ * Ensure the consistency among the dependencies for migrate. * * @group migrate_drupal - * @group Drupal - * @group migrate_drupal */ class MigrateDependenciesTest extends MigrateDrupal6TestBase { @@ -26,12 +25,24 @@ class MigrateDependenciesTest extends MigrateDrupal6TestBase { * Tests that the order is correct when loading several migrations. */ public function testMigrateDependenciesOrder() { - $migration_items = array('d6_comment', 'd6_filter_format', 'd6_node'); - $migrations = entity_load_multiple('migration', $migration_items); - $expected_order = array('d6_filter_format', 'd6_node', 'd6_comment'); + $migration_items = array('d6_comment', 'd6_filter_format', 'd6_node__page'); + $migrations = Migration::loadMultiple($migration_items); + $expected_order = array('d6_filter_format', 'd6_node__page', 'd6_comment'); $this->assertIdentical(array_keys($migrations), $expected_order); $expected_requirements = array( - 'd6_node', + // d6_comment depends on d6_node:*, which the storage controller expands + // into every variant of d6_node created by the MigrationBuilder. + 'd6_node__article', + 'd6_node__company', + 'd6_node__employee', + 'd6_node__event', + 'd6_node__page', + 'd6_node__sponsor', + 'd6_node__story', + 'd6_node__test_event', + 'd6_node__test_page', + 'd6_node__test_planet', + 'd6_node__test_story', 'd6_node_type', 'd6_node_settings', 'd6_filter_format', diff --git a/core/modules/migrate_drupal/tests/src/Unit/MigrationStorageTest.php b/core/modules/migrate_drupal/tests/src/Unit/MigrationStorageTest.php deleted file mode 100644 index 4c26509..0000000 --- a/core/modules/migrate_drupal/tests/src/Unit/MigrationStorageTest.php +++ /dev/null @@ -1,78 +0,0 @@ - 'test_migration', 'migrationClass' => 'Drupal\migrate_drupal\Entity\Migration'); - - /** - * Test that the entity load hooks are called on dynamic migrations. - * - * @dataProvider entityIdsDataProvider - */ - public function testMigrationStorage($entity_ids) { - $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); - $entity_type - ->expects($this->exactly(2)) - ->method('isStaticallyCacheable') - ->willReturn(FALSE); - - $load_plugin = $this->getMock('Drupal\migrate_drupal\Plugin\MigrateLoadInterface'); - $load_plugin - ->expects($this->once()) - ->method('loadMultiple') - ->willReturn([]); - - $migration = $this->getMigration(); - $migration - ->expects($this->once()) - ->method('getLoadPlugin') - ->willReturn($load_plugin); - - $storage = $this->getMock('Drupal\migrate_drupal\TestMigrationStorage', ['postLoad', 'doLoadMultiple'], [$entity_type]); - $storage - ->expects($this->exactly(2)) - ->method('postLoad'); - $storage - ->expects($this->once()) - ->method('doLoadMultiple') - ->willReturn(['test_migration' => $migration]); - - $storage->loadMultiple($entity_ids); - } - - /** - * The data provider for migration storage. - * - * @return array - * The entity ids. - */ - public function entityIdsDataProvider() { - return [ - [['test_migration:bundle']], - [NULL], - ]; - } - -} - -namespace Drupal\migrate_drupal; - -class TestMigrationStorage extends MigrationStorage { - public function __construct($entity_type) { - $this->entityType = $entity_type; - } -} diff --git a/core/modules/node/migration_templates/d6_node.yml b/core/modules/node/migration_templates/d6_node.yml index 76b34d8..779bda1 100644 --- a/core/modules/node/migration_templates/d6_node.yml +++ b/core/modules/node/migration_templates/d6_node.yml @@ -55,3 +55,4 @@ migration_dependencies: optional: - d6_field_instance_widget_settings - d6_field_formatter_settings + - d6_upload_field_instance diff --git a/core/modules/node/src/Plugin/migrate/builder/d6/Node.php b/core/modules/node/src/Plugin/migrate/builder/d6/Node.php index 6bc0966..1fcd488 100644 --- a/core/modules/node/src/Plugin/migrate/builder/d6/Node.php +++ b/core/modules/node/src/Plugin/migrate/builder/d6/Node.php @@ -51,6 +51,7 @@ public function buildMigrations(array $template) { $node_type = $row->getSourceProperty('type'); $values = $template; $values['id'] = $template['id'] . '__' . $node_type; + $values['source']['node_type'] = $node_type; $migration = Migration::create($values); $fields = $this->getSourcePlugin('d6_field_instance', ['node_type' => $node_type] + $template['source']); diff --git a/core/modules/node/src/Plugin/migrate/source/d6/Node.php b/core/modules/node/src/Plugin/migrate/source/d6/Node.php index 29f6745..b8a4d7d 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/Node.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/Node.php @@ -8,7 +8,6 @@ namespace Drupal\node\Plugin\migrate\source\d6; use Drupal\migrate\Row; -use Drupal\migrate\Plugin\SourceEntityInterface; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** @@ -18,7 +17,7 @@ * id = "d6_node" * ) */ -class Node extends DrupalSqlBase implements SourceEntityInterface { +class Node extends DrupalSqlBase { /** * The join options between the node and the node_revisions table. @@ -125,15 +124,6 @@ public function prepareRow(Row $row) { if ($this->moduleExists('content') && $this->getModuleSchemaVersion('content') >= 6001) { foreach ($this->getFieldValues($row) as $field => $values) { - foreach ($values as $delta => $item) { - foreach ($item as $column => $value) { - if (strpos($column, $field) === 0) { - $key = substr($column, strlen($field) + 1); - $values[$delta][$key] = $value; - unset($values[$delta][$column]); - } - } - } $row->setSourceProperty($field, $values); } } @@ -214,28 +204,39 @@ protected function getCckData(array $field, Row $node) { $db = $this->getDatabase()->schema(); if ($db->tableExists($field_table)) { - $query = $this->select($field_table, 't')->fields('t'); + $query = $this->select($field_table, 't'); // If the delta column does not exist, add it as an expression to // normalize the query results. - if (!$db->fieldExists($field_table, 'delta')) { + if ($db->fieldExists($field_table, 'delta')) { + $query->addField('t', 'delta'); + } + else { $query->addExpression(0, 'delta'); } } elseif ($db->tableExists($node_table)) { $query = $this->select($node_table, 't'); - // Add every DB column CCK knows about. - foreach (array_keys($field['db_columns']) as $column) { - $query->addField('t', $field['field_name'] . '_' . $column); - } - // Every row should have a delta of 0. $query->addExpression(0, 'delta'); } if (isset($query)) { + $columns = array_keys($field['db_columns']); + + // Add every column in the field's schema. + foreach ($columns as $column) { + $query->addField('t', $field['field_name'] . '_' . $column, $column); + } + return $query + // This call to isNotNull() is a kludge which relies on the convention + // that CCK field schemas usually define their most important + // column first. A better way would be to allow cckfield plugins to + // alter the query directly before it's run, but this will do for + // the time being. + ->isNotNull($field['field_name'] . '_' . $columns[0]) ->condition('nid', $node->getSourceProperty('nid')) ->condition('vid', $node->getSourceProperty('vid')) ->execute() @@ -255,18 +256,4 @@ public function getIds() { return $ids; } - /** - * {@inheritdoc} - */ - public function bundleMigrationRequired() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function entityTypeId() { - return 'node'; - } - } diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php index 7b19508..1673c9e 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeRevisionTest.php @@ -8,6 +8,7 @@ namespace Drupal\node\Tests\Migrate\d6; use Drupal\Core\Database\Database; +use Drupal\migrate\Entity\Migration; /** * Node content revisions migration. @@ -23,7 +24,7 @@ protected function setUp() { parent::setUp(); $id_mappings = array( - 'd6_node' => array( + 'd6_node:*' => array( array(array(1), array(1)), ), ); @@ -37,7 +38,8 @@ protected function setUp() { $user->save(); } - $this->executeMigration('d6_node_revision'); + $migrations = Migration::loadMultiple(['d6_node_revision:*']); + array_walk($migrations, [$this, 'executeMigration']); } /** diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php index 8b0b534..1c3f0c2 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php @@ -7,7 +7,7 @@ namespace Drupal\node\Tests\Migrate\d6; -use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\Entity\Migration; use Drupal\Core\Database\Database; use Drupal\node\Entity\Node; @@ -23,13 +23,13 @@ class MigrateNodeTest extends MigrateNodeTestBase { */ protected function setUp() { parent::setUp(); - /** @var \Drupal\migrate\entity\Migration $migration */ - $migration = entity_load('migration', 'd6_node'); - $executable = new MigrateExecutable($migration, $this); - $executable->import(); + // Each node type is imported separately. In this test, we're asserting + // on story and test_planet nodes. + $this->executeMigration('d6_node__test_planet'); + $this->executeMigration('d6_node__story'); // This is required for the second import below. - db_truncate($migration->getIdMap()->mapTableName())->execute(); + \Drupal::database()->truncate(Migration::load('d6_node__story')->getIdMap()->mapTableName())->execute(); $this->standalone = TRUE; } @@ -75,10 +75,8 @@ public function testNode() { ->condition('delta', 1) ->execute(); - /** @var \Drupal\migrate\entity\Migration $migration */ - $migration = entity_load('migration', 'd6_node'); - $executable = new MigrateExecutable($migration, $this); - $executable->import(); + $migration = Migration::load('d6_node__story'); + $this->executeMigration($migration); $node = Node::load(1); $this->assertIdentical('New node title', $node->getTitle()); diff --git a/core/modules/taxonomy/config/schema/taxonomy.source.schema.yml b/core/modules/taxonomy/config/schema/taxonomy.source.schema.yml index 39f81fd..8fc72ef 100644 --- a/core/modules/taxonomy/config/schema/taxonomy.source.schema.yml +++ b/core/modules/taxonomy/config/schema/taxonomy.source.schema.yml @@ -23,3 +23,19 @@ migrate.source.d6_taxonomy_vocabulary_per_type: constants: type: migrate_entity_constant label: 'Constants' + +migrate.source.d6_term_node: + type: migrate_source_sql + label: 'Drupal 6 terms per node' + mapping: + vid: + type: integer + label: 'Vocabulary ID' + +migrate.source.d6_term_node_revision: + type: migrate_source_sql + label: 'Drupal 6 terms per node revision' + mapping: + vid: + type: integer + label: 'Vocabulary ID' diff --git a/core/modules/taxonomy/src/Plugin/migrate/load/d6/LoadTermNode.php b/core/modules/taxonomy/src/Plugin/migrate/load/d6/LoadTermNode.php deleted file mode 100644 index cbdee31..0000000 --- a/core/modules/taxonomy/src/Plugin/migrate/load/d6/LoadTermNode.php +++ /dev/null @@ -1,64 +0,0 @@ -load('d6_taxonomy_vocabulary'); - $migrate_executable = new MigrateExecutable($bundle_migration, new MigrateMessage()); - $process = array_intersect_key($bundle_migration->get('process'), $bundle_migration->getDestinationPlugin()->getIds()); - $migrations = array(); - $vid_map = array(); - foreach ($bundle_migration->getIdMap() as $key => $value) { - $old_vid = unserialize($key)['sourceid1']; - $new_vid = $value['destid1']; - $vid_map[$old_vid] = $new_vid; - } - foreach ($bundle_migration->getSourcePlugin()->getIterator() as $source_row) { - $row = new Row($source_row, $source_row); - $migrate_executable->processRow($row, $process); - $old_vid = $source_row['vid']; - $new_vid = $row->getDestinationProperty('vid'); - $vid_map[$old_vid] = $new_vid; - } - foreach ($vid_map as $old_vid => $new_vid) { - $values = $this->migration->toArray(); - $migration_id = $this->migration->id() . ':' . $old_vid; - $values['id'] = $migration_id; - $values['source']['vid'] = $old_vid; - $values['process'][$new_vid] = 'tid'; - $migrations[$migration_id] = $storage->create($values);; - } - - return $migrations; - } - -} diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php index 4629bb3..0f87bb9 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/TermNode.php @@ -7,7 +7,6 @@ namespace Drupal\taxonomy\Plugin\migrate\source\d6; -use Drupal\migrate\Plugin\SourceEntityInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; @@ -19,7 +18,7 @@ * source_provider = "taxonomy" * ) */ -class TermNode extends DrupalSqlBase implements SourceEntityInterface { +class TermNode extends DrupalSqlBase { /** * The join options between the node and the term node table. @@ -76,18 +75,4 @@ public function getIds() { return $ids; } - /** - * {@inheritdoc} - */ - public function bundleMigrationRequired() { - return TRUE; - } - - /** - * {@inheritdoc} - */ - public function entityTypeId() { - return 'taxonomy_term'; - } - } diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeRevisionTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeRevisionTest.php index 3cd55d2..94d0aba 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeRevisionTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeRevisionTest.php @@ -7,7 +7,7 @@ namespace Drupal\taxonomy\Tests\Migrate\d6; -use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\Entity\Migration; /** * Upgrade taxonomy term node associations. @@ -22,20 +22,17 @@ class MigrateTermNodeRevisionTest extends MigrateTermNodeTestBase { protected function setUp() { parent::setUp(); $id_mappings = array( - 'd6_term_node' => array( + 'd6_term_node:*' => array( array(array(2), array(1)), ), - 'd6_node_revision' => array( + 'd6_node_revision:*' => array( array(array(2), array(2)), ), ); $this->prepareMigrations($id_mappings); - /** @var \Drupal\migrate\entity\Migration $migration */ - $migrations = entity_load_multiple('migration', array('d6_term_node_revision:*')); - foreach ($migrations as $migration) { - $executable = new MigrateExecutable($migration, $this); - $executable->import(); - } + + $migrations = Migration::loadMultiple(['d6_term_node_revision:*']); + array_walk($migrations, [$this, 'executeMigration']); } /** diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php index 6dd5dfd..6f75a53 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests\Migrate\d6; +use Drupal\migrate\Entity\Migration; use Drupal\migrate\MigrateExecutable; use Drupal\node\Entity\Node; @@ -22,12 +23,17 @@ class MigrateTermNodeTest extends MigrateTermNodeTestBase { */ protected function setUp() { parent::setUp(); - /** @var \Drupal\migrate\entity\Migration $migration */ - $migrations = entity_load_multiple('migration', array('d6_term_node:*')); - foreach ($migrations as $migration) { - $executable = new MigrateExecutable($migration, $this); - $executable->import(); - } + $id_mappings = array( + 'd6_node:*' => array( + array( + array(0), + array(0), + ), + ), + ); + $this->prepareMigrations($id_mappings); + $migrations = Migration::loadMultiple(['d6_term_node:*']); + array_walk($migrations, [$this, 'executeMigration']); } /** diff --git a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php b/core/modules/text/src/Plugin/migrate/cckfield/TextField.php index e7a56f0..ba3fdac 100644 --- a/core/modules/text/src/Plugin/migrate/cckfield/TextField.php +++ b/core/modules/text/src/Plugin/migrate/cckfield/TextField.php @@ -39,34 +39,36 @@ public function getFieldFormatterMap() { * {@inheritdoc} */ public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { - // The data is stored differently depending on whether we're using - // db storage. - $value_key = $data['db_storage'] ? $field_name : "$field_name/value"; - $format_key = $data['db_storage'] ? $field_name . '_format' : "$field_name/format" ; - - $migration->setProcessOfProperty("$field_name/value", $value_key); - - // See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(), - // signature_format for an example of the YAML that represents this - // process array. - $process = [ - [ - 'plugin' => 'static_map', - 'bypass' => TRUE, - 'source' => $format_key, - 'map' => [0 => NULL] - ], - [ - 'plugin' => 'skip_on_empty', - 'method' => 'process', - ], - [ - 'plugin' => 'migration', - 'migration' => 'd6_filter_format', - 'source' => $format_key, - ], - ]; - $migration->mergeProcessOfProperty("$field_name/format", $process); + $process = array( + array( + 'plugin' => 'iterator', + 'source' => $field_name, + // See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(), + // signature_format for an example of the YAML that represents this + // process array. + 'process' => [ + 'value' => 'value', + 'format' => [ + [ + 'plugin' => 'static_map', + 'bypass' => TRUE, + 'source' => 'format', + 'map' => [0 => NULL], + ], + [ + 'plugin' => 'skip_on_empty', + 'method' => 'process', + ], + [ + 'plugin' => 'migration', + 'migration' => 'd6_filter_format', + 'source' => 'format', + ], + ], + ], + ), + ); + $migration->setProcessOfProperty($field_name, $process); } } diff --git a/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php index 9c17eff..66c04c3 100644 --- a/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php +++ b/core/modules/user/src/Plugin/migrate/source/d6/ProfileFieldValues.php @@ -8,7 +8,6 @@ namespace Drupal\user\Plugin\migrate\source\d6; use Drupal\migrate\Row; -use Drupal\migrate\Plugin\SourceEntityInterface; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** @@ -19,7 +18,7 @@ * source_provider = "profile" * ) */ -class ProfileFieldValues extends DrupalSqlBase implements SourceEntityInterface { +class ProfileFieldValues extends DrupalSqlBase { /** * {@inheritdoc} @@ -97,18 +96,4 @@ public function getIds() { ); } - /** - * {@inheritdoc} - */ - public function bundleMigrationRequired() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function entityTypeId() { - return 'user'; - } - } diff --git a/core/modules/user/src/Plugin/migrate/source/d6/User.php b/core/modules/user/src/Plugin/migrate/source/d6/User.php index c347149..59c3229 100644 --- a/core/modules/user/src/Plugin/migrate/source/d6/User.php +++ b/core/modules/user/src/Plugin/migrate/source/d6/User.php @@ -7,7 +7,6 @@ namespace Drupal\user\Plugin\migrate\source\d6; -use Drupal\migrate\Plugin\SourceEntityInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; @@ -18,7 +17,7 @@ * id = "d6_user" * ) */ -class User extends DrupalSqlBase implements SourceEntityInterface { +class User extends DrupalSqlBase { /** * {@inheritdoc} @@ -134,18 +133,4 @@ protected function baseFields() { return $fields; } - /** - * {@inheritdoc} - */ - public function bundleMigrationRequired() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function entityTypeId() { - return 'user'; - } - } diff --git a/core/modules/user/src/Tests/Migrate/d6/MigrateUserProfileValuesTest.php b/core/modules/user/src/Tests/Migrate/d6/MigrateUserProfileValuesTest.php index d44f737..bcb29f2 100644 --- a/core/modules/user/src/Tests/Migrate/d6/MigrateUserProfileValuesTest.php +++ b/core/modules/user/src/Tests/Migrate/d6/MigrateUserProfileValuesTest.php @@ -130,8 +130,7 @@ protected function setUp() { $user->save(); } - $migration_format = entity_load('migration', 'd6_profile_values:user'); - $this->executeMigration($migration_format); + $this->executeMigration('d6_profile_values'); } /**