From 2f737fbbcd2cc7b5c815157a9e898ec9a0f909d0 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Fri, 19 Feb 2021 13:57:38 +0100 Subject: [PATCH 1/6] Remove legacy member cache refresher and unused typed cache refresher base class --- .../Cache/MemberCacheRefresher.cs | 41 ------------------- .../Cache/TypedCacheRefresherBase.cs | 36 ---------------- 2 files changed, 77 deletions(-) delete mode 100644 src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs diff --git a/src/Umbraco.Core/Cache/MemberCacheRefresher.cs b/src/Umbraco.Core/Cache/MemberCacheRefresher.cs index 2d0ce7da16..9fd2ed8fda 100644 --- a/src/Umbraco.Core/Cache/MemberCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/MemberCacheRefresher.cs @@ -12,13 +12,11 @@ namespace Umbraco.Cms.Core.Cache public sealed class MemberCacheRefresher : PayloadCacheRefresherBase { private readonly IIdKeyMap _idKeyMap; - private readonly LegacyMemberCacheRefresher _legacyMemberRefresher; public MemberCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IIdKeyMap idKeyMap) : base(appCaches, serializer) { _idKeyMap = idKeyMap; - _legacyMemberRefresher = new LegacyMemberCacheRefresher(this, appCaches); } public class JsonPayload @@ -66,12 +64,6 @@ namespace Umbraco.Cms.Core.Cache base.Remove(id); } - [Obsolete("This is no longer used and will be removed from the codebase in the future")] - public void Refresh(IMember instance) => _legacyMemberRefresher.Refresh(instance); - - [Obsolete("This is no longer used and will be removed from the codebase in the future")] - public void Remove(IMember instance) => _legacyMemberRefresher.Remove(instance); - private void ClearCache(params JsonPayload[] payloads) { AppCaches.ClearPartialViewCache(); @@ -99,38 +91,5 @@ namespace Umbraco.Cms.Core.Cache } #endregion - - #region Backwards Compat - - // TODO: this is here purely for backwards compat but should be removed in netcore - private class LegacyMemberCacheRefresher : TypedCacheRefresherBase - { - private readonly MemberCacheRefresher _parent; - - public LegacyMemberCacheRefresher(MemberCacheRefresher parent, AppCaches appCaches) : base(appCaches) - { - _parent = parent; - } - - public override Guid RefresherUniqueId => _parent.RefresherUniqueId; - - public override string Name => _parent.Name; - - protected override MemberCacheRefresher This => _parent; - - public override void Refresh(IMember instance) - { - _parent.ClearCache(new JsonPayload(instance.Id, instance.Username)); - base.Refresh(instance.Id); - } - - public override void Remove(IMember instance) - { - _parent.ClearCache(new JsonPayload(instance.Id, instance.Username)); - base.Remove(instance); - } - } - - #endregion } } diff --git a/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs b/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs deleted file mode 100644 index 9c9314aeae..0000000000 --- a/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Umbraco.Cms.Core.Sync; - -namespace Umbraco.Cms.Core.Cache -{ - /// - /// A base class for "typed" cache refreshers. - /// - /// The actual cache refresher type. - /// The entity type. - /// The actual cache refresher type is used for strongly typed events. - public abstract class TypedCacheRefresherBase : CacheRefresherBase, ICacheRefresher - where TInstanceType : class, ICacheRefresher - { - /// - /// Initializes a new instance of the . - /// - /// A cache helper. - protected TypedCacheRefresherBase(AppCaches appCaches) - : base(appCaches) - { } - - #region Refresher - - public virtual void Refresh(TEntityType instance) - { - OnCacheUpdated(This, new CacheRefresherEventArgs(instance, MessageType.RefreshByInstance)); - } - - public virtual void Remove(TEntityType instance) - { - OnCacheUpdated(This, new CacheRefresherEventArgs(instance, MessageType.RemoveByInstance)); - } - - #endregion - } -} From 71dacf474e0cc733f139263d7f916278d6429ab5 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Fri, 19 Feb 2021 14:10:56 +0100 Subject: [PATCH 2/6] Remove obsolete configuration references --- .../Configuration/Models/GlobalSettings.cs | 9 -- src/Umbraco.Core/Constants-AppSettings.cs | 152 ------------------ .../PublishedMediaCache.cs | 17 +- 3 files changed, 3 insertions(+), 175 deletions(-) delete mode 100644 src/Umbraco.Core/Constants-AppSettings.cs diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index ada191a46b..45abc39268 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -24,15 +24,6 @@ namespace Umbraco.Cms.Core.Configuration.Models /// public string ReservedPaths { get; set; } = StaticReservedPaths; - /// - /// Gets or sets a value for the configuration status. - /// - /// - /// TODO: https://github.com/umbraco/Umbraco-CMS/issues/4238 - stop having version in web.config appSettings - /// TODO: previously this would throw on set, but presumably we can't do that if we do still want this in config. - /// - public string ConfigurationStatus { get; set; } - /// /// Gets or sets a value for the timeout in minutes. /// diff --git a/src/Umbraco.Core/Constants-AppSettings.cs b/src/Umbraco.Core/Constants-AppSettings.cs deleted file mode 100644 index 1fd3720bb9..0000000000 --- a/src/Umbraco.Core/Constants-AppSettings.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System; - -namespace Umbraco.Cms.Core -{ - public static partial class Constants - { - /// - /// Specific web.config AppSetting keys for Umbraco.Core application - /// - public static class AppSettings - { - // TODO: Are these all obsolete in netcore now? - - public const string MainDomLock = "Umbraco.Core.MainDom.Lock"; - - // TODO: Kill me - still used in Umbraco.Core.IO.SystemFiles:27 - [Obsolete("We need to kill this appsetting as we do not use XML content cache umbraco.config anymore due to NuCache")] - public const string ContentXML = "Umbraco.Core.ContentXML"; //umbracoContentXML - - /// - /// TODO: FILL ME IN - /// - public const string RegisterType = "Umbraco.Core.RegisterType"; - - /// - /// This is used for a unit test in PublishedMediaCache - /// - public const string PublishedMediaCacheSeconds = "Umbraco.Core.PublishedMediaCacheSeconds"; - - /// - /// TODO: FILL ME IN - /// - public const string AssembliesAcceptingLoadExceptions = "Umbraco.Core.AssembliesAcceptingLoadExceptions"; - - /// - /// This will return the version number of the currently installed umbraco instance - /// - /// - /// Umbraco will automatically set & modify this value when installing & upgrading - /// - public const string ConfigurationStatus = "Umbraco.Core.ConfigurationStatus"; - - /// - /// The path to umbraco's root directory (/umbraco by default). - /// - public const string UmbracoPath = "Umbraco.Core.Path"; - - /// - /// Gets the path to umbraco's icons directory (/umbraco/assets/icons by default). - /// - public const string IconsPath = "Umbraco.Icons.Path"; - - /// - /// The reserved urls from web.config. - /// - public const string ReservedUrls = "Umbraco.Core.ReservedUrls"; - - /// - /// The path of the stylesheet folder. - /// - public const string UmbracoCssPath = "Umbraco.Web.CssPath"; - - /// - /// The path of script folder. - /// - public const string UmbracoScriptsPath = "Umbraco.Core.ScriptsPath"; - - /// - /// The path of media folder. - /// - public const string UmbracoMediaPath = "Umbraco.Core.MediaPath"; - - /// - /// The reserved paths from web.config - /// - public const string ReservedPaths = "Umbraco.Core.ReservedPaths"; - - /// - /// Set the timeout for the Umbraco backoffice in minutes - /// - public const string TimeOutInMinutes = "Umbraco.Core.TimeOutInMinutes"; - - /// - /// The number of days to check for a new version of Umbraco - /// - /// - /// Default is set to 7. Setting this to 0 will never check - /// This is used to help track statistics - /// - public const string VersionCheckPeriod = "Umbraco.Core.VersionCheckPeriod"; - - /// - /// This is the location type to store temporary files such as cache files or other localized files for a given machine - /// - /// - /// Currently used for the xml cache file and the plugin cache files - /// - public const string LocalTempStorage = "Umbraco.Core.LocalTempStorage"; - - /// - /// The default UI language of the backoffice such as 'en-US' - /// - public const string DefaultUILanguage = "Umbraco.Core.DefaultUILanguage"; - - /// - /// A true/false value indicating whether umbraco should hide top level nodes from generated URLs. - /// - public const string HideTopLevelNodeFromPath = "Umbraco.Core.HideTopLevelNodeFromPath"; - - /// - /// A true or false indicating whether umbraco should force a secure (https) connection to the backoffice. - /// - public const string UseHttps = "Umbraco.Core.UseHttps"; - - /// - /// TODO: FILL ME IN - /// - public const string DisableElectionForSingleServer = "Umbraco.Core.DisableElectionForSingleServer"; - - /// - /// Gets the path to the razor file used when no published content is available. - /// - public const string NoNodesViewPath = "Umbraco.Core.NoNodesViewPath"; - - /// - /// Debug specific web.config AppSetting keys for Umbraco - /// - /// - /// Do not use these keys in a production environment - /// - public static class Debug - { - /// - /// When set to true, Scope logs the stack trace for any scope that gets disposed without being completed. - /// this helps troubleshooting rogue scopes that we forget to complete - /// - public const string LogUncompletedScopes = "Umbraco.Core.Debug.LogUncompletedScopes"; - - /// - /// When set to true, the Logger creates a mini dump of w3wp in ~/App_Data/MiniDump whenever it logs - /// an error due to a ThreadAbortException that is due to a timeout. - /// - public const string DumpOnTimeoutThreadAbort = "Umbraco.Core.Debug.DumpOnTimeoutThreadAbort"; - - /// - /// TODO: FILL ME IN - /// - public const string DatabaseFactoryServerVersion = "Umbraco.Core.Debug.DatabaseFactoryServerVersion"; - } - } - } -} diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs index 8536c2ce33..0db61264ee 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Configuration; using System.IO; @@ -636,19 +636,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache private static void InitializeCacheConfig() { - var value = ConfigurationManager.AppSettings[Constants.AppSettings.PublishedMediaCacheSeconds]; - int seconds; - if (int.TryParse(value, out seconds) == false) - seconds = PublishedMediaCacheTimespanSeconds; - if (seconds > 0) - { - _publishedMediaCacheEnabled = true; - _publishedMediaCacheTimespan = TimeSpan.FromSeconds(seconds); - } - else - { - _publishedMediaCacheEnabled = false; - } + _publishedMediaCacheEnabled = true; + _publishedMediaCacheTimespan = TimeSpan.FromSeconds(PublishedMediaCacheTimespanSeconds); } internal IPublishedContent CreateFromCacheValues(CacheValues cacheValues) From 764014fd6376a7b9b1986f190b4f3ed82847b5c3 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Fri, 19 Feb 2021 14:26:55 +0100 Subject: [PATCH 3/6] Rename UmbracoVersion.Current to UmbracoVersion.Version --- src/Umbraco.Core/Configuration/IUmbracoVersion.cs | 2 +- src/Umbraco.Core/Configuration/UmbracoVersion.cs | 7 +++---- src/Umbraco.Core/Models/UpgradeCheckResponse.cs | 4 ++-- src/Umbraco.Core/Packaging/PackageDefinitionXmlParser.cs | 4 ++-- src/Umbraco.Infrastructure/Install/InstallHelper.cs | 8 ++++---- .../Install/InstallSteps/StarterKitDownloadStep.cs | 4 ++-- src/Umbraco.Infrastructure/RuntimeState.cs | 4 ++-- .../Controllers/PackageInstallController.cs | 6 +++--- .../Controllers/UpdateCheckController.cs | 6 +++--- .../Security/Providers/UmbracoMembershipProvider.cs | 6 +++--- 10 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/Umbraco.Core/Configuration/IUmbracoVersion.cs b/src/Umbraco.Core/Configuration/IUmbracoVersion.cs index 4e6e6e92e6..a7aae5e0cf 100644 --- a/src/Umbraco.Core/Configuration/IUmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/IUmbracoVersion.cs @@ -8,7 +8,7 @@ namespace Umbraco.Cms.Core.Configuration /// /// Gets the non-semantic version of the Umbraco code. /// - Version Current { get; } + Version Version { get; } /// /// Gets the semantic version comments of the Umbraco code. diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index c67ae5a7e5..2c0ba395ef 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using Umbraco.Cms.Core.Semver; using Umbraco.Extensions; @@ -25,14 +25,13 @@ namespace Umbraco.Cms.Core.Configuration SemanticVersion = SemVersion.Parse(umbracoCoreAssembly.GetCustomAttribute().InformationalVersion); // gets the non-semantic version - Current = SemanticVersion.GetVersion(3); + Version = SemanticVersion.GetVersion(3); } /// /// Gets the non-semantic version of the Umbraco code. /// - // TODO: rename to Version - public Version Current { get; } + public Version Version { get; } /// /// Gets the semantic version comments of the Umbraco code. diff --git a/src/Umbraco.Core/Models/UpgradeCheckResponse.cs b/src/Umbraco.Core/Models/UpgradeCheckResponse.cs index 8f036ca30f..8ac335e6e7 100644 --- a/src/Umbraco.Core/Models/UpgradeCheckResponse.cs +++ b/src/Umbraco.Core/Models/UpgradeCheckResponse.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using System.Runtime.Serialization; using Umbraco.Cms.Core.Configuration; @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.Models { Type = upgradeType; Comment = upgradeComment; - Url = upgradeUrl + "?version=" + WebUtility.UrlEncode(umbracoVersion.Current.ToString(3)); + Url = upgradeUrl + "?version=" + WebUtility.UrlEncode(umbracoVersion.Version.ToString(3)); } } } diff --git a/src/Umbraco.Core/Packaging/PackageDefinitionXmlParser.cs b/src/Umbraco.Core/Packaging/PackageDefinitionXmlParser.cs index 3ba47f09c0..14e6790f3c 100644 --- a/src/Umbraco.Core/Packaging/PackageDefinitionXmlParser.cs +++ b/src/Umbraco.Core/Packaging/PackageDefinitionXmlParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; @@ -81,7 +81,7 @@ namespace Umbraco.Cms.Core.Packaging new XAttribute("name", def.Name ?? string.Empty), new XAttribute("packagePath", def.PackagePath ?? string.Empty), new XAttribute("iconUrl", def.IconUrl ?? string.Empty), - new XAttribute("umbVersion", def.UmbracoVersion ?? _umbracoVersion.Current), + new XAttribute("umbVersion", def.UmbracoVersion ?? _umbracoVersion.Version), new XAttribute("packageGuid", def.PackageId), new XAttribute("view", def.PackageView ?? string.Empty), diff --git a/src/Umbraco.Infrastructure/Install/InstallHelper.cs b/src/Umbraco.Infrastructure/Install/InstallHelper.cs index 291bd50a05..75165dfe30 100644 --- a/src/Umbraco.Infrastructure/Install/InstallHelper.cs +++ b/src/Umbraco.Infrastructure/Install/InstallHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -98,8 +98,8 @@ namespace Umbraco.Web.Install } var installLog = new InstallLog(installId: installId, isUpgrade: IsBrandNewInstall == false, - installCompleted: isCompleted, timestamp: DateTime.Now, versionMajor: _umbracoVersion.Current.Major, - versionMinor: _umbracoVersion.Current.Minor, versionPatch: _umbracoVersion.Current.Build, + installCompleted: isCompleted, timestamp: DateTime.Now, versionMajor: _umbracoVersion.Version.Major, + versionMinor: _umbracoVersion.Version.Minor, versionPatch: _umbracoVersion.Version.Build, versionComment: _umbracoVersion.Comment, error: errorMsg, userAgent: userAgent, dbProvider: dbProvider); @@ -145,7 +145,7 @@ namespace Umbraco.Web.Install var packages = new List(); try { - var requestUri = $"https://our.umbraco.com/webapi/StarterKit/Get/?umbracoVersion={_umbracoVersion.Current}"; + var requestUri = $"https://our.umbraco.com/webapi/StarterKit/Get/?umbracoVersion={_umbracoVersion.Version}"; using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri)) { diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitDownloadStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitDownloadStep.cs index 2baa9e9655..b5e7976a6b 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitDownloadStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/StarterKitDownloadStep.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -70,7 +70,7 @@ namespace Umbraco.Web.Install.InstallSteps private async Task<(string packageFile, int packageId)> DownloadPackageFilesAsync(Guid kitGuid) { //Go get the package file from the package repo - var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, _umbracoVersion.Current, _backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0)); + var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, _umbracoVersion.Version, _backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0)); if (packageFile == null) throw new InvalidOperationException("Could not fetch package file " + kitGuid); //add an entry to the installedPackages.config diff --git a/src/Umbraco.Infrastructure/RuntimeState.cs b/src/Umbraco.Infrastructure/RuntimeState.cs index baebbd23d6..2e3f6e0ba9 100644 --- a/src/Umbraco.Infrastructure/RuntimeState.cs +++ b/src/Umbraco.Infrastructure/RuntimeState.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -54,7 +54,7 @@ namespace Umbraco.Core /// - public Version Version => _umbracoVersion.Current; + public Version Version => _umbracoVersion.Version; /// public string VersionComment => _umbracoVersion.Comment; diff --git a/src/Umbraco.Web.BackOffice/Controllers/PackageInstallController.cs b/src/Umbraco.Web.BackOffice/Controllers/PackageInstallController.cs index 0da770c0c5..578e58ae20 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/PackageInstallController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/PackageInstallController.cs @@ -139,7 +139,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers if (ins.UmbracoVersionRequirementsType == RequirementsType.Strict) { var packageMinVersion = ins.UmbracoVersion; - if (_umbracoVersion.Current < packageMinVersion) + if (_umbracoVersion.Version < packageMinVersion) { model.IsCompatible = false; } @@ -223,7 +223,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers { var packageFile = await _packagingService.FetchPackageFileAsync( Guid.Parse(packageGuid), - _umbracoVersion.Current, + _umbracoVersion.Version, _backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0)); fileName = packageFile.Name; @@ -267,7 +267,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers if (packageInfo.UmbracoVersionRequirementsType == RequirementsType.Strict) { var packageMinVersion = packageInfo.UmbracoVersion; - if (_umbracoVersion.Current < packageMinVersion) + if (_umbracoVersion.Version < packageMinVersion) return ValidationErrorResult.CreateNotificationValidationErrorResult( _localizedTextService.Localize("packager/targetVersionMismatch", new[] {packageMinVersion.ToString()})); } diff --git a/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs b/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs index 2f1f887ba6..145b3a658f 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UpdateCheckController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -49,8 +49,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers { try { - var version = new SemVersion(_umbracoVersion.Current.Major, _umbracoVersion.Current.Minor, - _umbracoVersion.Current.Build, _umbracoVersion.Comment); + var version = new SemVersion(_umbracoVersion.Version.Major, _umbracoVersion.Version.Minor, + _umbracoVersion.Version.Build, _umbracoVersion.Comment); var result = await _upgradeService.CheckUpgrade(version); return new UpgradeCheckResponse(result.UpgradeType, result.Comment, result.UpgradeUrl, _umbracoVersion); diff --git a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs index 5c21e43b2a..986f501110 100644 --- a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Specialized; using System.Configuration.Provider; using System.Linq; @@ -319,7 +319,7 @@ namespace Umbraco.Web.Security.Providers if (userIsOnline) { // when upgrading from 7.2 to 7.3 trying to save will throw - if (_umbracoVersion.Current >= new Version(7, 3, 0, 0)) + if (_umbracoVersion.Version >= new Version(7, 3, 0, 0)) { var now = DateTime.Now; // update the database data directly instead of a full member save which requires DB locks @@ -566,7 +566,7 @@ namespace Umbraco.Web.Security.Providers if (requiresFullSave) { // when upgrading from 7.2 to 7.3 trying to save will throw - if (_umbracoVersion.Current >= new Version(7, 3, 0, 0)) + if (_umbracoVersion.Version >= new Version(7, 3, 0, 0)) MemberService.Save(member, false); } else From dd78fbd4476e3568eb432e1b92bc457456ccdc50 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Fri, 19 Feb 2021 16:50:05 +0100 Subject: [PATCH 4/6] Clean up the IO Helper interface, obsolete/remove unused/deprecated methods --- .../Extensions/StringExtensions.cs | 47 +------------------ src/Umbraco.Core/IO/IIOHelper.cs | 12 +---- src/Umbraco.Core/IO/IOHelper.cs | 21 +-------- .../StringExtensionsTests.cs | 13 ----- 4 files changed, 4 insertions(+), 89 deletions(-) diff --git a/src/Umbraco.Core/Extensions/StringExtensions.cs b/src/Umbraco.Core/Extensions/StringExtensions.cs index 8902712a19..70c959d09f 100644 --- a/src/Umbraco.Core/Extensions/StringExtensions.cs +++ b/src/Umbraco.Core/Extensions/StringExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System; @@ -1259,51 +1259,6 @@ namespace Umbraco.Extensions && Path.GetPathRoot(path).Equals(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) == false; } - /// - /// Based on the input string, this will detect if the string is a JS path or a JS snippet. - /// If a path cannot be determined, then it is assumed to be a snippet the original text is returned - /// with an invalid attempt, otherwise a valid attempt is returned with the resolved path - /// - /// - /// - /// - /// This is only used for legacy purposes for the Action.JsSource stuff and shouldn't be needed in v8 - /// - internal static Attempt DetectIsJavaScriptPath(this string input, IIOHelper ioHelper) - { - //validate that this is a url, if it is not, we'll assume that it is a text block and render it as a text - //block instead. - var isValid = true; - - if (Uri.IsWellFormedUriString(input, UriKind.RelativeOrAbsolute)) - { - //ok it validates, but so does alert('hello'); ! so we need to do more checks - - //here are the valid chars in a url without escaping - if (Regex.IsMatch(input, @"[^a-zA-Z0-9-._~:/?#\[\]@!$&'\(\)*\+,%;=]")) - isValid = false; - - //we'll have to be smarter and just check for certain js patterns now too! - var jsPatterns = new[] { @"\+\s*\=", @"\);", @"function\s*\(", @"!=", @"==" }; - if (jsPatterns.Any(p => Regex.IsMatch(input, p))) - isValid = false; - - if (isValid) - { - var resolvedUrlResult = ioHelper.TryResolveUrl(input); - //if the resolution was success, return it, otherwise just return the path, we've detected - // it's a path but maybe it's relative and resolution has failed, etc... in which case we're just - // returning what was given to us. - return resolvedUrlResult.Success - ? resolvedUrlResult - : Attempt.Succeed(input); - } - } - - return Attempt.Fail(input); - } - - // FORMAT STRINGS /// diff --git a/src/Umbraco.Core/IO/IIOHelper.cs b/src/Umbraco.Core/IO/IIOHelper.cs index a9057803f4..5a814ab386 100644 --- a/src/Umbraco.Core/IO/IIOHelper.cs +++ b/src/Umbraco.Core/IO/IIOHelper.cs @@ -8,11 +8,9 @@ namespace Umbraco.Cms.Core.IO { string FindFile(string virtualPath); - // TODO: This is the same as IHostingEnvironment.ToAbsolute + [Obsolete("Use IHostingEnvironment.ToAbsolute instead")] string ResolveUrl(string virtualPath); - Attempt TryResolveUrl(string virtualPath); - /// /// Maps a virtual path to a physical path in the content root folder (i.e. www) /// @@ -21,14 +19,6 @@ namespace Umbraco.Cms.Core.IO [Obsolete("Use IHostingEnvironment.MapPathContentRoot or IHostingEnvironment.MapPathWebRoot instead")] string MapPath(string path); - /// - /// Returns true if the path has a root, and is considered fully qualified for the OS it is on - /// See https://github.com/dotnet/runtime/blob/30769e8f31b20be10ca26e27ec279cd4e79412b9/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs#L281 for the .NET Standard 2.1 version of this - /// - /// The path to check - /// True if the path is fully qualified, false otherwise - bool IsPathFullyQualified(string path); - /// /// Verifies that the current filepath matches a directory where the user is allowed to edit a file. /// diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 56db480632..e799bbdbe8 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.IO return retval; } - // TODO: This is the same as IHostingEnvironment.ToAbsolute + // TODO: This is the same as IHostingEnvironment.ToAbsolute - marked as obsolete in IIOHelper for now public string ResolveUrl(string virtualPath) { if (string.IsNullOrWhiteSpace(virtualPath)) return virtualPath; @@ -44,23 +44,6 @@ namespace Umbraco.Cms.Core.IO } - public Attempt TryResolveUrl(string virtualPath) - { - try - { - if (virtualPath.StartsWith("~")) - return Attempt.Succeed(virtualPath.Replace("~", _hostingEnvironment.ApplicationVirtualPath).Replace("//", "/")); - if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) - return Attempt.Succeed(virtualPath); - - return Attempt.Succeed(_hostingEnvironment.ToAbsolute(virtualPath)); - } - catch (Exception ex) - { - return Attempt.Fail(virtualPath, ex); - } - } - public string MapPath(string path) { if (path == null) throw new ArgumentNullException(nameof(path)); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs index c6a5510986..74d80d8665 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/ShortStringHelper/StringExtensionsTests.cs @@ -37,19 +37,6 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.ShortStringHelper Assert.AreEqual(result, first.ToGuid() == second.ToGuid()); } - [TestCase("alert('hello');", false)] - [TestCase("~/Test.js", true)] - [TestCase("../Test.js", true)] - [TestCase("/Test.js", true)] - [TestCase("Test.js", true)] - [TestCase("Test.js==", false)] - [TestCase("/Test.js function(){return true;}", false)] - public void Detect_Is_JavaScript_Path(string input, bool result) - { - Attempt output = input.DetectIsJavaScriptPath(Mock.Of()); - Assert.AreEqual(result, output.Success); - } - [TestCase("hello.txt", "hello")] [TestCase("this.is.a.Txt", "this.is.a")] [TestCase("this.is.not.a. Txt", "this.is.not.a. Txt")] From 6b3041c1fb7ed860758b256a66ddec2099b5f3e8 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Fri, 19 Feb 2021 17:14:57 +0100 Subject: [PATCH 5/6] Removed unused Process() from IMigrationExpression --- .../Rename/Expressions/RenameColumnExpression.cs | 5 +---- .../Migrations/IMigrationExpression.cs | 3 +-- .../Migrations/MigrationExpressionBase.cs | 7 +------ 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Infrastructure/Migrations/Expressions/Rename/Expressions/RenameColumnExpression.cs b/src/Umbraco.Infrastructure/Migrations/Expressions/Rename/Expressions/RenameColumnExpression.cs index 3ab5fd27b9..d01194d48d 100644 --- a/src/Umbraco.Infrastructure/Migrations/Expressions/Rename/Expressions/RenameColumnExpression.cs +++ b/src/Umbraco.Infrastructure/Migrations/Expressions/Rename/Expressions/RenameColumnExpression.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Core.Migrations.Expressions.Rename.Expressions +namespace Umbraco.Core.Migrations.Expressions.Rename.Expressions { public class RenameColumnExpression : MigrationExpressionBase { @@ -10,9 +10,6 @@ public virtual string OldName { get; set; } public virtual string NewName { get; set; } - public override string Process(IMigrationContext context) - => GetSql(); - /// protected override string GetSql() { diff --git a/src/Umbraco.Infrastructure/Migrations/IMigrationExpression.cs b/src/Umbraco.Infrastructure/Migrations/IMigrationExpression.cs index c60126f63c..d315030a58 100644 --- a/src/Umbraco.Infrastructure/Migrations/IMigrationExpression.cs +++ b/src/Umbraco.Infrastructure/Migrations/IMigrationExpression.cs @@ -1,11 +1,10 @@ -namespace Umbraco.Core.Migrations +namespace Umbraco.Core.Migrations { /// /// Marker interface for migration expressions /// public interface IMigrationExpression { - string Process(IMigrationContext context); // TODO: remove that one? void Execute(); } } diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs b/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs index 56ba221205..7a9aa02d48 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationExpressionBase.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -34,11 +34,6 @@ namespace Umbraco.Core.Migrations public List Expressions => _expressions ?? (_expressions = new List()); - public virtual string Process(IMigrationContext context) - { - return ToString(); - } - protected virtual string GetSql() { return ToString(); From 7d1ecf5c22e8b04a340571336be30757ada44fd8 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Fri, 19 Feb 2021 17:21:38 +0100 Subject: [PATCH 6/6] Move implementation of obsolete method in UmbracoBuilderExtensions to TestHelper --- src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 9 ++++++++- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- src/Umbraco.Web/UmbracoBuilderExtensions.cs | 9 +-------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index d094be3b9c..272450c48e 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -62,7 +62,7 @@ namespace Umbraco.Tests.TestHelpers services.AddUnique(_ => SqlContext); - var factory = Current.Factory = composition.CreateServiceProvider(); + var factory = Current.Factory = TestHelper.CreateServiceProvider(composition); var pocoMappers = new NPoco.MapperCollection { new PocoMapper() }; var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init()); diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index cfce05e35b..909a528dad 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; @@ -18,6 +18,7 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Diagnostics; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.IO; @@ -345,5 +346,11 @@ namespace Umbraco.Tests.TestHelpers } public static IPublishedUrlProvider GetPublishedUrlProvider() => _testHelperInternal.GetPublishedUrlProvider(); + + public static IServiceProvider CreateServiceProvider(IUmbracoBuilder builder) + { + builder.Build(); + return builder.Services.BuildServiceProvider(); + } } } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 12bcbfdf6b..bb530de882 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -242,7 +242,7 @@ namespace Umbraco.Tests.Testing TestObjects = new TestObjects(); Compose(); - Current.Factory = Factory = Builder.CreateServiceProvider(); + Current.Factory = Factory = TestHelper.CreateServiceProvider(Builder); Initialize(); } diff --git a/src/Umbraco.Web/UmbracoBuilderExtensions.cs b/src/Umbraco.Web/UmbracoBuilderExtensions.cs index fb47f76ecb..fc9379ce9a 100644 --- a/src/Umbraco.Web/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web/UmbracoBuilderExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Routing; @@ -11,13 +11,6 @@ namespace Umbraco.Web /// public static class UmbracoBuilderExtensions { - [Obsolete("This extension method exists only to ease migration, please refactor")] - public static IServiceProvider CreateServiceProvider(this IUmbracoBuilder builder) - { - builder.Build(); - return builder.Services.BuildServiceProvider(); - } - #region Uniques ///