Skip to content

Commit

Permalink
Merge pull request #149 from discoverygarden/fix/delay-migration-sour…
Browse files Browse the repository at this point in the history
…ce-dereference

DU-1 DDST-839 : Avoid dereferencing the source migration in the constructor.
  • Loading branch information
nchiasson-dgi authored Dec 16, 2024
2 parents 2a01ae6 + 454e1f8 commit 877038f
Showing 1 changed file with 16 additions and 16 deletions.
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']);
}

}

0 comments on commit 877038f

Please sign in to comment.