-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Allow multiple URL segments per document #18603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple URL segments per document #18603
Conversation
Set up currently failing integration test for expected routes.
…ious behaviour when a single segment is retrieved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there's a problem with your migration when running on SQLite. You cannot add the isPrimary column since bools are saved as INTEGER NOT NULL and there's no default value. One way to solve this would be to create a new table with the new column, migrate over the data, and replace the existing table with the new one. AddGuidsToUserGroups has an example of this; there's also more of an explanation in the comments there.
Also, a smaller thing, but we want to avoid raw SQL so we should do something like:
Execute.Sql(Sql().Update<DocumentUrlDto>(u => u.Set(x => x.IsPrimary, 1))).Do(); instead
|
Other than that I think it looks good, at least as far as I can tell, only did a minor tidy up |
Ah, good catch - I've been working with SQL Server locally and forgot about this SQLite restriction. I'll have a look. Just quickly though - you say there's no default value. Actually ideally I would have liked one, to just set the default to "1" and then I wouldn't need the update statement. But I couldn't find a migration where we had default values on columns. Do you know of one or know if we can do this please? |
|
That would also be a solution, and I think it would be fine since it should still align with existing behaviour, I remember doing it once, but I can't for the life of me remember how I did it right now 😅 |
|
Oh right I remember now, you can add The migration runs now, however, I run into a new issue, I get a |
|
OK - thanks for that. You can leave it with me now and I'll see if I can sort out what's going on there. |
|
I've updated to resolve the migration on SQLite. However I can't seem to trigger the issue you've mentioned. I guess it's occurring due to the URLs being rebuilt before the migration occurs - as the new field added won't be there yet. But I don't see it in test - either with attended or unattended migrations. And I can see we have this check in |
nikolajlauridsen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found an unused logger I've removed, but other than that it looks good to me now.
On the error, I can't reproduce it anymore either, I think I might have put my system in a weird state when playing around with the migrations, so it's good to merge in my opinion now 👍
|
Great, thanks for the review. |
This PR tackles an issue raised about having different URL segments for content for when the content is rendered as a page, versus when it's used as an ancestor for a page in the route.
Here's the specific example, where it's argued that doing so can add some SEO benefits.
Given the following content structure, these routes should be used:
To support this we can use an
IUrlProviderand anIContentFinder, as documented here and here. This issue is that ourIContentFinderneeds to look up the document from the route, and will use theIDocumentServicefor this. But this only supports one segment per document, culture and draft/published flag combination.URL segments are provided by registered
IUrlSegmentProviderclasses, which, although you can register more than one, terminate when they find and return a segment. So you can never find more than one segment for a given document, culture and draft/published flag combination.This PR makes the following changes:
umbracoDocumentUrltable to include thesegmentcolumn).isPrimaryto the table, which allows us to record which segment was first resolved from theIUrlSegmentProvidercollection.AllowAdditionalSegmentstoIUrlSegmentProvider, which defaults tofalse. If set totrue, the provider will no longer terminate and thus allow other providers to return segments. This allows for more than one segment per document, culture and draft/published flag combination to be resolved and persisted.IDocumentServiceto use all segments when looking up a document by the provided route.Code Sample
Putting it all together we can meet the use case with the following custom
IUrlProvider,IContentFinderandIUrlSegmentProvider:Composer and components to meet the described use case
To Review:
DocumentUrlServicein particular a little harder to spot via GitHub, so you may need to pull this down locally, or review commits 2-4 independently.To Test: