V17 - Properties and validators, removing obsoleted code (#19961)

* Removing obsoleted code from ApiMediaQueryService.cs

* Removing obsoleted code from ApiRichTextMarkupParserTests.cs

* Removing obsoleted code from ContentCacheRefresher.cs

* Removing obsoleted code from ContentFinderByUrlAlias.cs and adjusting its tests to use the new logic

* Removing obsoleted code from ContentFinderByUrl.cs & its dependencies

* Removing obsoleted code from ApiRichTextMarkupParserTests.cs

* Removing obsoleted code from DocumentCache.cs & its dependencies

* Removing obsoleted code from MediaCache.cs & its dependencies

* Removing obsoleted code from PublishedCacheBase.cs & its dependencies

* Removing obsoleted code from RenderNoContentController.cs and its tests

* Removing obsoleted code from UmbracoRouteValueTransformer.cs

* Removing obsoleted constructors from DefaultUrlProvider.cs

* Removing the RadioValueEditor.cs & RadioValueValidator.cs obsoleted classes.

* Removing obsolete constructor from MultipleValueValidator.cs

* Removing obsolete constructor from EmailValidator.cs

* Removing obsoleted code from DataValueReferenceFactoryCollection.cs

* Removing obsoleted code from ApiContentBuilderBase.cs

* Fixing constructor missing attribute

* Making use of the TryGet result

* Fixing use of obsoleted constructor

* Removing silly bookmark comment

* Fixing deleted code and restructuring to use new cache

* Making use of TryGetRootKeys bool, to return null if false.

* Extending code to use new constructor

* Updated PublishedContentQuery.cs to return empty array

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

---------

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
This commit is contained in:
Nicklas Kramer
2025-08-26 13:31:27 +02:00
committed by GitHub
parent 156bcdc98a
commit 2a6bb64c78
30 changed files with 177 additions and 595 deletions

View File

@@ -36,6 +36,7 @@ using Umbraco.Cms.Core.Scoping;
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 partial class UmbracoBuilderExtensions
factory.GetRequiredService<IVariationContextAccessor>(),
factory.GetRequiredService<IExamineManager>(),
factory.GetRequiredService<IPublishedContentCache>(),
factory.GetRequiredService<IPublishedMediaCache>());
factory.GetRequiredService<IPublishedMediaCache>(),
factory.GetRequiredService<IDocumentNavigationQueryService>());
});
// register accessors for cultures

View File

@@ -2,9 +2,12 @@ using System.Collections;
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<string> _returnedQueryFields =
new() { ExamineFieldNames.ItemIdFieldName, ExamineFieldNames.CategoryFieldName };
@@ -30,13 +34,33 @@ public class PublishedContentQuery : IPublishedContentQuery
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;
}
/// <summary>
/// Initializes a new instance of the <see cref="PublishedContentQuery" /> class.
/// </summary>
[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<IDocumentNavigationQueryService>())
{
}
#region Convert Helpers
@@ -212,8 +236,9 @@ public class PublishedContentQuery : IPublishedContentQuery
private IEnumerable<IPublishedContent> ItemsByIds(IPublishedCache? cache, IEnumerable<Guid> ids)
=> ids.Select(eachId => ItemById(eachId, cache)).WhereNotNull();
private static IEnumerable<IPublishedContent> ItemsAtRoot(IPublishedCache? cache)
=> cache?.GetAtRoot() ?? Array.Empty<IPublishedContent>();
private IEnumerable<IPublishedContent> ItemsAtRoot(IPublishedCache? cache)
=> _documentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys) is false ? []
: rootKeys.Select(x => cache?.GetById(false, x)).WhereNotNull();
#endregion

View File

@@ -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<ContentFinderByConfigured404> _logger;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IDocumentUrlService _documentUrlService;
private readonly IPublishedContentCache _publishedContentCache;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IDocumentNavigationQueryService _documentNavigationQueryService;
private ContentSettings _contentSettings;
/// <summary>
@@ -31,7 +38,10 @@ public class ContentFinderByConfigured404 : IContentLastChanceFinder
IOptionsMonitor<ContentSettings> contentSettings,
IExamineManager examineManager,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor)
IUmbracoContextAccessor umbracoContextAccessor,
IDocumentUrlService documentUrlService,
IPublishedContentCache publishedContentCache,
IDocumentNavigationQueryService documentNavigationQueryService)
{
_logger = logger;
_entityService = entityService;
@@ -39,10 +49,34 @@ public class ContentFinderByConfigured404 : IContentLastChanceFinder
_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<ContentFinderByConfigured404> logger,
IEntityService entityService,
IOptionsMonitor<ContentSettings> contentSettings,
IExamineManager examineManager,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor)
: this(
logger,
entityService,
contentSettings,
examineManager,
variationContextAccessor,
umbracoContextAccessor,
StaticServiceProvider.Instance.GetRequiredService<IDocumentUrlService>(),
StaticServiceProvider.Instance.GetRequiredService<IPublishedContentCache>(),
StaticServiceProvider.Instance.GetRequiredService<IDocumentNavigationQueryService>())
{
}
/// <summary>
/// Tries to find and assign an Umbraco document to a <c>PublishedRequest</c>.
/// </summary>
@@ -77,8 +111,13 @@ public class ContentFinderByConfigured404 : IContentLastChanceFinder
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 class ContentFinderByConfigured404 : IContentLastChanceFinder
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);