Merge pull request #12081 from umbraco/v9/bugfix/fix-invariant-redirect-tracking

Fix invariant redirect tracking
This commit is contained in:
Nikolaj Geisle
2022-03-02 12:20:15 +01:00
committed by GitHub
3 changed files with 21 additions and 13 deletions

View File

@@ -159,7 +159,7 @@ namespace Umbraco.Cms.Core.Routing
: DomainUtilities.DomainForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, int.Parse(route.Substring(0, pos), CultureInfo.InvariantCulture), current, culture);
var defaultCulture = _localizationService.GetDefaultLanguageIsoCode();
if (domainUri is not null || culture is null || culture.Equals(defaultCulture, StringComparison.InvariantCultureIgnoreCase))
if (domainUri is not null || string.IsNullOrEmpty(culture) || culture.Equals(defaultCulture, StringComparison.InvariantCultureIgnoreCase))
{
var url = AssembleUrl(domainUri, path, current, mode).ToString();
return UrlInfo.Url(url, culture);

View File

@@ -99,25 +99,32 @@ namespace Umbraco.Cms.Core.Routing
{
return;
}
var contentCache = publishedSnapshot.Content;
var entityContent = contentCache?.GetById(entity.Id);
if (entityContent == null)
IPublishedContentCache contentCache = publishedSnapshot.Content;
IPublishedContent entityContent = contentCache?.GetById(entity.Id);
if (entityContent is null)
{
return;
}
// get the default affected cultures by going up the tree until we find the first culture variant entity (default to no cultures)
var defaultCultures = entityContent.AncestorsOrSelf()?.FirstOrDefault(a => a.Cultures.Any())?.Cultures.Keys.ToArray()
?? new[] { (string)null };
foreach (var x in entityContent.DescendantsOrSelf(_variationContextAccessor))
foreach (IPublishedContent publishedContent in entityContent.DescendantsOrSelf(_variationContextAccessor))
{
// if this entity defines specific cultures, use those instead of the default ones
var cultures = x.Cultures.Any() ? x.Cultures.Keys : defaultCultures;
IEnumerable<string> cultures = publishedContent.Cultures.Any() ? publishedContent.Cultures.Keys : defaultCultures;
foreach (var culture in cultures)
{
var route = contentCache.GetRouteById(x.Id, culture);
var route = contentCache.GetRouteById(publishedContent.Id, culture);
if (IsNotRoute(route))
{
continue;
oldRoutes[new ContentIdAndCulture(x.Id, culture)] = new ContentKeyAndOldRoute(x.Key, route);
}
oldRoutes[new ContentIdAndCulture(publishedContent.Id, culture)] = new ContentKeyAndOldRoute(publishedContent.Key, route);
}
}
}
@@ -135,13 +142,16 @@ namespace Umbraco.Cms.Core.Routing
{
_logger.LogWarning("Could not track redirects because there is no current published snapshot available.");
return;
}
}
foreach (var oldRoute in oldRoutes)
foreach (KeyValuePair<ContentIdAndCulture, ContentKeyAndOldRoute> oldRoute in oldRoutes)
{
var newRoute = contentCache.GetRouteById(oldRoute.Key.ContentId, oldRoute.Key.Culture);
if (IsNotRoute(newRoute) || oldRoute.Value.OldRoute == newRoute)
{
continue;
}
_redirectUrlService.Register(oldRoute.Value.OldRoute, oldRoute.Value.ContentKey, oldRoute.Key.Culture);
}
}

View File

@@ -13,9 +13,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string LangId(string culture)
{
return culture != null ? ("-L:" + culture) : string.Empty;
}
=> string.IsNullOrEmpty(culture) ? string.Empty : ("-L:" + culture);
public static string PublishedContentChildren(Guid contentUid, bool previewing)
{