Commit d15ee714 authored by catch's avatar catch

Issue #2845486 by Jo Fitzgerald, quietone, gaurav.kapoor, ohthehugemanatee,...

Issue #2845486 by Jo Fitzgerald, quietone, gaurav.kapoor, ohthehugemanatee, heddn, Yogesh Pawar, catch, shabana.navas, phenaproxima, mikeryan: Rename Migration process plugin and add documentation
parent 13e8aca2
...@@ -7,7 +7,7 @@ source: ...@@ -7,7 +7,7 @@ source:
process: process:
iid: iid iid: iid
fid: fid:
plugin: migration plugin: migration_lookup
migration: d6_aggregator_feed migration: d6_aggregator_feed
source: fid source: fid
title: title title: title
......
...@@ -7,7 +7,7 @@ source: ...@@ -7,7 +7,7 @@ source:
process: process:
iid: iid iid: iid
fid: fid:
plugin: migration plugin: migration_lookup
migration: d7_aggregator_feed migration: d7_aggregator_feed
source: fid source: fid
title: title title: title
......
...@@ -8,7 +8,7 @@ process: ...@@ -8,7 +8,7 @@ process:
id: bid id: bid
info: info info: info
'body/format': 'body/format':
plugin: migration plugin: migration_lookup
migration: d6_filter_format migration: d6_filter_format
source: format source: format
'body/value': body 'body/value': body
......
...@@ -8,7 +8,7 @@ process: ...@@ -8,7 +8,7 @@ process:
id: bid id: bid
info: info info: info
'body/format': 'body/format':
plugin: migration plugin: migration_lookup
migration: d7_filter_format migration: d7_filter_format
source: format source: format
'body/value': body 'body/value': body
......
...@@ -14,7 +14,7 @@ process: ...@@ -14,7 +14,7 @@ process:
method: process method: process
source: plid source: plid
- -
plugin: migration plugin: migration_lookup
migration: d6_book migration: d6_book
destination: destination:
plugin: book plugin: book
......
...@@ -11,7 +11,7 @@ process: ...@@ -11,7 +11,7 @@ process:
# the cid field to allow incremental migrations. # the cid field to allow incremental migrations.
cid: cid cid: cid
pid: pid:
plugin: migration plugin: migration_lookup
migration: d6_comment migration: d6_comment
source: pid source: pid
entity_id: nid entity_id: nid
...@@ -32,7 +32,7 @@ process: ...@@ -32,7 +32,7 @@ process:
thread: thread thread: thread
'comment_body/value': comment 'comment_body/value': comment
'comment_body/format': 'comment_body/format':
plugin: migration plugin: migration_lookup
migration: d6_filter_format migration: d6_filter_format
source: format source: format
destination: destination:
......
...@@ -11,7 +11,7 @@ process: ...@@ -11,7 +11,7 @@ process:
# the cid field to allow incremental migrations. # the cid field to allow incremental migrations.
cid: cid cid: cid
pid: pid:
plugin: migration plugin: migration_lookup
migration: d7_comment migration: d7_comment
source: pid source: pid
entity_id: nid entity_id: nid
......
...@@ -11,7 +11,7 @@ process: ...@@ -11,7 +11,7 @@ process:
user_default_enabled: contact_default_status user_default_enabled: contact_default_status
'flood/limit': contact_hourly_threshold 'flood/limit': contact_hourly_threshold
default_form: default_form:
plugin: migration plugin: migration_lookup
migration: contact_category migration: contact_category
source: default_category source: default_category
destination: destination:
......
...@@ -11,7 +11,7 @@ process: ...@@ -11,7 +11,7 @@ process:
user_default_enabled: contact_default_status user_default_enabled: contact_default_status
'flood/limit': contact_threshold_limit 'flood/limit': contact_threshold_limit
default_form: default_form:
plugin: migration plugin: migration_lookup
migration: contact_category migration: contact_category
source: default_category source: default_category
destination: destination:
......
...@@ -15,7 +15,7 @@ process: ...@@ -15,7 +15,7 @@ process:
# field migration. # field migration.
field_type_exists: field_type_exists:
- -
plugin: migration plugin: migration_lookup
migration: d6_field migration: d6_field
source: source:
- field_name - field_name
...@@ -29,7 +29,7 @@ process: ...@@ -29,7 +29,7 @@ process:
entity_type: 'constants/entity_type' entity_type: 'constants/entity_type'
bundle: bundle:
- -
plugin: migration plugin: migration_lookup
migration: d6_node_type migration: d6_node_type
source: type_name source: type_name
- -
...@@ -37,7 +37,7 @@ process: ...@@ -37,7 +37,7 @@ process:
method: row method: row
view_mode: view_mode:
- -
plugin: migration plugin: migration_lookup
migration: d6_view_modes migration: d6_view_modes
source: source:
- view_mode - view_mode
......
...@@ -14,7 +14,7 @@ process: ...@@ -14,7 +14,7 @@ process:
# field migration. # field migration.
field_type_exists: field_type_exists:
- -
plugin: migration plugin: migration_lookup
migration: d6_field migration: d6_field
source: source:
- field_name - field_name
...@@ -29,7 +29,7 @@ process: ...@@ -29,7 +29,7 @@ process:
field_name: field_name field_name: field_name
bundle: bundle:
- -
plugin: migration plugin: migration_lookup
migration: d6_node_type migration: d6_node_type
source: type_name source: type_name
- -
......
...@@ -16,7 +16,7 @@ process: ...@@ -16,7 +16,7 @@ process:
# field migration. # field migration.
field_type_exists: field_type_exists:
- -
plugin: migration plugin: migration_lookup
migration: d6_field migration: d6_field
source: source:
- field_name - field_name
...@@ -29,7 +29,7 @@ process: ...@@ -29,7 +29,7 @@ process:
method: row method: row
bundle: bundle:
- -
plugin: migration plugin: migration_lookup
migration: d6_node_type migration: d6_node_type
source: type_name source: type_name
- -
......
...@@ -13,7 +13,7 @@ process: ...@@ -13,7 +13,7 @@ process:
# field migration. # field migration.
field_type_exists: field_type_exists:
- -
plugin: migration plugin: migration_lookup
migration: d7_field migration: d7_field
source: source:
- field_name - field_name
...@@ -29,7 +29,7 @@ process: ...@@ -29,7 +29,7 @@ process:
bundle: bundle bundle: bundle
view_mode: view_mode:
- -
plugin: migration plugin: migration_lookup
migration: d7_view_modes migration: d7_view_modes
source: source:
- entity_type - entity_type
......
...@@ -14,7 +14,7 @@ process: ...@@ -14,7 +14,7 @@ process:
# field migration. # field migration.
field_type_exists: field_type_exists:
- -
plugin: migration plugin: migration_lookup
migration: d7_field migration: d7_field
source: source:
- field_name - field_name
......
...@@ -13,7 +13,7 @@ process: ...@@ -13,7 +13,7 @@ process:
source: upload source: upload
process: process:
target_id: target_id:
plugin: migration plugin: migration_lookup
migration: d6_file migration: d6_file
source: fid source: fid
display: list display: list
......
...@@ -13,7 +13,7 @@ process: ...@@ -13,7 +13,7 @@ process:
entity_type: 'constants/entity_type' entity_type: 'constants/entity_type'
bundle: bundle:
- -
plugin: migration plugin: migration_lookup
migration: d6_node_type migration: d6_node_type
source: node_type source: node_type
- -
......
...@@ -18,7 +18,7 @@ process: ...@@ -18,7 +18,7 @@ process:
'topics/page_limit': forum_per_page 'topics/page_limit': forum_per_page
'topics/order': forum_order 'topics/order': forum_order
vocabulary: vocabulary:
plugin: migration plugin: migration_lookup
migration: d6_taxonomy_vocabulary migration: d6_taxonomy_vocabulary
source: forum_nav_vocabulary source: forum_nav_vocabulary
destination: destination:
......
...@@ -18,7 +18,7 @@ process: ...@@ -18,7 +18,7 @@ process:
'topics/page_limit': forum_per_page 'topics/page_limit': forum_per_page
'topics/order': forum_order 'topics/order': forum_order
vocabulary: vocabulary:
plugin: migration plugin: migration_lookup
migration: d7_taxonomy_vocabulary migration: d7_taxonomy_vocabulary
source: forum_nav_vocabulary source: forum_nav_vocabulary
destination: destination:
......
...@@ -10,7 +10,7 @@ process: ...@@ -10,7 +10,7 @@ process:
description: description description: description
menu_name: menu_name:
- -
plugin: migration plugin: migration_lookup
# The menu migration is in the system module. # The menu migration is in the system module.
migration: d6_menu migration: d6_menu
source: menu_name source: menu_name
......
...@@ -13,7 +13,7 @@ process: ...@@ -13,7 +13,7 @@ process:
description: description description: description
menu_name: menu_name:
- -
plugin: migration plugin: migration_lookup
migration: d7_menu migration: d7_menu
source: menu_name source: menu_name
- -
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* process: * process:
* uid: * uid:
* - * -
* plugin: migration * plugin: migration_lookup
* migration: users * migration: users
* source: author * source: author
* - * -
......
...@@ -2,16 +2,8 @@ ...@@ -2,16 +2,8 @@
namespace Drupal\migrate\Plugin\migrate\process; namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @trigger_error('The ' . __NAMESPACE__ . '\Migration is deprecated in
use Drupal\migrate\MigrateSkipProcessException; Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MigrationLookup', E_USER_DEPRECATED);
use Drupal\migrate\Plugin\MigratePluginManagerInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Calculates the value of a property based on a previous migration. * Calculates the value of a property based on a previous migration.
...@@ -21,156 +13,8 @@ ...@@ -21,156 +13,8 @@
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "migration" * id = "migration"
* ) * )
*
* @deprecated in Drupal 8.3.x and will be removed in Drupal 9.0.x.
* Use \Drupal\migrate\Plugin\migrate\process\MigrationLookup instead.
*/ */
class Migration extends ProcessPluginBase implements ContainerFactoryPluginInterface { class Migration extends MigrationLookup { }
/**
* The process plugin manager.
*
* @var \Drupal\migrate\Plugin\MigratePluginManager
*/
protected $processPluginManager;
/**
* The migration plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
*/
protected $migrationPluginManager;
/**
* The migration to be executed.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManagerInterface $process_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrationPluginManager = $migration_plugin_manager;
$this->migration = $migration;
$this->processPluginManager = $process_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$migration,
$container->get('plugin.manager.migration'),
$container->get('plugin.manager.migrate.process')
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$migration_ids = $this->configuration['migration'];
if (!is_array($migration_ids)) {
$migration_ids = [$migration_ids];
}
if (!is_array($value)) {
$value = [$value];
}
$this->skipOnEmpty($value);
$self = FALSE;
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
$destination_ids = NULL;
$source_id_values = [];
$migrations = $this->migrationPluginManager->createInstances($migration_ids);
foreach ($migrations as $migration_id => $migration) {
if ($migration_id == $this->migration->id()) {
$self = TRUE;
}
if (isset($this->configuration['source_ids'][$migration_id])) {
$configuration = ['source' => $this->configuration['source_ids'][$migration_id]];
$source_id_values[$migration_id] = $this->processPluginManager
->createInstance('get', $configuration, $this->migration)
->transform(NULL, $migrate_executable, $row, $destination_property);
}
else {
$source_id_values[$migration_id] = $value;
}
// Break out of the loop as soon as a destination ID is found.
if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) {
break;
}
}
if (!$destination_ids && !empty($this->configuration['no_stub'])) {
return NULL;
}
if (!$destination_ids && ($self || isset($this->configuration['stub_id']) || count($migrations) == 1)) {
// If the lookup didn't succeed, figure out which migration will do the
// stubbing.
if ($self) {
$migration = $this->migration;
}
elseif (isset($this->configuration['stub_id'])) {
$migration = $migrations[$this->configuration['stub_id']];
}
else {
$migration = reset($migrations);
}
$destination_plugin = $migration->getDestinationPlugin(TRUE);
// Only keep the process necessary to produce the destination ID.
$process = $migration->getProcess();
// We already have the source ID values but need to key them for the Row
// constructor.
$source_ids = $migration->getSourcePlugin()->getIds();
$values = [];
foreach (array_keys($source_ids) as $index => $source_id) {
$values[$source_id] = $source_id_values[$migration->id()][$index];
}
$stub_row = new Row($values + $migration->getSourceConfiguration(), $source_ids, TRUE);
// Do a normal migration with the stub row.
$migrate_executable->processRow($stub_row, $process);
$destination_ids = [];
try {
$destination_ids = $destination_plugin->import($stub_row);
}
catch (\Exception $e) {
$migration->getIdMap()->saveMessage($stub_row->getSourceIdValues(), $e->getMessage());
}
if ($destination_ids) {
$migration->getIdMap()->saveIdMapping($stub_row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
}
}
if ($destination_ids) {
if (count($destination_ids) == 1) {
return reset($destination_ids);
}
else {
return $destination_ids;
}
}
}
/**
* Skips the migration process entirely if the value is FALSE.
*
* @param mixed $value
* The incoming value to transform.
*
* @throws \Drupal\migrate\MigrateSkipProcessException
*/
protected function skipOnEmpty(array $value) {
if (!array_filter($value)) {
throw new MigrateSkipProcessException();
}
}
}
<?php
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\Plugin\MigratePluginManagerInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\Plugin\MigrateIdMapInterface;