From e9b697b0c2943ef2eabfcda0eb3fca2b2cf70eea Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Tue, 17 Aug 2021 13:10:13 +0200 Subject: [PATCH] Cleanup --- .../ContentPickerValueConverter.cs | 2 -- .../MemberPickerValueConverter.cs | 2 -- .../IPublishedSnapshotAccessor.cs | 2 +- .../Templates/HtmlLocalLinkParser.cs | 8 +++++++- .../Web/HybridUmbracoContextAccessor.cs | 12 ++++++++++-- .../Web/IUmbracoContextAccessor.cs | 6 +++--- .../PublishedContentQueryAccessor.cs | 3 +-- .../PublishedSnapshotService.cs | 18 ++++++++++++++---- .../IUmbracoHelperAccessor.cs | 1 - 9 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs index e1b5d2e8e9..1f89fea12d 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs @@ -57,8 +57,6 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot(); if (inter is int id) { - - content = publishedSnapshot.Content.GetById(id); if (content != null) return content; diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs index f3f965d324..a891021ec4 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs @@ -55,8 +55,6 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters return null; } - - IPublishedContent member; var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot(); if (source is int id) diff --git a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotAccessor.cs b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotAccessor.cs index 99007f2e53..1fe2c9636b 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotAccessor.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotAccessor.cs @@ -1,7 +1,7 @@ namespace Umbraco.Cms.Core.PublishedCache { /// - /// Provides access to a TryGetPublishedSnapshot bool method that will return true if the "current" . is not null + /// Provides access to a TryGetPublishedSnapshot bool method that will return true if the "current" is not null. /// public interface IPublishedSnapshotAccessor { diff --git a/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs b/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs index 32441abbb8..a92548ea18 100644 --- a/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs +++ b/src/Umbraco.Core/Templates/HtmlLocalLinkParser.cs @@ -42,9 +42,15 @@ namespace Umbraco.Cms.Core.Templates /// public string EnsureInternalLinks(string text, bool preview) { - var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext(); + if (!_umbracoContextAccessor.TryGetUmbracoContext(out var umbracoContext)) + { + throw new InvalidOperationException("Could not parse internal links, there is no current UmbracoContext"); + } + if (!preview) + { return EnsureInternalLinks(text); + } using (umbracoContext.ForcedPreview(preview)) // force for URL provider { diff --git a/src/Umbraco.Core/Web/HybridUmbracoContextAccessor.cs b/src/Umbraco.Core/Web/HybridUmbracoContextAccessor.cs index 120995f761..5b7388d4f7 100644 --- a/src/Umbraco.Core/Web/HybridUmbracoContextAccessor.cs +++ b/src/Umbraco.Core/Web/HybridUmbracoContextAccessor.cs @@ -15,16 +15,24 @@ namespace Umbraco.Cms.Core.Web { } /// - /// Gets or sets the object. + /// Tries to get the object. /// - /// public bool TryGetUmbracoContext(out IUmbracoContext umbracoContext) { umbracoContext = Value; return umbracoContext is not null; } + + /// + /// Clears the current object. + /// public void Clear() => Value = null; + + /// + /// Sets the object. + /// + /// public void Set(IUmbracoContext umbracoContext) => Value = umbracoContext; } } diff --git a/src/Umbraco.Core/Web/IUmbracoContextAccessor.cs b/src/Umbraco.Core/Web/IUmbracoContextAccessor.cs index d2bb3af5a9..c0cd6061be 100644 --- a/src/Umbraco.Core/Web/IUmbracoContextAccessor.cs +++ b/src/Umbraco.Core/Web/IUmbracoContextAccessor.cs @@ -1,9 +1,9 @@ namespace Umbraco.Cms.Core.Web { /// - /// Provides access to a TryGetUmbracoContext bool method that will return true if the "current" . is not null. - /// Provides a Clear() method that will clear the current UmbracoContext. - /// Provides a Set() method that til set the current UmbracoContext. + /// Provides access to a TryGetUmbracoContext bool method that will return true if the "current" is not null. + /// Provides a Clear() method that will clear the current object. + /// Provides a Set() method that til set the current object. /// public interface IUmbracoContextAccessor { diff --git a/src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs b/src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs index 6ca23133db..9f716365a0 100644 --- a/src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs +++ b/src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs @@ -1,6 +1,5 @@ using System; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Infrastructure; namespace Umbraco.Cms.Core { @@ -9,12 +8,12 @@ namespace Umbraco.Cms.Core private readonly IServiceProvider _serviceProvider; public PublishedContentQueryAccessor(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider; + public bool TryGetValue(out IPublishedContentQuery publishedContentQuery) { publishedContentQuery = _serviceProvider.GetRequiredService(); return publishedContentQuery is not null; } - } } diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index e68278a8d6..15b9f7f070 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -117,7 +117,14 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache _publishedModelFactory = publishedModelFactory; } - protected PublishedSnapshot CurrentPublishedSnapshot { get { _publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot); return (PublishedSnapshot)publishedSnapshot; } } + protected PublishedSnapshot CurrentPublishedSnapshot + { + get + { + _publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot); + return (PublishedSnapshot)publishedSnapshot; + } + } // NOTE: These aren't used within this object but are made available internally to improve the IdKey lookup performance // when nucache is enabled. @@ -880,9 +887,12 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache break; case DomainChangeTypes.Refresh: var domain = _serviceContext.DomainService.GetById(payload.Id); - if (domain == null) continue; - if (domain.RootContentId.HasValue == false) continue; // anomaly - if (domain.LanguageIsoCode.IsNullOrWhiteSpace()) continue; // anomaly + if (domain == null) + continue; + if (domain.RootContentId.HasValue == false) + continue; // anomaly + if (domain.LanguageIsoCode.IsNullOrWhiteSpace()) + continue; // anomaly var culture = domain.LanguageIsoCode; _domainStore.SetLocked(domain.Id, new Domain(domain.Id, domain.DomainName, domain.RootContentId.Value, culture, domain.IsWildcard)); break; diff --git a/src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs b/src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs index f81a912df0..b2085bc175 100644 --- a/src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs +++ b/src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs @@ -3,6 +3,5 @@ namespace Umbraco.Cms.Web.Common public interface IUmbracoHelperAccessor { bool TryGetUmbracoHelper(out UmbracoHelper umbracoHelper); - } }