A process plugin to only migrate users with certain roles would be useful.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff_16-17.txt | 2.21 KB | lisotton |
| #17 | migrate_plus-n3057685-17.patch | 2.82 KB | lisotton |
| #16 | migrate_plus-n3057685-16.patch | 2.21 KB | patpluspun |
| #12 | migrate_plus-n3057685-12.patch | 2.2 KB | damienmckenna |
| #12 | migrate_plus-n3057685-12.interdiff.txt | 576 bytes | damienmckenna |
Comments
Comment #2
damienmckennaThis adds a new source plugin called d7_user_role_filter which looks for a "roles" value in the yml file. Here's the docblock:
Comment #3
damienmckennaThanks to the folks in the #migration channel on Slack for their help, including ttamniwdoog, benjifisher, timwood, heddn and mikelutz.
Comment #4
marvil07 commentedskip_on_valuebased on the addedridsource field. Naturally an implementation like this will have better performance because it will not need to go over all users, so it is a better option when the amount of d7 users is not small.d7_useris also handling d7 profile contrib module, so an option to filter on roles sounds also as a good canditate for core itself. We may want to move it over there.role.nametable field.query()method calling the parent seems a bit more natural.required_rolesdata member probably should berequiredRolesMarking as NW for at least the last two items.
Comment #5
damienmckennaWhile this doesn't work on the changes requested, ran out of time today, this adds *another* plugin that also adds all users who have created nodes, though I need to test & tweak it.
Comment #6
damienmckennaFixed the UserAuthorRoleFilter and changed UserRoleFilter::query() so it extends the base query instead of duplicating the code.
Comment #7
damienmckennaGah, mucked up the last patches, sorry.
Comment #8
damienmckennaGoing over the feedback from #4:
Comment #9
damienmckennaThis renames the class variable, changes the variable check to a cast statement, removes a commented out print_r() statement, and leaves two @todo items for later.
Comment #10
damienmckennaThe UNION statement isn't working as intended because SqlBase::initializeIterator() is joining a extra table to the first query, but not the second one, so it throws this error:
and turning it into this:
Comment #11
damienmckennaI split this up into two separate requests, so this one is back to just the user role filter.
Comment #12
damienmckennaThis needed a $query->distinct(TRUE) to make sure the query count was correct.
Comment #13
heddnComment #14
patpluspun commentedJust tested it with a single role and multiple roles, works like a charm. Thanks Damien!
Comment #15
damienmckennaGlad it worked for you, @patpluspun.
Let's go back to the request to allow limiting it by role name.
Comment #16
patpluspun commentedPatch #16 addresses changes in drupal_migrate that we encountered. Very minor change. I'll try and tackle limiting by role name in the near future.
Comment #17
lisotton commentedI have included the possibility to filter roles by name.
Comment #18
lisotton commentedComment #19
matroskeenThis is definitely a common requirement for a custom migration. Thanks for the all hard work done here 👍
However, you might be interested in #3069776: SQL source plugins: allow defining conditions and join in migration yml, which allows supplying additional
joinsandconditionsto the existing source plugins. For this particular case, the source plugin can be configured in the following way:It'll make the source plugin retrieve users that have one of these roles: 1, 2, 3.
I think we can close this one in favor of #3069776: SQL source plugins: allow defining conditions and join in migration yml.