diff --git a/src/Umbraco.Cms.Api.Delivery/Services/ApiMediaQueryService.cs b/src/Umbraco.Cms.Api.Delivery/Services/ApiMediaQueryService.cs index 15ecaa1423e0..09fd3649b288 100644 --- a/src/Umbraco.Cms.Api.Delivery/Services/ApiMediaQueryService.cs +++ b/src/Umbraco.Cms.Api.Delivery/Services/ApiMediaQueryService.cs @@ -66,7 +66,12 @@ private IPublishedMediaCache GetRequiredPublishedMediaCache() private IPublishedContent? TryGetByPath(string path, IPublishedMediaCache mediaCache) { var segments = path.Split(Constants.CharArrays.ForwardSlash, StringSplitOptions.RemoveEmptyEntries); - IEnumerable currentChildren = mediaCache.GetAtRoot(); + if (_mediaNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys) is false) + { + return null; + } + + IEnumerable currentChildren = rootKeys.Select(x => mediaCache.GetById(false, x)).WhereNotNull(); IPublishedContent? resolvedMedia = null; foreach (var segment in segments) @@ -101,9 +106,9 @@ private IPublishedMediaCache GetRequiredPublishedMediaCache() } IPublishedMediaCache mediaCache = GetRequiredPublishedMediaCache(); - if (childrenOf.Trim(Constants.CharArrays.ForwardSlash).Length == 0) + if (childrenOf.Trim(Constants.CharArrays.ForwardSlash).Length == 0 && _mediaNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys)) { - return mediaCache.GetAtRoot(); + return rootKeys.Select(x => mediaCache.GetById(false, x)).WhereNotNull(); } IPublishedContent? parent = Guid.TryParse(childrenOf, out Guid parentKey) diff --git a/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs b/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs index 4741eedcc436..fae5a03144fd 100644 --- a/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs @@ -27,39 +27,6 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase()) - { - } - public ContentCacheRefresher( AppCaches appCaches, IJsonSerializer serializer, diff --git a/src/Umbraco.Core/Cache/Refreshers/Implement/MediaCacheRefresher.cs b/src/Umbraco.Core/Cache/Refreshers/Implement/MediaCacheRefresher.cs index 7beeda73b69c..32d21704d26c 100644 --- a/src/Umbraco.Core/Cache/Refreshers/Implement/MediaCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/Refreshers/Implement/MediaCacheRefresher.cs @@ -22,31 +22,6 @@ public sealed class MediaCacheRefresher : PayloadCacheRefresherBase()) - { - } - public MediaCacheRefresher( AppCaches appCaches, IJsonSerializer serializer, diff --git a/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs b/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs index 209ce4e33e2e..bc9b37414e1b 100644 --- a/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs +++ b/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.Models.DeliveryApi; +using Umbraco.Cms.Core.Models.DeliveryApi; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Extensions; @@ -12,19 +10,6 @@ public abstract class ApiContentBuilderBase private readonly IApiContentNameProvider _apiContentNameProvider; private readonly IOutputExpansionStrategyAccessor _outputExpansionStrategyAccessor; - [Obsolete("Please use the constructor that takes all parameters. Scheduled for removal in Umbraco 17.")] - protected ApiContentBuilderBase( - IApiContentNameProvider apiContentNameProvider, - IApiContentRouteBuilder apiContentRouteBuilder, - IOutputExpansionStrategyAccessor outputExpansionStrategyAccessor) - : this( - apiContentNameProvider, - apiContentRouteBuilder, - outputExpansionStrategyAccessor, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - protected ApiContentBuilderBase( IApiContentNameProvider apiContentNameProvider, IApiContentRouteBuilder apiContentRouteBuilder, diff --git a/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs b/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs index d11e08bad357..c5eed0e9c99e 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollection.cs @@ -1,7 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Composing; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; @@ -17,17 +15,6 @@ public class DataValueReferenceFactoryCollection : BuilderCollectionBase _logger; - /// - /// Initializes a new instance of the class. - /// - /// The items. - [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 17.")] - public DataValueReferenceFactoryCollection(Func> items) - : this( - items, - StaticServiceProvider.Instance.GetRequiredService>()) - { } - /// /// Initializes a new instance of the class. /// @@ -159,17 +146,6 @@ private IEnumerable GetReferencesFromPropertyValues(IEnu return result; } - /// - /// Gets all relation type aliases that are automatically tracked. - /// - /// The property editors. - /// - /// All relation type aliases that are automatically tracked. - /// - [Obsolete("Use GetAllAutomaticRelationTypesAliases. This will be removed in Umbraco 15.")] - public ISet GetAutomaticRelationTypesAliases(PropertyEditorCollection propertyEditors) => - GetAllAutomaticRelationTypesAliases(propertyEditors); - public ISet GetAllAutomaticRelationTypesAliases(PropertyEditorCollection propertyEditors) { // Always add default automatic relation types diff --git a/src/Umbraco.Core/PropertyEditors/RadioValueEditor.cs b/src/Umbraco.Core/PropertyEditors/RadioValueEditor.cs deleted file mode 100644 index 1672c7b4647a..000000000000 --- a/src/Umbraco.Core/PropertyEditors/RadioValueEditor.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.PropertyEditors.Validators; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Strings; - -namespace Umbraco.Cms.Core.PropertyEditors; - -[Obsolete("This is no longer used and has been migrated to an internal class within RadioButtonsPropertyEditor. Scheduled for removal in Umbraco 17.")] -public class RadioValueEditor : DataValueEditor -{ - public RadioValueEditor( - IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper, - DataEditorAttribute attribute) - : base(shortStringHelper, jsonSerializer, ioHelper, attribute) => - Validators.Add(new RadioValueValidator()); -} diff --git a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs index e8866622b8af..e210cd502f2f 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs @@ -14,15 +14,6 @@ public sealed class EmailValidator : IValueValidator { private readonly ILocalizedTextService _localizedTextService; - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 17.")] - public EmailValidator() - : this(StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Umbraco.Core/PropertyEditors/Validators/MultipleValueValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/MultipleValueValidator.cs index ed1d11ad1867..1b77f1c655c5 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/MultipleValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/MultipleValueValidator.cs @@ -14,15 +14,6 @@ public class MultipleValueValidator : IValueValidator { private readonly ILocalizedTextService _localizedTextService; - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Please use the constructor that takes all parameters. Scheduled for removal in Umbraco 17.")] - public MultipleValueValidator() - : this(StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RadioValueValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/RadioValueValidator.cs deleted file mode 100644 index 67806760f6fe..000000000000 --- a/src/Umbraco.Core/PropertyEditors/Validators/RadioValueValidator.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Umbraco.Cms.Core.Models.Validation; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors.Validators; - -[Obsolete("This is no longer used and has been migrated to an internal class within RadioButtonsPropertyEditor. Scheduled for removal in Umbraco 17.")] -public class RadioValueValidator : IValueValidator -{ - public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration, - PropertyValidationContext validationContext) - { - // don't validate if empty - if (value == null || value.ToString().IsNullOrWhiteSpace()) - { - yield break; - } - - if (dataTypeConfiguration is not ValueListConfiguration valueListConfiguration) - { - yield break; - } - - if (value is not string valueAsString) - { - yield break; - } - - if (valueListConfiguration.Items.Contains(valueAsString) is false) - { - yield return new ValidationResult( - $"The value {valueAsString} is not a part of the pre-values", ["items"]); - } - } -} diff --git a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs index c07baf4ca600..db37ff735a8c 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs @@ -25,16 +25,6 @@ public interface IPublishedCache /// The value of overrides defaults. IPublishedContent? GetById(bool preview, Guid contentId); - /// - /// Gets a content identified by its Udi identifier. - /// - /// A value indicating whether to consider unpublished content. - /// The content Udi identifier. - /// The content, or null. - /// The value of overrides defaults. - [Obsolete] // FIXME: Remove when replacing nucache - IPublishedContent? GetById(bool preview, Udi contentId); - /// /// Gets a content identified by its unique identifier. /// @@ -50,49 +40,4 @@ public interface IPublishedCache /// The content, or null. /// Considers published or unpublished content depending on defaults. IPublishedContent? GetById(Guid contentId); - - /// - /// Gets a content identified by its unique identifier. - /// - /// The content unique identifier. - /// The content, or null. - /// Considers published or unpublished content depending on defaults. - [Obsolete] // FIXME: Remove when replacing nucache - IPublishedContent? GetById(Udi contentId); - - /// - /// Gets contents at root. - /// - /// A value indicating whether to consider unpublished content. - /// A culture. - /// The contents. - /// The value of overrides defaults. - [Obsolete("Scheduled for removal, use IDocumentNavigationQueryService instead in v17")] - IEnumerable GetAtRoot(bool preview, string? culture = null); - - /// - /// Gets contents at root. - /// - /// A culture. - /// The contents. - /// Considers published or unpublished content depending on defaults. - [Obsolete("Scheduled for removal, use IDocumentNavigationQueryService instead in v17")] - IEnumerable GetAtRoot(string? culture = null); - - /// - /// Gets a value indicating whether the cache contains published content. - /// - /// A value indicating whether to consider unpublished content. - /// A value indicating whether the cache contains published content. - /// The value of overrides defaults. - [Obsolete("Scheduled for removal in v17")] - bool HasContent(bool preview); - - /// - /// Gets a value indicating whether the cache contains published content. - /// - /// A value indicating whether the cache contains published content. - /// Considers published or unpublished content depending on defaults. - [Obsolete("Scheduled for removal in v17")] - bool HasContent(); } diff --git a/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs b/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs index 8230b0f306d8..b2f0e7e277a7 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs @@ -44,46 +44,6 @@ public interface IPublishedContentCache : IPublishedCache /// The value of overrides defaults. /// [Obsolete] - IPublishedContent? GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string? culture = null); - - /// - /// Gets content identified by a route. - /// - /// The route - /// A value forcing the HideTopLevelNode setting. - /// The culture - /// The content, or null. - /// - /// - /// A valid route is either a simple path eg /foo/bar/nil or a root node id and a path, eg - /// 123/foo/bar/nil. - /// - /// - /// If - /// - /// is null then the settings value is used. - /// - /// Considers published or unpublished content depending on defaults. - /// - [Obsolete] - IPublishedContent? GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null); - - /// - /// Gets the route for a content identified by its unique identifier. - /// - /// A value indicating whether to consider unpublished content. - /// The content unique identifier. - /// The culture - /// A special string formatted route path. - /// - /// - /// The resulting string is a special encoded route string that may contain the domain ID - /// for the current route. If a domain is present the string will be prefixed with the domain ID integer, example: - /// {domainId}/route-path-of-item - /// - /// The value of overrides defaults. - /// - [Obsolete] string? GetRouteById(bool preview, int contentId, string? culture = null); /// diff --git a/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs index a37dba82c7bd..6dbc832a5b9d 100644 --- a/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs +++ b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs @@ -24,21 +24,10 @@ public PublishedCacheBase(IVariationContextAccessor variationContextAccessor, bo public IPublishedContent? GetById(Guid contentId) => GetById(PreviewDefault, contentId); - public abstract IPublishedContent? GetById(bool preview, Udi contentId); - - public IPublishedContent? GetById(Udi contentId) - => GetById(PreviewDefault, contentId); - public abstract bool HasById(bool preview, int contentId); public bool HasById(int contentId) => HasById(PreviewDefault, contentId); public abstract IEnumerable GetAtRoot(bool preview, string? culture = null); - - public IEnumerable GetAtRoot(string? culture = null) => GetAtRoot(PreviewDefault, culture); - - public abstract bool HasContent(bool preview); - - public bool HasContent() => HasContent(PreviewDefault); } diff --git a/src/Umbraco.Core/PublishedCache/PublishedElement.cs b/src/Umbraco.Core/PublishedCache/PublishedElement.cs index 9b0c6bcce664..c8d8acab4d2e 100644 --- a/src/Umbraco.Core/PublishedCache/PublishedElement.cs +++ b/src/Umbraco.Core/PublishedCache/PublishedElement.cs @@ -15,28 +15,8 @@ namespace Umbraco.Cms.Core.PublishedCache; // public class PublishedElement : IPublishedElement { - private readonly IPublishedProperty[] _propertiesArray; - [Obsolete("Please use the non-obsolete constructor. Will be removed in V17.")] - public PublishedElement(IPublishedContentType contentType, Guid key, Dictionary values, bool previewing) - : this(contentType, key, values, previewing, PropertyCacheLevel.None, null) - { - } - - [Obsolete("Please use the non-obsolete constructor. Will be removed in V17.")] - public PublishedElement(IPublishedContentType contentType, Guid key, Dictionary? values, bool previewing, PropertyCacheLevel referenceCacheLevel, ICacheManager? cacheManager) - : this( - contentType, - key, - values, - previewing, - referenceCacheLevel, - StaticServiceProvider.Instance.GetRequiredService().VariationContext ?? new VariationContext(), - cacheManager) - { - } - // initializes a new instance of the PublishedElement class // within the context of a published snapshot service (eg a published content property value) public PublishedElement(IPublishedContentType contentType, Guid key, Dictionary? values, bool previewing, PropertyCacheLevel referenceCacheLevel, VariationContext variationContext, ICacheManager? cacheManager) diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrl.cs b/src/Umbraco.Core/Routing/ContentFinderByUrl.cs index d2b2a564a70b..b5bed945a89d 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByUrl.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByUrl.cs @@ -10,6 +10,7 @@ namespace Umbraco.Cms.Core.Routing; /// /// Handles /foo/bar where /foo/bar is the nice URL of a document. /// +[Obsolete("Scheduled for removal in Umbraco 18")] public class ContentFinderByUrl : IContentFinder { private readonly ILogger _logger; @@ -60,41 +61,5 @@ public virtual Task TryFindContent(IPublishedRequestBuilder frequest) /// Tries to find an Umbraco document for a PublishedRequest and a route. /// /// The document node, or null. - protected IPublishedContent? FindContent(IPublishedRequestBuilder docreq, string route) - { - if (!UmbracoContextAccessor.TryGetUmbracoContext(out IUmbracoContext? umbracoContext)) - { - return null; - } - - if (docreq == null) - { - throw new ArgumentNullException(nameof(docreq)); - } - - if (_logger.IsEnabled(LogLevel.Debug)) - { - _logger.LogDebug("Test route {Route}", route); - } - - IPublishedContent? node = - umbracoContext.Content?.GetByRoute(umbracoContext.InPreviewMode, route, culture: docreq.Culture); - if (node != null) - { - docreq.SetPublishedContent(node); - if (_logger.IsEnabled(LogLevel.Debug)) - { - _logger.LogDebug("Got content, id={NodeId}", node.Id); - } - } - else - { - if (_logger.IsEnabled(LogLevel.Debug)) - { - _logger.LogDebug("No match."); - } - } - - return node; - } + protected IPublishedContent? FindContent(IPublishedRequestBuilder docreq, string route) => null; } diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs b/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs index 7f16b1fd48d6..7e9f41db4ee5 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs @@ -3,6 +3,7 @@ using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.Navigation; using Umbraco.Cms.Core.Web; using Umbraco.Extensions; @@ -26,7 +27,6 @@ public class ContentFinderByUrlAlias : IContentFinder private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IDocumentNavigationQueryService _documentNavigationQueryService; private readonly IPublishedContentStatusFilteringService _publishedContentStatusFilteringService; - /// /// Initializes a new instance of the class. /// @@ -44,61 +44,6 @@ public ContentFinderByUrlAlias( _logger = logger; } - [Obsolete("Please use tne non-obsolete constructor instead. Scheduled removal in v17")] - public ContentFinderByUrlAlias( - ILogger logger, - IPublishedValueFallback publishedValueFallback, - IVariationContextAccessor variationContextAccessor, - IUmbracoContextAccessor umbracoContextAccessor, - IPublishedContentCache contentCache, - IDocumentNavigationQueryService documentNavigationQueryService, - IPublishStatusQueryService publishStatusQueryService, - IPublishedContentStatusFilteringService publishedContentStatusFilteringService) - : this( - logger, - publishedValueFallback, - umbracoContextAccessor, - documentNavigationQueryService, - publishedContentStatusFilteringService) - { - } - - [Obsolete("Please use tne non-obsolete constructor instead. Scheduled removal in v17")] - public ContentFinderByUrlAlias( - ILogger logger, - IPublishedValueFallback publishedValueFallback, - IVariationContextAccessor variationContextAccessor, - IUmbracoContextAccessor umbracoContextAccessor, - IPublishedContentCache contentCache, - IDocumentNavigationQueryService documentNavigationQueryService, - IPublishStatusQueryService publishStatusQueryService) - : this( - logger, - publishedValueFallback, - umbracoContextAccessor, - documentNavigationQueryService, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - - [Obsolete("Please use tne non-obsolete constructor instead. Scheduled removal in v17")] - public ContentFinderByUrlAlias( - ILogger logger, - IPublishedValueFallback publishedValueFallback, - IVariationContextAccessor variationContextAccessor, - IUmbracoContextAccessor umbracoContextAccessor, - IPublishedContentCache contentCache, - IDocumentNavigationQueryService documentNavigationQueryService) - : this( - logger, - publishedValueFallback, - umbracoContextAccessor, - documentNavigationQueryService, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Tries to find and assign an Umbraco document to a PublishedRequest. /// @@ -204,7 +149,12 @@ bool IsMatch(IPublishedContent c, string a1, string a2) if (cache is not null) { - foreach (IPublishedContent rootContent in cache.GetAtRoot()) + if (_documentNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys) is false) + { + return null; + } + + foreach (IPublishedContent rootContent in rootKeys.Select(x => cache.GetById(false, x)).WhereNotNull()) { IPublishedContent? c = rootContent.DescendantsOrSelf(_documentNavigationQueryService, _publishedContentStatusFilteringService) .FirstOrDefault(x => IsMatch(x, test1, test2)); diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs b/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs index 200a7d71438e..32bbcb4f2388 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByUrlAndTemplate.cs @@ -24,6 +24,7 @@ namespace Umbraco.Cms.Core.Routing; /// /// If successful, then the template of the document request is also assigned. /// +[Obsolete("Scheduled for removal in Umbraco 18")] public class ContentFinderByUrlAndTemplate : ContentFinderByUrl { private readonly IContentTypeService _contentTypeService; diff --git a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs index 1ec57e20e59f..d06abb6c2b01 100644 --- a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs @@ -50,71 +50,6 @@ public DefaultUrlProvider( requestSettings.OnChange(x => _requestSettings = x); } - [Obsolete("Use the non-obsolete constructor. Scheduled for removal in V17.")] - public DefaultUrlProvider( - IOptionsMonitor requestSettings, - ILogger logger, - ISiteDomainMapper siteDomainMapper, - IUmbracoContextAccessor umbracoContextAccessor, - UriUtility uriUtility, - ILocalizationService localizationService, - IPublishedContentCache contentCache, - IDocumentNavigationQueryService navigationQueryService, - IPublishedContentStatusFilteringService publishedContentStatusFilteringService) - : this( - requestSettings, - logger, - siteDomainMapper, - umbracoContextAccessor, - uriUtility, - localizationService, - navigationQueryService, - publishedContentStatusFilteringService) - { - } - - [Obsolete("Use the non-obsolete constructor. Scheduled for removal in V17.")] - public DefaultUrlProvider( - IOptionsMonitor requestSettings, - ILogger logger, - ISiteDomainMapper siteDomainMapper, - IUmbracoContextAccessor umbracoContextAccessor, - UriUtility uriUtility, - ILocalizationService localizationService, - IPublishedContentCache contentCache, - IDocumentNavigationQueryService navigationQueryService) - : this( - requestSettings, - logger, - siteDomainMapper, - umbracoContextAccessor, - uriUtility, - localizationService, - navigationQueryService, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - [Obsolete("Use the non-obsolete constructor. Scheduled for removal in V17.")] - public DefaultUrlProvider( - IOptionsMonitor requestSettings, - ILogger logger, - ISiteDomainMapper siteDomainMapper, - IUmbracoContextAccessor umbracoContextAccessor, - UriUtility uriUtility, - ILocalizationService localizationService) - : this( - requestSettings, - logger, - siteDomainMapper, - umbracoContextAccessor, - uriUtility, - localizationService, - StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService()) - { - } - #region GetOtherUrls /// diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index 6b48a5a13c31..3f32a2f9d5c5 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -36,6 +36,7 @@ using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Services.Navigation; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Core.Templates; using Umbraco.Cms.Core.Web; @@ -206,7 +207,8 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde factory.GetRequiredService(), factory.GetRequiredService(), factory.GetRequiredService(), - factory.GetRequiredService()); + factory.GetRequiredService(), + factory.GetRequiredService()); }); // register accessors for cultures diff --git a/src/Umbraco.Infrastructure/PublishedContentQuery.cs b/src/Umbraco.Infrastructure/PublishedContentQuery.cs index 221a7545bade..1893ea2f1f4b 100644 --- a/src/Umbraco.Infrastructure/PublishedContentQuery.cs +++ b/src/Umbraco.Infrastructure/PublishedContentQuery.cs @@ -2,9 +2,12 @@ using System.Globalization; using Examine; using Examine.Search; +using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Cms.Core.Services.Navigation; using Umbraco.Cms.Infrastructure.Examine; using Umbraco.Extensions; @@ -20,6 +23,7 @@ public class PublishedContentQuery : IPublishedContentQuery private readonly IPublishedContentCache _publishedContent; private readonly IPublishedMediaCache _publishedMediaCache; private readonly IVariationContextAccessor _variationContextAccessor; + private readonly IDocumentNavigationQueryService _documentNavigationQueryService; private static readonly HashSet _returnedQueryFields = new() { ExamineFieldNames.ItemIdFieldName, ExamineFieldNames.CategoryFieldName }; @@ -30,13 +34,33 @@ public PublishedContentQuery( IVariationContextAccessor variationContextAccessor, IExamineManager examineManager, IPublishedContentCache publishedContent, - IPublishedMediaCache publishedMediaCache) + IPublishedMediaCache publishedMediaCache, + IDocumentNavigationQueryService documentNavigationQueryService) { _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _examineManager = examineManager ?? throw new ArgumentNullException(nameof(examineManager)); _publishedContent = publishedContent; _publishedMediaCache = publishedMediaCache; + _documentNavigationQueryService = documentNavigationQueryService; + } + + /// + /// Initializes a new instance of the class. + /// + [Obsolete("Scheduled for removal in Umbraco 18")] + public PublishedContentQuery( + IVariationContextAccessor variationContextAccessor, + IExamineManager examineManager, + IPublishedContentCache publishedContent, + IPublishedMediaCache publishedMediaCache) + : this( + variationContextAccessor, + examineManager, + publishedContent, + publishedMediaCache, + StaticServiceProvider.Instance.GetRequiredService()) + { } #region Convert Helpers @@ -212,8 +236,9 @@ private static IEnumerable ItemsByIds(IPublishedCache? cache, private IEnumerable ItemsByIds(IPublishedCache? cache, IEnumerable ids) => ids.Select(eachId => ItemById(eachId, cache)).WhereNotNull(); - private static IEnumerable ItemsAtRoot(IPublishedCache? cache) - => cache?.GetAtRoot() ?? Array.Empty(); + private IEnumerable ItemsAtRoot(IPublishedCache? cache) + => _documentNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys) is false ? [] + : rootKeys.Select(x => cache?.GetById(false, x)).WhereNotNull(); #endregion diff --git a/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs index d518ff1b1b85..99e5a7078ca9 100644 --- a/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs +++ b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs @@ -1,10 +1,14 @@ using System.Globalization; using Examine; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Services.Navigation; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Infrastructure; @@ -19,7 +23,10 @@ public class ContentFinderByConfigured404 : IContentLastChanceFinder private readonly IExamineManager _examineManager; private readonly ILogger _logger; private readonly IUmbracoContextAccessor _umbracoContextAccessor; + private readonly IDocumentUrlService _documentUrlService; + private readonly IPublishedContentCache _publishedContentCache; private readonly IVariationContextAccessor _variationContextAccessor; + private readonly IDocumentNavigationQueryService _documentNavigationQueryService; private ContentSettings _contentSettings; /// @@ -31,7 +38,10 @@ public ContentFinderByConfigured404( IOptionsMonitor contentSettings, IExamineManager examineManager, IVariationContextAccessor variationContextAccessor, - IUmbracoContextAccessor umbracoContextAccessor) + IUmbracoContextAccessor umbracoContextAccessor, + IDocumentUrlService documentUrlService, + IPublishedContentCache publishedContentCache, + IDocumentNavigationQueryService documentNavigationQueryService) { _logger = logger; _entityService = entityService; @@ -39,10 +49,34 @@ public ContentFinderByConfigured404( _examineManager = examineManager; _variationContextAccessor = variationContextAccessor; _umbracoContextAccessor = umbracoContextAccessor; + _documentUrlService = documentUrlService; + _publishedContentCache = publishedContentCache; + _documentNavigationQueryService = documentNavigationQueryService; contentSettings.OnChange(x => _contentSettings = x); } + [Obsolete("Scheduled for removal in Umbraco 18")] + public ContentFinderByConfigured404( + ILogger logger, + IEntityService entityService, + IOptionsMonitor contentSettings, + IExamineManager examineManager, + IVariationContextAccessor variationContextAccessor, + IUmbracoContextAccessor umbracoContextAccessor) + : this( + logger, + entityService, + contentSettings, + examineManager, + variationContextAccessor, + umbracoContextAccessor, + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService()) + { + } + /// /// Tries to find and assign an Umbraco document to a PublishedRequest. /// @@ -77,8 +111,13 @@ public Task TryFindContent(IPublishedRequestBuilder frequest) while (pos > 1) { route = route.Substring(0, pos); - node = umbracoContext.Content?.GetByRoute(route, culture: frequest?.Culture); - if (node != null) + Guid? keyByRoute = _documentUrlService.GetDocumentKeyByRoute(route, frequest.Culture, null, false); + if (keyByRoute is not null) + { + node = _publishedContentCache.GetById(keyByRoute.Value); + } + + if (node is not null) { break; } @@ -100,7 +139,7 @@ public Task TryFindContent(IPublishedRequestBuilder frequest) var error404 = NotFoundHandlerHelper.GetCurrentNotFoundPageId( _contentSettings.Error404Collection.ToArray(), _entityService, - new PublishedContentQuery(_variationContextAccessor, _examineManager, umbracoContext.Content!, umbracoContext.Media), + new PublishedContentQuery(_variationContextAccessor, _examineManager, umbracoContext.Content!, umbracoContext.Media, _documentNavigationQueryService), errorCulture, domainContentId); diff --git a/src/Umbraco.PublishedCache.HybridCache/DocumentCache.cs b/src/Umbraco.PublishedCache.HybridCache/DocumentCache.cs index c6570845dcc6..e4ccee3eb41d 100644 --- a/src/Umbraco.PublishedCache.HybridCache/DocumentCache.cs +++ b/src/Umbraco.PublishedCache.HybridCache/DocumentCache.cs @@ -43,30 +43,6 @@ public DocumentCache( public IPublishedContent? GetById(Guid contentId) => GetByIdAsync(contentId).GetAwaiter().GetResult(); - // TODO: These are all obsolete and should be removed - - [Obsolete("Scheduled for removal in v17")] - public IPublishedContent? GetById(bool preview, Udi contentId) - { - if(contentId is not GuidUdi guidUdi) - { - throw new NotSupportedException("Only GuidUdi is supported"); - } - - return GetById(preview, guidUdi.Guid); - } - - [Obsolete("Scheduled for removal in v17")] - public IPublishedContent? GetById(Udi contentId) - { - if(contentId is not GuidUdi guidUdi) - { - throw new NotSupportedException("Only GuidUdi is supported"); - } - - return GetById(guidUdi.Guid); - } - public IEnumerable GetAtRoot(bool preview, string? culture = null) { _documentNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys); @@ -75,34 +51,6 @@ public IEnumerable GetAtRoot(bool preview, string? culture = return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture)); } - public IEnumerable GetAtRoot(string? culture = null) - { - _documentNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys); - - IEnumerable rootContent = rootKeys.Select(key => GetById(key)).WhereNotNull(); - return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture)); - } - - [Obsolete("Scheduled for removal in v17")] - public bool HasContent(bool preview) => HasContent(); - - [Obsolete("Scheduled for removal in v17")] - public bool HasContent() => _documentUrlService.HasAny(); - - [Obsolete("Use IPublishedUrlProvider.GetUrl instead, scheduled for removal in v17")] - public IPublishedContent? GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string? culture = null) - { - Guid? key = _documentUrlService.GetDocumentKeyByRoute(route, culture, null, preview); - return key is not null ? GetById(preview, key.Value) : null; - } - - [Obsolete("Use IPublishedUrlProvider.GetUrl instead, scheduled for removal in v17")] - public IPublishedContent? GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null) - { - Guid? key = _documentUrlService.GetDocumentKeyByRoute(route, culture, null, false); - return key is not null ? GetById(key.Value) : null; - } - [Obsolete("Use IPublishedUrlProvider.GetUrl instead, scheduled for removal in v17")] public string? GetRouteById(bool preview, int contentId, string? culture = null) { diff --git a/src/Umbraco.PublishedCache.HybridCache/MediaCache.cs b/src/Umbraco.PublishedCache.HybridCache/MediaCache.cs index 95a98fabf9b9..368869c530c9 100644 --- a/src/Umbraco.PublishedCache.HybridCache/MediaCache.cs +++ b/src/Umbraco.PublishedCache.HybridCache/MediaCache.cs @@ -33,29 +33,6 @@ public MediaCache(IMediaCacheService mediaCacheService, IPublishedContentTypeCac public IPublishedContent? GetById(Guid contentId) => GetByIdAsync(contentId).GetAwaiter().GetResult(); - - [Obsolete("Scheduled for removal in v17")] - public IPublishedContent? GetById(bool preview, Udi contentId) - { - if(contentId is not GuidUdi guidUdi) - { - throw new NotSupportedException("Only GuidUdi is supported"); - } - - return GetById(preview, guidUdi.Guid); - } - - [Obsolete("Scheduled for removal in v17")] - public IPublishedContent? GetById(Udi contentId) - { - if(contentId is not GuidUdi guidUdi) - { - throw new NotSupportedException("Only GuidUdi is supported"); - } - - return GetById(guidUdi.Guid); - } - public IEnumerable GetAtRoot(bool preview, string? culture = null) { _mediaNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys); @@ -63,21 +40,4 @@ public IEnumerable GetAtRoot(bool preview, string? culture = IEnumerable rootContent = rootKeys.Select(key => GetById(preview, key)).WhereNotNull(); return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture)); } - - public IEnumerable GetAtRoot(string? culture = null) - { - _mediaNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys); - - IEnumerable rootContent = rootKeys.Select(key => GetById(key)).WhereNotNull(); - return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture)); - } - - [Obsolete("Media does not support preview, this method will be removed in future versions")] - public bool HasContent(bool preview) => HasContent(); - - public bool HasContent() - { - _mediaNavigationQueryService.TryGetRootKeys(out IEnumerable rootKeys); - return rootKeys.Any(); - } } diff --git a/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs b/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs index 4f90fe79f0e4..a3ba703b9b2a 100644 --- a/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs +++ b/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs @@ -1,36 +1,44 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Hosting; -using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Web.Website.Models; -using Umbraco.Extensions; namespace Umbraco.Cms.Web.Website.Controllers; public class RenderNoContentController : Controller { - private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; private readonly GlobalSettings _globalSettings; + private readonly IDocumentUrlService _urlService; + [ActivatorUtilitiesConstructor] public RenderNoContentController( - IUmbracoContextAccessor umbracoContextAccessor, IHostingEnvironment hostingEnvironment, - IOptionsSnapshot globalSettings) + IOptionsSnapshot globalSettings, + IDocumentUrlService urlService) { - _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings)); + _urlService = urlService; + } + + [Obsolete("Scheduled for removal in Umbraco 18")] + public RenderNoContentController( + IUmbracoContextAccessor umbracoContextAccessor, + IHostingEnvironment hostingEnvironment, + IOptionsSnapshot globalSettings) + : this(hostingEnvironment, globalSettings, StaticServiceProvider.Instance.GetRequiredService()) + { } public ActionResult Index() { - IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext(); - IPublishedContentCache? store = umbracoContext.Content; - if (store?.HasContent() ?? false) + if (_urlService.HasAny()) { // If there is actually content, go to the root. return Redirect("~/"); diff --git a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs index 2fd979d8ca92..0f4dd2be6d8a 100644 --- a/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Website/DependencyInjection/UmbracoBuilderExtensions.cs @@ -59,7 +59,8 @@ public static IUmbracoBuilder AddWebsite(this IUmbracoBuilder builder) x.GetRequiredService(), x.GetRequiredService(), x.GetRequiredService(), - x.GetRequiredService>())); + x.GetRequiredService>(), + x.GetRequiredService())); builder.Services.AddSingleton(); builder.Services.TryAddEnumerable(Singleton()); builder.Services.AddSingleton(); diff --git a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs index a990d981dbb5..5a42821b1ab0 100644 --- a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs +++ b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs @@ -5,9 +5,11 @@ using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Routing; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Web; @@ -45,6 +47,7 @@ public class UmbracoRouteValueTransformer : DynamicRouteValueTransformer private readonly IRuntimeState _runtime; private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IUmbracoVirtualPageRoute _umbracoVirtualPageRoute; + private readonly IDocumentUrlService _urlService; private GlobalSettings _globalSettings; /// @@ -61,7 +64,8 @@ public UmbracoRouteValueTransformer( IControllerActionSearcher controllerActionSearcher, IPublicAccessRequestHandler publicAccessRequestHandler, IUmbracoVirtualPageRoute umbracoVirtualPageRoute, - IOptionsMonitor globalSettings) + IOptionsMonitor globalSettings, + IDocumentUrlService urlService) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _umbracoContextAccessor = @@ -77,6 +81,39 @@ public UmbracoRouteValueTransformer( _umbracoVirtualPageRoute = umbracoVirtualPageRoute; _globalSettings = globalSettings.CurrentValue; globalSettings.OnChange(x => _globalSettings = x); + _urlService = urlService; + } + + /// + /// Initializes a new instance of the class. + /// + [Obsolete("Scheduled for removal in Umbraco 18")] + public UmbracoRouteValueTransformer( + ILogger logger, + IUmbracoContextAccessor umbracoContextAccessor, + IPublishedRouter publishedRouter, + IRuntimeState runtime, + IUmbracoRouteValuesFactory routeValuesFactory, + IRoutableDocumentFilter routableDocumentFilter, + IDataProtectionProvider dataProtectionProvider, + IControllerActionSearcher controllerActionSearcher, + IPublicAccessRequestHandler publicAccessRequestHandler, + IUmbracoVirtualPageRoute umbracoVirtualPageRoute, + IOptionsMonitor globalSettings) + : this( + logger, + umbracoContextAccessor, + publishedRouter, + runtime, + routeValuesFactory, + routableDocumentFilter, + dataProtectionProvider, + controllerActionSearcher, + publicAccessRequestHandler, + umbracoVirtualPageRoute, + globalSettings, + StaticServiceProvider.Instance.GetRequiredService()) + { } /// @@ -100,8 +137,7 @@ public override async ValueTask TransformAsync( } // Check if there is no existing content and return the no content controller - // FIXME: This should be changed to route cache, so instead, if there are any routes, we know there is content. - if (!umbracoContext.Content?.HasContent() ?? false) + if (!_urlService?.HasAny() ?? false) { return new RouteValueDictionary { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/PublishedContentQueryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/PublishedContentQueryTests.cs index 93ec1370ab2f..8f4411511b99 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/PublishedContentQueryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/PublishedContentQueryTests.cs @@ -3,11 +3,11 @@ using Examine.Lucene.Directories; using Examine.Lucene.Providers; using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Tokens; using Moq; using NUnit.Framework; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Cms.Core.Services.Navigation; using Umbraco.Cms.Infrastructure; using Umbraco.Cms.Infrastructure.Examine; using Umbraco.Cms.Tests.Common.Attributes; @@ -80,7 +80,7 @@ private PublishedContentQuery CreatePublishedContentQuery(IIndex indexer) var variationContext = new VariationContext(); var variationContextAccessor = Mock.Of(x => x.VariationContext == variationContext); - return new PublishedContentQuery(variationContextAccessor, examineManager.Object, contentCache.Object, Mock.Of()); + return new PublishedContentQuery(variationContextAccessor, examineManager.Object, contentCache.Object, Mock.Of(), Mock.Of()); } [TestCase("fr-fr", ExpectedResult = "1, 3", Description = "Search Culture: fr-fr. Must return both fr-fr and invariant results")] diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/ContentFinderByUrlAliasTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/ContentFinderByUrlAliasTests.cs index 11872abbfb10..c9ac3ffb45fd 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/ContentFinderByUrlAliasTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/ContentFinderByUrlAliasTests.cs @@ -43,7 +43,7 @@ public async Task Lookup_By_Url_Alias( var contentItem = rootContents[0]; Mock.Get(umbracoContextAccessor).Setup(x => x.TryGetUmbracoContext(out umbracoContext)).Returns(true); Mock.Get(umbracoContext).Setup(x => x.Content).Returns(publishedContentCache); - Mock.Get(publishedContentCache).Setup(x => x.GetAtRoot(null)).Returns(rootContents); + Mock.Get(publishedContentCache).Setup(x => x.GetById(false, It.IsAny())).Returns(contentItem); Mock.Get(contentItem).Setup(x => x.Id).Returns(nodeMatch); Mock.Get(contentItem).Setup(x => x.GetProperty(Constants.Conventions.Content.UrlAlias)).Returns(urlProperty); Mock.Get(contentItem).Setup(x => x.ItemType).Returns(PublishedItemType.Content); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/DeliveryApi/ApiRichTextMarkupParserTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/DeliveryApi/ApiRichTextMarkupParserTests.cs index 04c6df0882f0..ff297d5a0d71 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/DeliveryApi/ApiRichTextMarkupParserTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/DeliveryApi/ApiRichTextMarkupParserTests.cs @@ -112,20 +112,12 @@ private ApiRichTextMarkupParser BuildDefaultSut(Dictionary mockD .Returns((preview, key) => mockData[key].PublishedContent); contentCacheMock.Setup(cc => cc.GetById(It.IsAny())) .Returns(key => mockData[key].PublishedContent); - contentCacheMock.Setup(cc => cc.GetById(It.IsAny(), It.IsAny())) - .Returns((preview, udi) => mockData[((GuidUdi)udi).Guid].PublishedContent); - contentCacheMock.Setup(cc => cc.GetById(It.IsAny())) - .Returns(udi => mockData[((GuidUdi)udi).Guid].PublishedContent); var mediaCacheMock = new Mock(); mediaCacheMock.Setup(cc => cc.GetById(It.IsAny(), It.IsAny())) .Returns((preview, key) => mockData[key].PublishedContent); mediaCacheMock.Setup(cc => cc.GetById(It.IsAny())) .Returns(key => mockData[key].PublishedContent); - mediaCacheMock.Setup(cc => cc.GetById(It.IsAny(), It.IsAny())) - .Returns((preview, udi) => mockData[((GuidUdi)udi).Guid].PublishedContent); - mediaCacheMock.Setup(cc => cc.GetById(It.IsAny())) - .Returns(udi => mockData[((GuidUdi)udi).Guid].PublishedContent); _apiMediaUrlProvider = new Mock(); _apiMediaUrlProvider.Setup(mup => mup.GetUrl(It.IsAny())) diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/RenderNoContentControllerTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/RenderNoContentControllerTests.cs index 649ee47bde5e..b2630e7dd347 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/RenderNoContentControllerTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/RenderNoContentControllerTests.cs @@ -7,6 +7,7 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.IO; +using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Tests.Common; using Umbraco.Cms.Web.Website.Controllers; @@ -21,13 +22,13 @@ public class RenderNoContentControllerTests [Test] public void Redirects_To_Root_When_Content_Published() { - var mockUmbracoContext = new Mock(); - mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true); + var mockUrlService = new Mock(); + mockUrlService.Setup(x => x.HasAny()).Returns(true); var mockHostingEnvironment = new Mock(); var controller = new RenderNoContentController( - new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockHostingEnvironment.Object, - new TestOptionsSnapshot(new GlobalSettings())); + new TestOptionsSnapshot(new GlobalSettings()), + mockUrlService.Object); var result = controller.Index() as RedirectResult; @@ -41,8 +42,8 @@ public void Renders_View_When_No_Content_Published() const string umbracoPathSetting = Constants.System.DefaultUmbracoPath; const string umbracoPath = "/umbraco"; const string viewPath = "~/config/splashes/NoNodes.cshtml"; - var mockUmbracoContext = new Mock(); - mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(false); + var mockUrlService = new Mock(); + mockUrlService.Setup(x => x.HasAny()).Returns(false); var mockIOHelper = new Mock(); mockIOHelper.Setup(x => x.ResolveUrl(It.Is(y => y == umbracoPathSetting))).Returns(umbracoPath); var mockHostingEnvironment = new Mock(); @@ -53,7 +54,7 @@ public void Renders_View_When_No_Content_Published() { NoNodesViewPath = viewPath, }); - var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockHostingEnvironment.Object, globalSettings); + var controller = new RenderNoContentController(mockHostingEnvironment.Object, globalSettings, mockUrlService.Object); var result = controller.Index() as ViewResult; Assert.IsNotNull(result); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs index 338e3c55687b..a03f4db10290 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using System.Threading.Tasks; +using Lucene.Net.Search.Similarities; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; @@ -38,15 +39,17 @@ private UmbracoRouteValueTransformer GetTransformerWithRunState( IUmbracoContextAccessor ctx, IRoutableDocumentFilter filter = null, IPublishedRouter router = null, - IUmbracoRouteValuesFactory routeValuesFactory = null) - => GetTransformer(ctx, Mock.Of(x => x.Level == RuntimeLevel.Run), filter, router, routeValuesFactory); + IUmbracoRouteValuesFactory routeValuesFactory = null, + IDocumentUrlService documentUrlService = null) + => GetTransformer(ctx, Mock.Of(x => x.Level == RuntimeLevel.Run), filter, router, routeValuesFactory, documentUrlService); private UmbracoRouteValueTransformer GetTransformer( IUmbracoContextAccessor ctx, IRuntimeState state, IRoutableDocumentFilter filter = null, IPublishedRouter router = null, - IUmbracoRouteValuesFactory routeValuesFactory = null) + IUmbracoRouteValuesFactory routeValuesFactory = null, + IDocumentUrlService documentUrlService = null) { var publicAccessRequestHandler = new Mock(); publicAccessRequestHandler.Setup(x => @@ -67,13 +70,14 @@ private UmbracoRouteValueTransformer GetTransformer( Mock.Of(), publicAccessRequestHandler.Object, Mock.Of(), - Mock.Of>()); + Mock.Of>(), + documentUrlService ?? Mock.Of(x => x.HasAny() == true)); return transformer; } private IUmbracoContext GetUmbracoContext(bool hasContent) { - var publishedContent = Mock.Of(x => x.HasContent() == hasContent); + var publishedContent = Mock.Of(x => x.HasAny() == hasContent); var uri = new Uri("http://example.com"); var umbracoContext = Mock.Of(x => @@ -142,7 +146,11 @@ public async Task NoContentController_Values_When_No_Content() var umbracoContext = GetUmbracoContext(false); var transformer = GetTransformerWithRunState( - Mock.Of(x => x.TryGetUmbracoContext(out umbracoContext))); + Mock.Of(x => x.TryGetUmbracoContext(out umbracoContext)), + null, + null, + null, + Mock.Of(x => x.HasAny() == false)); var result = await transformer.TransformAsync(new DefaultHttpContext(), new RouteValueDictionary()); Assert.AreEqual(2, result.Count);