diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs index 2c110496f03d..b700854a32c6 100644 --- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs @@ -68,6 +68,7 @@ public static string Name(this IPublishedContent content, IVariationContextAcces /// The specific culture to get the URL segment for. If null is used the current culture is used /// (Default is null). /// + [Obsolete("Please use GetUrlSegment() on IDocumentUrlService instead. Scheduled for removal in V16.")] public static string? UrlSegment(this IPublishedContent content, IVariationContextAccessor? variationContextAccessor, string? culture = null) { if (content == null) @@ -89,10 +90,8 @@ public static string Name(this IPublishedContent content, IVariationContextAcces culture = variationContextAccessor?.VariationContext?.Culture ?? string.Empty; } - // get - return culture != string.Empty && content.Cultures.TryGetValue(culture, out PublishedCultureInfo? infos) - ? infos.UrlSegment - : null; + IDocumentUrlService documentUrlService = StaticServiceProvider.Instance.GetRequiredService(); + return documentUrlService.GetUrlSegment(content.Key, culture, content.IsDraft()); } #endregion diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs index 56f77895788b..bf41498c4320 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs @@ -31,6 +31,7 @@ public abstract class PublishedContentBase : IPublishedContent public virtual string Name => this.Name(_variationContextAccessor); /// + [Obsolete("Please use GetUrlSegment() on IDocumentUrlService instead. Scheduled for removal in V16.")] public virtual string? UrlSegment => this.UrlSegment(_variationContextAccessor); /// @@ -75,7 +76,6 @@ public abstract class PublishedContentBase : IPublishedContent [Obsolete("Please use TryGetParentKey() on IDocumentNavigationQueryService or IMediaNavigationQueryService instead. Scheduled for removal in V16.")] public abstract IPublishedContent? Parent { get; } - // FIXME /// [Obsolete("Please use TryGetChildrenKeys() on IDocumentNavigationQueryService or IMediaNavigationQueryService instead. Scheduled for removal in V16.")] public virtual IEnumerable Children => GetChildren(); diff --git a/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs b/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs index 7fa38dd62637..e2be9797a0fa 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs @@ -1,6 +1,5 @@ -using StackExchange.Profiling.Internal; -using Umbraco.Cms.Core.Media.EmbedProviders; -using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Extensions; @@ -10,11 +9,13 @@ internal class CacheNodeFactory : ICacheNodeFactory { private readonly IShortStringHelper _shortStringHelper; private readonly UrlSegmentProviderCollection _urlSegmentProviders; + private readonly IDocumentUrlService _documentUrlService; - public CacheNodeFactory(IShortStringHelper shortStringHelper, UrlSegmentProviderCollection urlSegmentProviders) + public CacheNodeFactory(IShortStringHelper shortStringHelper, UrlSegmentProviderCollection urlSegmentProviders, IDocumentUrlService documentUrlService) { _shortStringHelper = shortStringHelper; _urlSegmentProviders = urlSegmentProviders; + _documentUrlService = documentUrlService; } public ContentCacheNode ToContentCacheNode(IContent content, bool preview) @@ -126,6 +127,7 @@ private ContentData GetContentData(IContentBase content, bool published, int? te } var cultureData = new Dictionary(); + string? urlSegment = null; // sanitize - names should be ok but ... never knows if (content.ContentType.VariesByCulture()) @@ -153,10 +155,14 @@ private ContentData GetContentData(IContentBase content, bool published, int? te } } } + else + { + urlSegment = content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders); + } return new ContentData( content.Name, - null, + urlSegment, content.VersionId, content.UpdateDate, content.CreatorId, diff --git a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs index 30d1358d648c..4f7deffeb8fa 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs @@ -574,8 +574,7 @@ private ContentNuDto GetDtoFromContent(IContentBase content, bool published, ICo cultureData[cultureInfo.Culture] = new CultureVariation { Name = cultureInfo.Name, - UrlSegment = - content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders, cultureInfo.Culture), + UrlSegment = content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders, cultureInfo.Culture), Date = content.GetUpdateDate(cultureInfo.Culture) ?? DateTime.MinValue, IsDraft = cultureIsDraft, }; @@ -843,7 +842,7 @@ private ContentCacheNode CreateContentNodeKit(ContentSourceDto dto, IContentCach serializer.Deserialize(dto, dto.EditData, dto.EditDataRaw, published); var draftContentData = new ContentData( dto.EditName, - null, + deserializedDraftContent?.UrlSegment, dto.VersionId, dto.EditVersionDate, dto.CreatorId, @@ -882,7 +881,7 @@ private ContentCacheNode CreateContentNodeKit(ContentSourceDto dto, IContentCach ContentCacheDataModel? deserializedContent = serializer.Deserialize(dto, dto.PubData, dto.PubDataRaw, true); var publishedContentData = new ContentData( dto.PubName, - null, + deserializedContent?.UrlSegment, dto.VersionId, dto.PubVersionDate, dto.CreatorId,