class Migration in Zircon Profile 8
Same name in this branch
- 8 core/modules/migrate/src/Entity/Migration.php \Drupal\migrate\Entity\Migration
- 8 core/modules/migrate/src/Plugin/migrate/process/Migration.php \Drupal\migrate\Plugin\migrate\process\Migration
Same name and namespace in other branches
- 8.0 core/modules/migrate/src/Plugin/migrate/process/Migration.php \Drupal\migrate\Plugin\migrate\process\Migration
Calculates the value of a property based on a previous migration.
Plugin annotation
@MigrateProcessPlugin(
id = "migration"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\migrate\Plugin\migrate\process\Migration implements ContainerFactoryPluginInterface
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of Migration
1 string reference to 'Migration'
- migrate.schema.yml in core/
modules/ migrate/ config/ schema/ migrate.schema.yml - core/modules/migrate/config/schema/migrate.schema.yml
File
- core/
modules/ migrate/ src/ Plugin/ migrate/ process/ Migration.php, line 28 - Contains \Drupal\migrate\Plugin\migrate\process\Migration.
Namespace
Drupal\migrate\Plugin\migrate\processView source
class Migration extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* @var \Drupal\migrate\Plugin\MigratePluginManager
*/
protected $processPluginManager;
/**
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $migrationStorage;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, MigratePluginManager $process_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrationStorage = $storage;
$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('entity.manager')
->getStorage('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 = array(
$migration_ids,
);
}
$scalar = FALSE;
if (!is_array($value)) {
$scalar = TRUE;
$value = array(
$value,
);
}
$this
->skipOnEmpty($value);
$self = FALSE;
/** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */
$migrations = $this->migrationStorage
->loadMultiple($migration_ids);
$destination_ids = NULL;
$source_id_values = array();
foreach ($migrations as $migration_id => $migration) {
if ($migration_id == $this->migration
->id()) {
$self = TRUE;
}
if (isset($this->configuration['source_ids'][$migration_id])) {
$configuration = array(
'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 && ($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
->get('process');
// We already have the source id values but need to key them for the Row
// constructor.
$source_ids = $migration
->getSourcePlugin()
->getIds();
$values = array();
foreach (array_keys($source_ids) as $index => $source_id) {
$values[$source_id] = $source_id_values[$migration
->id()][$index];
}
$stub_row = new Row($values + $migration
->get('source'), $source_ids, TRUE);
// Do a normal migration with the stub row.
$migrate_executable
->processRow($stub_row, $process);
$destination_ids = array();
try {
$destination_ids = $destination_plugin
->import($stub_row);
} catch (\Exception $e) {
$migrate_executable
->saveMessage($e
->getMessage());
}
}
if ($destination_ids) {
if ($scalar) {
if (count($destination_ids) == 1) {
return reset($destination_ids);
}
}
else {
return $destination_ids;
}
}
}
/**
* Skip the migration process entirely if the value is FALSE.
*
* @param mixed $value
* The incoming value to transform.
*
* @throws \Drupal\migrate\MigrateSkipProcessException
*/
protected function skipOnEmpty($value) {
if (!array_filter($value)) {
throw new MigrateSkipProcessException();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
Migration:: |
protected | property | ||
Migration:: |
protected | property | ||
Migration:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Migration:: |
protected | function | Skip the migration process entirely if the value is FALSE. | |
Migration:: |
public | function |
Performs the associated process. Overrides ProcessPluginBase:: |
|
Migration:: |
public | function |
Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 2 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
ProcessPluginBase:: |
public | function |
Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface:: |
2 |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |