Migrating from Drupal 7 to Drupal 8, is there a migration for the pathauto state? I'm referring to the pathauto_state table in the database that controls the "Generate automatic url alias" checkbox.
In my testing of d7_url_alias and the two pathauto migrations d7_pathauto_pattterns, d7_pathauto_settings I haven't found a solution.
Let me know if I've missed something and/or any tips for how to go about this myself.
| Comment | File | Size | Author |
|---|---|---|---|
| #75 | pathauto-n3079275-75-combined.patch | 137.55 KB | marcelovani |
| #71 | pathauto-n3079275-71-combined.patch | 137.33 KB | jienckebd |
| #69 | pathauto-n3079275-69-combined.patch | 137.35 KB | damienmckenna |
| #62 | pathauto-n3079275-62-combined.patch | 137.71 KB | damienmckenna |
| #62 | pathauto-n3079275-62.interdiff.txt | 3.2 KB | damienmckenna |
Issue fork pathauto-3079275
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
bbombachiniBy now I think you've figured this already but that's how I've solved this. I've created a custom process plugin where I query the migrate database for the
pathauto_persistvalue for each node.Here's an example of my migrate_plus.migration.d7_node_basic_page.yml for example:
And then my process plugin src/Plugin/migrate/process/PathautoGenerate.php:
Important to notice that I'm also migrating the alias, but this will only take effect if 'path/pathauto' is set to 0 (do not auto generate url). Otherwise pathauto will override it.
I have based my example off this one https://drupal.stackexchange.com/questions/238393/migrate-duplicate-entr... although the issue was quite different.
Comment #3
mariaioann commented@bbombachini's process plugin worked for me. Except that I had to change the D7 table name from
pathauto_persisttopathauto_state.Comment #4
mariaioann commentedOne more problem I see is that the pathauto state had not been saved in Drupal 7 DB for some nodes and was auto-calculated. So, we have to somehow calculate the pathauto state of these nodes before or during or after the migration.
Comment #5
m@ster commentedTnx. This is correct only for Pathauto 7.x-1.5
https://www.drupal.org/node/1167612
Comment #6
mstrelan commentedFWIW you might be better off extending the source plugin to add a join to the query instead of performing an additional query for each row.
Comment #7
wim leersComment #8
huzookaComment #9
huzookaThe patch I post here ensures that custom aliases aren't lost during the migration.
PathautoFieldItemListto check the state before blindly applying the default value, and flags migrated entities to suppress path alias generation for a migrated entity.Comment #10
huzookaComment #11
huzookaComment #12
huzookaComment #13
huzookaComment #14
huzooka#3179835: Migrate forum pattern to taxonomy term forums if forum is enabled on the source site and #3179865: [PP-1] Derive pathauto pattern migrations to solve inaccurate pattern migration dependencies got newer patches.
Comment #15
wim leers🤔 The description makes much more sense than the classname IMHO.
I think something like
NodeAndTaxonomyPathAliasStateMigratorwould make more sense as a name.🤓 s/to flags/to flag/
👏 Crucial comment!
🤔 Ah, so the Drupal 7
pathautomodule literally only supports it for these entity types?If so, why are we then not moving this logic into
::isApplicable()?🤔 Hm, this means that we also support migrating from old
pathautomodules on Drupal 7.Right?
If so, let's document that explicitly in the class-level docblock.
🤯🤩👏
👍 Nice, all four permutations: F && F, F && T, T && F, T && T.
Let's clean this comment up 😛 It seems like a debug leftover?
a migrated content entity→a content entity being migrated👍 I do not worry about the overhead on production sites because this code only runs
if ($this→getEntity()→isNew()), which is slow already. One more key-value lookup won't make a material difference.🤔 Let's first assign the key-value lookup in a variable. That will make this much easier to read.
🙏 Can you document why this needs reflection?
Ideally we wouldn't have this, to avoid overhead on production sites.
Nice! Zero overhead on production sites! 👍
Comment #16
huzookaComment #17
huzookaRe #15:
NodeAndTaxonomyPathAliasStateMigratorwould be misleading imho.Instead of renaming the class, I kept the neutral
ContentEntityMigrationname, but added a long class description.::isApplicable(), I couldn’t prevent alias generation for users (or for other contrib entity types that might have an already migrated or preexisting pattern on the destination site).Comment #18
wim leersThanks, that addresses all of my concerns! 😊
Comment #19
huzookaThe patch
pathauto-prevent_losing_custom_aliases-3079275-17.patchdepends on #3179835: Migrate forum pattern to taxonomy term forums if forum is enabled on the source site and #3179865: [PP-1] Derive pathauto pattern migrations to solve inaccurate pattern migration dependencies because of the tests.Comment #20
wim leersActually, this is a pretty major bug because it results in data loss.
Comment #21
huzookaComment #22
huzookaPatch on top of #3179835-14: Migrate forum pattern to taxonomy term forums if forum is enabled on the source site, #3179865-25: [PP-1] Derive pathauto pattern migrations to solve inaccurate pattern migration dependencies and #3182708-11: [PP-2] Migrate language-specific patterns.
Comment #23
mariaioann commentedPatch on top of combined patch #17.
The only change is that it checks whether $destination_entity_id is empty in ContentEntityMigration Event Subscriber, before setting the pathauto state, as in some cases it happens to be empty. Maybe it should not be empty and it is a stale content problem, but could we be more defensive at that point?
Comment #24
mariaioann commentedAbove patch at #23 did not include added files. This is a fixed version of the #23 patch and an interdiff with #17 patch.
Comment #25
matroskeenI was looking for a way to preserve pathauto state in the custom migration (where IDs are not preserved) and came across this issue.
Unfortunately, current patch doesn't cover my case, because these lines never returned destination IDs:
In my custom migration, IDs are not preserved, so the destination property is always missing.
I'm attaching a patch with the fix, where the piece of code related to pathauto state has been moved into
MigrateEvents::POST_ROW_SAVEevent handler. Normally, the destination entity should be already available at this stage and should cover both automatic and manual migrations.Comment #26
damienmckennaFor anyone reading at home, the sequence of necessary patches is:
This is a combined patch that includes all of these changes in one.
Comment #27
narendrarPatch on top of #3179835-22: Migrate forum pattern to taxonomy term forums if forum is enabled on the source site, #3179865-25: [PP-1] Derive pathauto pattern migrations to solve inaccurate pattern migration dependencies and #3182708-12: [PP-2] Migrate language-specific patterns.
Comment #28
huzooka#27fixes my previous inaccuracy:
In the most recent PHP versions, getting an array offset of type null not just returns
NULLbut also throws an error.This change ensures that the patch is compatible with PHP 7.4+.
Comment #29
damienmckennaThis is an updated combined patch which includes the changes from #27.
Comment #30
damienmckennaRerolled.
Comment #32
damienmckennaThis should fix the mismatched testSource() method.
Comment #34
damienmckennaOne of the test failures comes from this line:
The odd part is that this class method doesn't exist, so why is this needed?
Comment #35
damienmckennaThat part of the combined patch comes from #3179865, so I've crossposted my question there.
Comment #36
lily.yan commentedHi,
I tried to apply the latest patch (pathauto-n3079275-32-combined.patch) to the latest tag 8.x-1.10, got the below error.
git apply pathauto-n3079275-32-combined.patch
pathauto-n3079275-32-combined.patch:1313: trailing whitespace.
error: patch failed: pathauto.module:185
error: pathauto.module: patch does not apply
Comment #37
kpaxman commentedI confirm that the patch fails to apply to the current release; it also fails against the dev branch.
Comment #38
lily.yan commentedRerolled pathauto-n3079275-32-combined.patch based on the latest tag version 8.x-1.10.
Comment #39
lily.yan commentedpathauto-n3079275-38-combined.patch is not correct. Here is the correct one.
Comment #40
damienmckennaFYI the migration plugin fails if you're doing a custom migration that does not include the nid or tid, i.e. the entity's ID is not migrated, failing with this error:
It tries to get the destination ID in this code:
Should it not get the entity ID from the migration object instead of assuming the value was migrated?
Comment #41
damienmckennaChanging that line to the following makes it work, at least in my local testing where I'm running a migration update (drush migrate:import --update):
The question is - is that safe to use in all cases?
Comment #42
damienmckennaThe trick from #41 doesn't work when migrations are new, so it might be best to add some logic to skip the record if $destination_entity_id is empty.
Comment #43
damienmckennaRerolled everything...
This combines everything from the other three issues, adds #22 along with the fixes from #23, #25 and #27.
Comment #44
damienmckennaFYI #45 leads to bugs with PHP 8.1 as getPathautoStateKey() gets passed an empty variable when the node form is loaded.
Comment #45
damienmckennaWorking on the PHP 8.1 compatibility fixes.
Comment #46
damienmckennaThis resolves a PHP 8.1 bug that would trigger the following error when loading an form to create an entity which had a pathauto pattern defined:
Comment #47
damienmckennaThis fixes the error from #47.
Comment #49
damienmckennaWorking on the test regressions.
Comment #50
damienmckennaLooking at the test failures:
That suggests this introduces a UI change which adds the Pathauto checkbox to show on user forms.
Comment #51
damienmckennaFixing a few of the smaller issues.
Comment #52
damienmckennaSorry about that.
Comment #54
damienmckennaLooking at the test failure of Drupal\Tests\pathauto\FunctionalJavascript\PathautoUiTest, it hits this error message:
Working on it.
Comment #55
damienmckennaIn local testing this fixes PathautoUiTest.
Comment #57
damienmckennaThis should fix PathautoMigrateUiTest .
Comment #58
damienmckennaIncidentally, the changes in #57 stem from code like this:
The problem is that $path_alias_repository->lookupBySystemPath('/node/11', 'en') returns NULL if the value doesn't exist, so PHP yells about trying to access an array element on NULL. The solution here was to remove the array element on the assertions where it was checking for NULL.
Comment #60
damienmckennaThe failures in PathautoBulkUpdateTest are because a URL is not automatically created for the admin user created in setUp(), which goes back to the problem identified in #54.
Comment #61
damienmckennaIn MigratePathautoTest, for some reason the English version of the node results in a path alias, even though the comment says it shouldn't have an alias after the node is re-saved. Is the test wrong or is there a bug somewhere in the code?
Comment #62
damienmckennaThis fixes PathautoSourceTest by simplifying/fixing some of the database prefix logic that was added at some point (I previously questioned this logic in #34).
Comment #64
damienmckennaFYI #62 includes the following dump() output, because I forgot to remove the lines prior to creating the patches:
This is the output from MigratePathautoTest::testPathautoMigrations() and shows the output of the $path_alias_repository->lookupBySystemPath() calls - it's expected to show three "null" statements, but the first one shows an alias record that the test doesn't expect to find.
Comment #65
damienmckennaLeaving it for someone else to look at.
Comment #66
jonathan_hunt commentedUnfortunately patch in #62 no longer applies to Pathauto 8.x-1.12.
Comment #67
damienmckenna#62-combined rerolled.
Comment #68
ressaThanks @DamienMcKenna, I am following your awesome upgrade from D7 to D10 videos, so thanks for documenting the process, as well clearing bumps in the road ahead for all us other upgraders :-)
Since Pathauto is used in most D7 projects, and the D7 EOL is getting closer, it would be awesome to land this before too long.
Comment #69
damienmckennaRerolled.
Comment #70
alisonThank you for all the work on this issue!
I tried the patch on #69 on 1.x-dev this evening, and:
--update, nodes for which "Generate automatic URL alias" is disabled on my Drupal 7 source site now have this checkbox disabled on my Drupal 10 destination site 🎉upgrade_d7_url_aliasanyway, so this ^^ behavior is correct??I'm not totally certain of the intended behavior, so I won't say if it's working or not working :) The issue summary might need an update, but that could just be my relative unfamiliarity with the issue.
I do have a question: Can the changes in this patch be used to disable "Generate automatic URL alias" during a node migration? Like, is there anything in the new/updated process plugin(s) that would let me set that field value in the process section of my node migration?
EDIT: Apparently it's as simple as adding this to each node migration:
So please disregard my question!
About me:
- Drupal 10.2.0
- Pathauto 1.x-dev (from this evening)
- Using "classic" node migrations, not "node complete"
- Preserving node IDs, not migrating revision history, not preserving VIDs.
- Not a multilingual site
- (Anything else?)
Comment #71
jienckebd commentedPatch from #69 is failing tests.
The node_type condition plugin was deprecated since Drupal 9.3 in favor of a generalized entity_bundle:* condition plugin.
This pathauto issue applies this change to 1.x branch.
The patch in this issue still references the removed node_type condition plugin and results in test failures.
The attached patch:
Comment #72
zipymonkey commentedI had to apply a couple other patches to apply this to 8.x-1.12 and I am setting a deprecation warning when on PHP8.3.
It looks like this requires defining the basePluginId variable.
Comment #73
zipymonkey commentedI created a fork, applied the patch and updated the Deriver to fix the PHP 8.3 deprecation warning: https://git.drupalcode.org/issue/pathauto-3079275/-/commit/b93e5527a4b88...
Comment #75
marcelovaniRerolled patch #71
Comment #76
anish.a commentedThis patch is not applying on latest pathauto.
Comment #77
ressa@anish.a: The MR at the top says MR !77 mergeable so it looks fine.
Is the patch in comment #75 of use, or should it be disregarded? 🤔
Thanks for sharing your observations in @alison #70! If you or anyone else feel like sharing examples on how to use features from the patch under the
processsection in migration files, it would be a great addition in the Issue Summary.Comment #79
mably commentedSome tests are failing.
Recategorizing this issue from "Bug report" to "Task".
This is related to Drupal 7 migration support, and reclassifying it as a task helps us better triage the issue queue by distinguishing migration-related work from actual bugs affecting current functionality.
No change in priority or scope — just a category adjustment for clarity.