From 095633ba27afc72aa01991e1109f7735c9e5df6d Mon Sep 17 00:00:00 2001 From: Sebastiaan Jansssen Date: Fri, 9 Feb 2018 13:27:25 +0100 Subject: [PATCH 1/5] Test names were inverted --- src/Umbraco.Tests/ObjectExtensionsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests/ObjectExtensionsTests.cs b/src/Umbraco.Tests/ObjectExtensionsTests.cs index b3b27e30a7..2b00765019 100644 --- a/src/Umbraco.Tests/ObjectExtensionsTests.cs +++ b/src/Umbraco.Tests/ObjectExtensionsTests.cs @@ -277,7 +277,7 @@ namespace Umbraco.Tests [Test] public void ConvertToDateTimeTest() { - var conv = "2016-06-07".TryConvertTo(); + var conv = "2016-06-07".TryConvertTo(); Assert.IsTrue(conv); Assert.AreEqual(new DateTime(2016, 6, 7), conv.Result); } @@ -285,7 +285,7 @@ namespace Umbraco.Tests [Test] public void ConvertToNullableDateTimeTest() { - var conv = "2016-06-07".TryConvertTo(); + var conv = "2016-06-07".TryConvertTo(); Assert.IsTrue(conv); Assert.AreEqual(new DateTime(2016, 6, 7), conv.Result); } From a4c0342bdafe4c5e0d4aee8d012375a81bf4b73b Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 9 Feb 2018 14:09:03 +0100 Subject: [PATCH 2/5] Fixes broken MNTP by switching convert cases to the correct DataType --- .../ValueConverters/MultiNodeTreePickerPropertyConverter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerPropertyConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerPropertyConverter.cs index abe444435f..7a831094e5 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerPropertyConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerPropertyConverter.cs @@ -146,11 +146,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters switch (GetPublishedContentType(propertyType.DataTypeId)) { case PublishedItemType.Media: - contentFetcher = umbHelper.TypedMember; + contentFetcher = umbHelper.TypedMedia; break; case PublishedItemType.Member: - contentFetcher = umbHelper.TypedMedia; + contentFetcher = umbHelper.TypedMember; break; case PublishedItemType.Content: From e9007111804a4beb530affc659ce2f2c739c28c1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 14 Feb 2018 11:53:49 +1100 Subject: [PATCH 3/5] Updates the CDF version changer to to use a hash of the current version and the date time so that it's not constantly updated if it's not changed. --- .../ClientDependencyConfiguration.cs | 70 ++++++++++++++++++- .../Install/Controllers/InstallController.cs | 3 +- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs b/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs index 62cd1ab59c..a4438d81b8 100644 --- a/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs +++ b/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs @@ -1,10 +1,14 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; using System.Web; using System.Xml.Linq; using ClientDependency.Core.CompositeFiles.Providers; using ClientDependency.Core.Config; +using Semver; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -25,6 +29,70 @@ namespace Umbraco.Core.Configuration _fileName = IOHelper.MapPath(string.Format("{0}/ClientDependency.config", SystemDirectories.Config)); } + /// + /// Changes the version number in ClientDependency.config to a hashed value for the version and the DateTime.Day + /// + /// + /// + /// + /// Allows the developer to specify the date precision for the hash (i.e. "yyyyMMdd" would be a precision for the day) + /// + /// + public bool UpdateVersionNumber(SemVersion version, DateTime date, string dateFormat) + { + var byteContents = Encoding.Unicode.GetBytes(version + date.ToString(dateFormat)); + + //This is a way to convert a string to a long + //see https://www.codeproject.com/Articles/34309/Convert-String-to-bit-Integer + //We could much more easily use MD5 which would create us an INT but since that is not compliant with + //hashing standards we have to use SHA + int intHash; + using (var hash = SHA256.Create()) + { + var bytes = hash.ComputeHash(byteContents); + + var longResult = new[] { 0, 8, 16, 24 } + .Select(i => BitConverter.ToInt64(bytes, i)) + .Aggregate((x, y) => x ^ y); + + //CDF requires an INT, and although this isn't fail safe, it will work for our purposes. We are not hashing for crypto purposes + //so there could be some collisions with this conversion but it's not a problem for our purposes + //It's also important to note that the long.GetHashCode() implementation in .NET is this: return (int) this ^ (int) (this >> 32); + //which means that this value will not change per appdomain like some GetHashCode implementations. + intHash = longResult.GetHashCode(); + } + + try + { + var clientDependencyConfigXml = XDocument.Load(_fileName, LoadOptions.PreserveWhitespace); + if (clientDependencyConfigXml.Root != null) + { + + var versionAttribute = clientDependencyConfigXml.Root.Attribute("version"); + + //Set the new version to the hashcode of now + var oldVersion = versionAttribute.Value; + var newVersion = Math.Abs(intHash).ToString(); + + //don't update if it's the same version + if (oldVersion == newVersion) + return false; + + versionAttribute.SetValue(newVersion); + clientDependencyConfigXml.Save(_fileName, SaveOptions.DisableFormatting); + + _logger.Info(string.Format("Updated version number from {0} to {1}", oldVersion, newVersion)); + return true; + } + } + catch (Exception ex) + { + _logger.Error("Couldn't update ClientDependency version number", ex); + } + + return false; + } + /// /// Changes the version number in ClientDependency.config to a random value to avoid stale caches /// @@ -107,4 +175,4 @@ namespace Umbraco.Core.Configuration return success; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/Install/Controllers/InstallController.cs b/src/Umbraco.Web/Install/Controllers/InstallController.cs index 7e3336e1e8..12c9415b78 100644 --- a/src/Umbraco.Web/Install/Controllers/InstallController.cs +++ b/src/Umbraco.Web/Install/Controllers/InstallController.cs @@ -46,7 +46,8 @@ namespace Umbraco.Web.Install.Controllers { // Update ClientDependency version var clientDependencyConfig = new ClientDependencyConfiguration(ApplicationContext.Current.ProfilingLogger.Logger); - var clientDependencyUpdated = clientDependencyConfig.IncreaseVersionNumber(); + var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumberForVersion( + UmbracoVersion.GetSemanticVersion(), DateTime.UtcNow, "yyyyMMdd"); // Delete ClientDependency temp directories to make sure we get fresh caches var clientDependencyTempFilesDeleted = clientDependencyConfig.ClearTempFiles(HttpContext); From eae1ce70126786d563b291a3bc015de9d27bd037 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 14 Feb 2018 12:05:05 +1100 Subject: [PATCH 4/5] fixes build --- src/Umbraco.Web/Install/Controllers/InstallController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/Install/Controllers/InstallController.cs b/src/Umbraco.Web/Install/Controllers/InstallController.cs index 12c9415b78..f5859a44b8 100644 --- a/src/Umbraco.Web/Install/Controllers/InstallController.cs +++ b/src/Umbraco.Web/Install/Controllers/InstallController.cs @@ -45,8 +45,8 @@ namespace Umbraco.Web.Install.Controllers if (ApplicationContext.Current.IsUpgrading) { // Update ClientDependency version - var clientDependencyConfig = new ClientDependencyConfiguration(ApplicationContext.Current.ProfilingLogger.Logger); - var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumberForVersion( + var clientDependencyConfig = new ClientDependencyConfiguration(_umbracoContext.Application.ProfilingLogger.Logger); + var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumber( UmbracoVersion.GetSemanticVersion(), DateTime.UtcNow, "yyyyMMdd"); // Delete ClientDependency temp directories to make sure we get fresh caches var clientDependencyTempFilesDeleted = clientDependencyConfig.ClearTempFiles(HttpContext); From 4640cf56d1b391112fd9a9ae2d3d096e318b87f7 Mon Sep 17 00:00:00 2001 From: Sebastiaan Jansssen Date: Wed, 14 Feb 2018 10:23:58 +0100 Subject: [PATCH 5/5] Make change non-breaking --- .../ClientDependencyConfiguration.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs b/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs index a4438d81b8..3a08361bd6 100644 --- a/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs +++ b/src/Umbraco.Core/Configuration/ClientDependencyConfiguration.cs @@ -29,17 +29,26 @@ namespace Umbraco.Core.Configuration _fileName = IOHelper.MapPath(string.Format("{0}/ClientDependency.config", SystemDirectories.Config)); } + /// + /// Changes the version number in ClientDependency.config to a hashed value for the version and the DateTime.Now + /// + /// Boolean to indicate succesful update of the ClientDependency.config file + /// + [Obsolete("Use the overload specifying the date and dateFormat")] + public bool UpdateVersionNumber() + { + return UpdateVersionNumber(UmbracoVersion.GetSemanticVersion(), DateTime.UtcNow, "yyyyMMdd"); + } + /// /// Changes the version number in ClientDependency.config to a hashed value for the version and the DateTime.Day /// - /// - /// - /// - /// Allows the developer to specify the date precision for the hash (i.e. "yyyyMMdd" would be a precision for the day) - /// - /// + /// The version of Umbraco we're upgrading to + /// A date value to use in the hash to prevent this method from updating the version on each startup + /// Allows the developer to specify the date precision for the hash (i.e. "yyyyMMdd" would be a precision for the day) + /// Boolean to indicate succesful update of the ClientDependency.config file public bool UpdateVersionNumber(SemVersion version, DateTime date, string dateFormat) - { + { var byteContents = Encoding.Unicode.GetBytes(version + date.ToString(dateFormat)); //This is a way to convert a string to a long