Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DU-1 DDST-839 : Avoid dereferencing the source migration in the constructor. #149

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/Plugin/migrate/source/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Migration extends SourcePluginBase implements ContainerFactoryPluginInterf
*
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
*/
protected $migrationPluginManager;
protected MigrationPluginManagerInterface $migrationPluginManager;

/**
* The target migration.
* Memoized target migration.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $targetMigration;
protected MigrationInterface $targetMigration;

/**
* Constructor.
Expand All @@ -39,7 +39,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);

$this->migrationPluginManager = $migration_plugin_manager;
$this->targetMigration = $this->migrationPluginManager->createInstance($this->configuration['migration']);
}

/**
Expand All @@ -55,18 +54,28 @@ public static function create(ContainerInterface $container, array $configuratio
);
}

/**
* Load and identify the target migration.
*
* @return \Drupal\migrate\Plugin\MigrationInterface
* The target migration.
*/
protected function getTargetMigration() : MigrationInterface {
return $this->targetMigration ??= $this->migrationPluginManager->createInstance($this->configuration['migration']);
}

/**
* {@inheritdoc}
*/
public function initializeIterator() {
return new MigrationIterator($this->targetMigration->getIdMap(), 'currentDestination');
return new MigrationIterator($this->getTargetMigration()->getIdMap(), 'currentDestination');
}

/**
* {@inheritdoc}
*/
public function getIds() {
return (array) $this->targetMigration->getDestinationPlugin()->getIds();
return (array) $this->getTargetMigration()->getDestinationPlugin()->getIds();
}

/**
Expand All @@ -81,7 +90,7 @@ public function fields() {
*/
public function __toString() {
return strtr('target migration: @migration', [
'@migration' => $this->targetMigration->id(),
'@migration' => $this->getTargetMigration()->id(),
]);
}

Expand All @@ -106,13 +115,4 @@ public function __sleep() {
return $vars;
}

/**
* {@inheritdoc}
*/
public function __wakeup() {
parent::__wakeup();

$this->targetMigration = $this->migrationPluginManager->createInstance($this->configuration['migration']);
}

}
Loading