Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Complex migrations needs support code in the various events dispatched by migrate module. But an event subscriber react for every migration so a developer need to switch over the plugin_id to execute custom code only on desired migrations.
Proposed resolution
We can provide a generic event subscriber that delegate execution to custom classes (one for migration plugin id) that contains the code only for that migration.
Remaining tasks
Review code
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#7 | add_support_for_single-2778431-7.patch | 17.15 KB | lussoluca |
#5 | add_support_for_single-2778431-5.patch | 10.55 KB | lussoluca |
#2 | add_support_for_single-2778431-2.patch | 10.41 KB | lussoluca |
Comments
Comment #2
lussolucaComment #3
lussolucaComment #4
mikeryanThis provides new APIs extending core, there's no tool work here - migrate_plus is the appropriate module for this.
Comment #5
lussolucaComment #6
mikeryanI like this! It beats having to check migration IDs in every event handler...
Besides the nits below, how about an example? I would suggest converting BeerNode::prepareRow() to use this model, with comments contrasting the approach with BeerUser::prepareRow() (extending the parent prepareRow()).
Space after if.
Please fill in the docs for the onMigrate* methods.
Any reason not to make this abstract?
s/,/./
Comment #7
lussolucaNitpicks fixed and Node example updated (how do you think about the comments?)
Comment #8
mikeryan\Drupal\migrate_example\Plugin\migrate_plus\migration_events\BeerNodeMigrationEvents
Drupal\migrate_example\Plugin\migrate_plus\migration_events
I think 'migration_events' rather than 'migration' as the last component here, to be clearer about its role (and not mistake it for a manager of migration plugins).
Please fill in the docs here.
The docs should be on the interface, and the implementations here should use {@inheritdoc}.
Please document the methods on the interfaces.
A broader issue - this is going to receive every single event that's dispatched during a migration and execute runEvent() for every one, how much overhead is that going to generate? Yes, runEvent() isn't that heavy, but it is going to get called a *whole lot* (3-4 times per imported row, twice per rolled-back row), it'll add up.
Just spitballing some thoughts here: What if MigrateEventsSubscriber has its own PRE_IMPORT handler (the only one in getSubscribedEvents()), which finds if there are any event plugins for the current migration and lazy-subscribes those events as needed (and, perhaps also builds a map of such plugins to optimize the actual dispatching). Problem - the base class implements every event handler, so we don't know when there's a "real" implementation...
Any other ideas on optimizing this?
Thanks!
Comment #9
heddnSo, this does help for custom migrations where we are writing event subscribers. This won't work in a generic sense (by contrib) though because we don't always know what a migration will be called.