Problem/Motivation
The d7_menu_links migration complains about failed path validation for many links.
The reason: it points to content entities that have not yet been migrated. Its migration dependencies are:
migration_dependencies:
required:
- d7_menu
While this guarantees the existence of the menu in which a migrated menu link lives, it does not guarantee that the location the menu link points to exists. This is the problem.
Proposed resolution
- Add dependencies.
- Add deriver, to allow migrating subsets of menu links (to be able to migrate only menu links targeting only content entities that have already been migrated).
Remaining tasks
- Add tests for the deriver.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #69 | core-derive_menu_link_migrations_per_entity_type-3051251-69.patch | 51.5 KB | wim leers |
| #67 | core-derive_menu_link_migrations_per_entity_type-3051251-67.patch | 50.44 KB | omkar.podey |
| #61 | drupal-n3051251-61.patch | 53.68 KB | damienmckenna |
| #61 | drupal-n3051251-61.interdiff.txt | 3.38 KB | damienmckenna |
| #59 | interdiff-52-59.txt | 11.47 KB | narendrar |
Comments
Comment #2
quietone commentedJust have time for to comment about views.
That is correct. More information can be found at Known issues when upgrading from Drupal 6 or 7 to Drupal 8.
Comment #3
hass commentedI‘m aware of this, but every view I export in D7 cannot imported to D8. This is not written in the known issues. We should update the text that the exports are all broken and the D7 module is useless.
Comment #5
huzookaI had to solve the taxonomy term related errors for my team.
Long story short: this happens because the d7_menu_link migration only depends on the d7_node migration (and only optionally). But nothing guarantees that your taxonomy terms are also migrated before menu links.
Also see #2975461-2: Convert query string to array for d6 menu_link migration.
Comment #6
huzookaComment #7
huzookaThe attached patch basically repeats the same pattern that I added at #3122649-12: [PP-2] Derive path alias migrations per entity type (and bundle).
Instead of having a single menu link migration (that Ideally should be executed only after every other, content-entity related migrations), I create standalone derivatives for nodes (per bundle), for terms (per vocabulary) and for users, and one more for everything else. And later, after that the migrations are collected and the migration plugin alter hooks are invoked, I collect every corresponding content entity migrations per entity type (and bundle) and add them to the related derived menu link migration in
menu_link_content_migration_plugins_alter().Comment #8
huzookaComment #9
huzookaComment #10
wim leersLooking great! 😊
Comment #11
wim leersAh and this means that this patch already includes #3152943-5: Remove migration of shortcuts from menu_link migration 🤓
Comment #12
huzookaComment #13
huzookaWith the derived menu link migrations, it's still possible that the parent menu link (B) of the menu link 'A' is in an another migration.
To solve this properly, we should be able to create stub menu links.
Comment #14
huzookaThe patch attached here depends on #3156083-2: Route migrate process plugin shouldn't assume that the $options variable is always an array.
Comment #16
wim leers🤓 🤔 I'm surprised this
ifcondition is necessary, because if we've reached this point then we already know for a fact that theMenuLinkContententity could not be loaded, nor could$linksbe non-empty.So … can we just remove this condition? If we can't, could you add a comment? 🙏
Other than that detail, this is a wonderfully simple interdiff! 😄
Comment #17
deepak goyal commentedHi @Wim Leers
Updated patch please review.
And below are un-used statements I removed that.
-use Drupal\Component\Plugin\Exception\PluginNotFoundException;
-use Drupal\migrate\MigrateStub;
Comment #18
deepak goyal commentedForget to upload interter-diff.
Comment #20
deepak goyal commentedHi @Wim Leers
Fixed failed test cases, please review.
Comment #21
hardik_patel_12 commentedLast patch failed to apply re-rolling for 9.1.x , kindly review.
Comment #23
hardik_patel_12 commentedSolving failed test cases, kindly review.
Comment #24
mikelutz#14 says that the patch depended on another issue that hasn't been committed, but I don't quite see how. The tests pass, and the code from the other issue isn't included in this patch. I'm trying to see if this issue should be postponed on that one. If it really requires the other issue to work correctly, yet is still passing tests, then it sounds like it might need more tests? @hazooka?
Comment #25
mikelutzKicking this back to NW for a response to #24
Comment #27
wim leersI suspect it's thanks to #2845485: Refactor and document the MenuLinkParent process plugin that this may no longer be hard-blocked on #3156083: Route migrate process plugin shouldn't assume that the $options variable is always an array, specifically the
menu link is route itemtest case that was added there.But I'd like @huzooka to confirm.
Frankly, I am 90% confident that this just needs additional test coverage, for the case where the menu parent is a route with
optionsnot being an array.Comment #28
wim leersReviewing #17 (and the interdiff at #18):
😅 Unfortunately badly reformatted code… This violates the coding standards.
👎 This change should not be necessary, the foreach won't do anything if the array is empty.
EDIT: oh I see, this is to make tests "pass", but the newly created stub in the unit test just doesn't stub the
::createInstances()call. This!empty()test is precisely why the tests appear to be passing whereas in reality they do not.Nice additions!
Again badly formatted code…
Comment #29
wim leersRebasing #14, because #14 does not apply to
9.1.xanymore, and the work in #17 and later unfortunately cannot be trusted — see my review in #28, and specifically point 2… 😢Re-reviewing #14 too:
This seems to be a bug in @huzooka's #14 patch.
Comment #30
wim leersAnd resurrecting the correct test coverage changes made in #17 through #23, while adding todos to explain what needs to happen to make them pass.
@Deepak Goyal and @Hardik_Patel_12 — would you like to continue here? 🤓
Comment #31
wim leersNW for #16 and #29.
Comment #32
huzookaThis patch also "fixes" the migration of menu links which are pointing to a node translation on the source Drupal 7 instance.
#14 still should be addressed.
I don't really see what actually is the issue highlighted in #29.
Tests are failing because we really need #3156083: Route migrate process plugin shouldn't assume that the $options variable is always an array. Without that fix, we cannot "stub" not-yet-migrated parent menu link content entities.
Comment #33
wim leersQueued a test. Updated issue title. The discovery in #32 IMHO makes this a major bug.
$menu_nameis an undefined variable!Wow this is one hell of a process pipeline.
The issue that originally introduced this, #2912353: Handle menu_items related to Drupal 6 and 7 node translations with different IDs, even had this comment from @phenaproxima:
The comments added here do help for sure. 👍
Why?
🤔 Why is this being removed here and in many other places?
Comment #34
wim leers#33.3: @huzooka just explained to me that we need the parent menu link items to be able to get stubbed, hence
no_stub: truegetting removed. 👍Comment #35
huzookaSupport derived migration of localized and also for translated menu links.
Comment #36
huzookaThis should be
Drupal\content_translation\Plugin\migrate\D7MenuLinkDeriver.Comment #37
wim leersThis drops the
d7_menu_linksdependency! And that's okay, because it now allows stubbing.This is good, because otherwise it is impossible to know which derivative of
d7_menu_linksthis should depend on — it would have to depend on all of them. Stubbing is indeed the solution.But that does mean that the indirect dependency on
d7_menuis lost, which is why I created #3189476: If d7_menu_links depends on d7_menu, then node_translation_menu_links should too. This brings back that same lost dependency.Comment #38
wim leersThe queries generated here by the
The resulting queries for this on a concrete site resulted in this query:
which took 127 seconds to return 3604 rows…
Comment #39
wim leersTurns out that this patch never got the optimizations that I added to #3122649: [PP-2] Derive path alias migrations per entity type (and bundle) in #3122649-15: [PP-2] Derive path alias migrations per entity type (and bundle) through #3122649-32: [PP-2] Derive path alias migrations per entity type (and bundle).
I am still thoroughly testing this, but wanted to post my WIP interdiff already.
Comment #40
wim leersFor #37.
Comment #41
wim leersIn the end, the #39 WIP interdiff has become the final interdiff 👍
This is ugly, but a pre-existing missing capability.
Comment #42
huzookaComment #43
huzookaPatch at #42 should be ignored.
Comment #44
nikitagupta commentedComment #47
wim leers#3189880: Use square brackets syntax in sql queries and #3207968: Replace @codingStandards comments with phpcs: comments broke this between
9.1.7and9.2.0-rc1. Fortunately, #44 already fixed it after #3189880 :) Thanks, @nikitagupta!Comment #49
wim leersHuh, looks like #44 actually made many other changes in
D7MenuLinkDeriverTraitfor undocumented reasons, this caused many problems 😬😔Comment #50
quietone commentedThe issue summary here only has a description of the problem. Let's use the template and complete all the sections.
I skimmed the patch and see that there is a new deriver, why is a deriver necessary to fix a validation issue?
I presume it is know that tests are needed. The deriver will need test. And there are no changes to the existing MigrateMenuLinkTests which I would have expected. Am I wrong on that?
@nikitagupta, when adding a patch always add an interdiff and an explanation of the changes. That will help to avoid the problems faced in #49 where the undocumented changes 'caused many problems'. There are instructions for creating an interdiff in the handbook.
Comment #51
wim leersBecause of the reason @huzooka gave in #5:
So the solution is given in #7:
The menu links no longer fail to import due to validation errors because the content they're pointing to has not yet been migrated :)
Comment #52
wim leersIt is passing only because it contains hardcoded knowledge about the exact order in which migrations should be executed. Quoting
\Drupal\Tests\menu_link_content\Kernel\Migrate\d7\MigrateMenuLinkTest::setUp():Who knows this? How can one know this? The answer is simple: this cannot be known. The solution: add the necessary migration dependencies.
But this then presents the next problem: maybe you want to focus on the migration of taxonomy terms first, but also the migration of menus targeting taxonomy terms. But blanket statements such as "
d7_menu_linksoptionally depend ond7_node,d7_taxonomy_term,d7_node_translation, …" then fail to be helpful: you can only run the migration reliably if you've first migrated literally every content entity over, otherwise your menu links migration might fail!That last paragraph is the answer to:
Not to mention: you may want to migrate nodes, but not taxonomy terms, or vice versa. If that's the case, then the current all-or-nothing
d7_menu_linksmigration is guaranteed to generate a lot of validation errors.Comment #54
danflanagan8I'm wondering what the relationship is between this issue and #3253959: Menu links migration should run after terms are migrated
From comment #5 above:
This is exactly what the new issue is about. Are these duplicates? Or is there something more in this issue that the related issue misses?
Setting to NR to get thoughts on whether or not these are duplicates.
Comment #55
quietone commentedIt does look like this is working to solve the same problem as #3253959: Menu links migration should run after terms are migrated, where the dependency on the term migration is solved.
The issue title states that the 'ALL menu links pointing to node translations are invalid'. That should have been improved by #3008028: Migrate D7 i18n menu links, committed in Oct 2020, as it sets the correct language on the menu link. There is no information provided about why validation failed so we can't confirm if that change is sufficient.
The solution here, to add the dependency using derivers, is not needed in core migrate.
I am tempted to close this as works as designed but first I want to double check the menu links for translated nodes. Setting to NW while I do that.
Comment #56
narendrarRerolled #52 to 9.3.x
Comment #57
trevorbradley commented#56 fixed my d7_menu_links migration error, but
now failing on nearly identical d7_menu_links_other error messages.
drush migrate:messages upgrade_d7_menu_links_other shows:
1 515 upgrade_d7_menu_links_other:link/uri: The path "internal:/some/views/url" failed validation.("some/views/url" my own above)
Comment #58
damienmckennaThanks to Wim Leers for pointing out that the issue I ran into (#3253959) was a symptom of this larger issue.
Comment #59
narendrarRemoved extra node_translation_menu_links.yml.orig file from patch and added https://www.drupal.org/node/3064016 code in D7MenuLinkDeriverTrait.php.
Again rerolled #52 to 9.3.x
Comment #60
wim leersManually differed #48 with #59, and they're indeed identical except for two changes:
*.origfile (which already was in #48 😅) is omitted 👍Comment #61
damienmckennaThis is test coverage that quietone and danflanagan8 added to #3253959, so attribution should go to them.
Comment #62
mikelutzAgreed on fixing dependencies. We've played loose and fast in the past by bypassing validation and using stubs with the idea that at the end of the core suite of migrations everything will fall into place. Migrating menus linking to term ids before the terms are created is fine because at the end of the process the terms will exist and everything is good. As core hardens security and error checking we need to keep track of things where there are actual validation errors in the process and make sure we are adding dependencies as needed.
I've said this before, but the migrations provided by core are designed to be run together in the order specified by core and all at once. If you want to migrate taxonomy terms followed by taxonomy menus, that is a custom migration that would require a custom menu migration, and we provide the tools for you to write that.
If you want to migrate nodes but not taxonomy or vice versa, you are also running custom migrations and not the core suite of migrations, and again you would need to customise your menu migration as well. This derivative falls into the same pattern as the other ones that have been suggested over the past year or two, as far as I can tell. It's not needed in core, but can be added to the contrib modules that export migrations for customization.
Without invoking custom migration flows, can someone give me a reason why we can't just make the menu link migration depend on all the content migrations in core instead of creating derivitives?
NW for cspell
Comment #63
wim leersI don't know of a single site that is able to migrate from 7 to 9 by using the
migrate_drupal_uimodule.So this:
is ignoring the fact that pretty much every site out there needs to execute specific migrations in a specific order.
Comment #64
mikelutzI'm not ignoring it, what I'm saying is that is the litmus test we use when deciding if something goes into core vs contrib, vs something the core api supports via custom migrations. Changing this would be a much bigger discussion, but we provide the tools and places in contrib to put things that make the custom migrations easier. In addition to adding this derivative to the other ones in migrate_upgrade, there is nothing stopping anyone from putting out a module with a complete set of alternative core migrations designed to be split into lots of smaller derived migrations ready for customization, but It doesn't pass the test for going into core that we've currently adopted.
I'm not trying to be difficult. The needs for custom migrations are wide and varied and need to move faster than we can always support in core, I really think it's better for the migration community to have these tools in contrib where things can move faster and more easily support more customized complex workflows.
Still NW for cspell and passing tests.
Comment #65
huzookaIf anyone wants not to loose their complex menu link structure during Drupal 7 -> Drupal 9 migration, try this: Migrate Magician Menu Link Migrate
Comment #67
omkar.podey commentedRerolled patch for 9.4.x.
Comment #69
wim leersRerolling for
9.5.5. (#67 still applied fine to9.5.2.)#3152943: Remove migration of shortcuts from menu_link migration conflicted with this in
\Drupal\menu_link_content\Plugin\migrate\source\MenuLink. This patch already had the logic that that added inD7MenuLinkDeriverTrait::getBaseQuery().(See #11.)
Comment #71
quietone commentedThe Migrate Drupal Module was approved for removal in #3371229: [Policy] Migrate Drupal and Migrate Drupal UI after Drupal 7 EOL.
This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
The deprecation work is in #3522602: [meta] Tasks to remove Migrate Drupal module and the removal work in #3522602: [meta] Tasks to remove Migrate Drupal module.
Migrate Drupal will not be moved to a contributed project. It will be removed from core after the Drupal 12.x branch is open.
Comment #72
quietone commentedjust updating tags