My work on extending the Migrate UI for 2.6 has revealed some basic weaknesses with how migrations are constructed. The pattern we've used to date has relied primarily on writing new classes extending the base Migration class or intermediate classes, with everything that's important to defining the migration embedded in the constructor. This makes it difficult to modify anything about a migration through the UI, everything has to be done in code. I did manage to work out some ability to override field mappings through the UI, but that implementation feels fragile and hackish to me, and there's not much else that can be done through the UI today.

Meanwhile, trying to get up-to-speed on Drupal 8, I've heard a lot about dependency injection. The Wikipedia article makes it sound harder than it is - the basic idea is, instead of hard-coding stuff in the constructor, make it more dynamic by passing stuff as arguments into the constructor or setting it on the constructed object. Moving to a dependency injection pattern for putting together migration processes would be much more flexible, and make it easier to support a rich UI.

My plan was to get Migrate 2.6 out at pretty much the current level of functionality, and then focus primarily on Migrate 3 for Drupal 8, addressing this and other architectural issues there, but it occurs to me that it may not be that hard to make significant improvements in Migrate 2 simply by adding some setters - ->setSource($source), ->setDestination($destination), etc. - it may be a fairly respectable bang for the buck. No guarantee this will make it in to Migrate 2, but I'd like to take a little time doing a POC and see how effectively this pattern can be applied.

Comments

mikeryan’s picture

Status: Active » Fixed

Well, I dug in a bit, and realized that we really need Drupal 8 to fully take advantage of the dependency injection pattern:

  • We would want to be able to persist migration configuration that isn't persisted today - source, destination, and map classes for a migration, as well as any number of other options like description. The Drupal 8 CMI is a much better approach to this than adding more SQL tables/columns.
  • Symfony has built-in classes for managing dependency injection containers.
  • Being able to inject anonymous functions to do the work callbacks/prepareRow/prepare do now is potentially very powerful, but requires at least PHP 5.3 - Drupal 7 needs to support PHP 5.2.

I have added setters for key migration elements - no reason not to, and they may be useful in some situations - but a real dependency injection solution will need to wait for Migrate 3 on Drupal 8.

Automatically closed -- issue fixed for 2 weeks with no activity.