diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index 6de1bc71c9..75d5a5f113 100644 --- a/src/Umbraco.Core/Models/ContentBase.cs +++ b/src/Umbraco.Core/Models/ContentBase.cs @@ -302,6 +302,8 @@ namespace Umbraco.Core.Models if (Properties.Contains(propertyTypeAlias)) { Properties[propertyTypeAlias].SetValue(value, culture, segment); + //bump the culture to be flagged for updating + this.TouchCulture(culture); return; } @@ -312,6 +314,9 @@ namespace Umbraco.Core.Models var property = propertyType.CreateProperty(); property.SetValue(value, culture, segment); Properties.Add(property); + + //bump the culture to be flagged for updating + this.TouchCulture(culture); } #endregion diff --git a/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs b/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs index 287182d20e..52f6f9adb6 100644 --- a/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs +++ b/src/Umbraco.Core/Models/ContentCultureInfosCollection.cs @@ -17,21 +17,7 @@ namespace Umbraco.Core.Models public ContentCultureInfosCollection() : base(x => x.Culture, StringComparer.InvariantCultureIgnoreCase) { } - - /// - /// Initializes a new instance of the class with items. - /// - public ContentCultureInfosCollection(IEnumerable items) - : base(x => x.Culture, StringComparer.InvariantCultureIgnoreCase) - { - // make sure to add *copies* and not the original items, - // as items can be modified by AddOrUpdate, and therefore - // the new collection would be impacted by changes made - // to the old collection - foreach (var item in items) - Add(new ContentCultureInfos(item)); - } - + /// /// Adds or updates a instance. /// diff --git a/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs b/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs index 31e040f2d4..8d4e962ae1 100644 --- a/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs +++ b/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs @@ -142,7 +142,15 @@ namespace Umbraco.Core.Models content.PublishCultureInfos.AddOrUpdate(culture, name, date); } - // adjust dates to sync between version, cultures etc used by the repo when persisting + /// + /// Used to synchronize all culture dates to the same date if they've been modified + /// + /// + /// + /// + /// This is so that in an operation where (for example) 2 languages are updates like french and english, it is possible that + /// these dates assigned to them differ by a couple of Ticks, but we need to ensure they are persisted at the exact same time. + /// public static void AdjustDates(this IContent content, DateTime date) { foreach (var culture in content.PublishedCultures.ToList()) @@ -150,11 +158,9 @@ namespace Umbraco.Core.Models if (!content.PublishCultureInfos.TryGetValue(culture, out var publishInfos)) continue; - //fixme: Removing the logic here for the old WasCulturePublished and the _publishInfosOrig has broken - // the test Can_Rollback_Version_On_Multilingual, but we need to understand what it's doing since I don't - - //fixme: Because this is being called, we end up updating a culture which triggers the dirty change tracking - // which ends up in error because the culture is not actually being updated which causes the tests to fail + if (!publishInfos.IsDirty()) + continue; //if it's not dirty, it means it hasn't changed so there's nothing to adjust + content.PublishCultureInfos.AddOrUpdate(culture, publishInfos.Name, date); if (content.CultureInfos.TryGetValue(culture, out var infos)) @@ -276,7 +282,7 @@ namespace Umbraco.Core.Models /// /// Updates a culture date, if the culture exists. /// - public static void TouchCulture(this IContent content, string culture) + public static void TouchCulture(this IContentBase content, string culture) { if (!content.CultureInfos.TryGetValue(culture, out var infos)) return; content.CultureInfos.AddOrUpdate(culture, infos.Name, DateTime.Now); diff --git a/src/Umbraco.Tests/Services/ContentServiceEventTests.cs b/src/Umbraco.Tests/Services/ContentServiceEventTests.cs index b4fde295a7..1547ec232a 100644 --- a/src/Umbraco.Tests/Services/ContentServiceEventTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceEventTests.cs @@ -64,8 +64,8 @@ namespace Umbraco.Tests.Services Assert.AreSame(document, saved); - Assert.IsTrue(e.IsSavingCulture(saved, "fr-FR")); - Assert.IsFalse(e.IsSavingCulture(saved, "en-UK")); + Assert.IsTrue(e.IsSavingCulture(saved, "en-US")); + Assert.IsFalse(e.IsSavingCulture(saved, "fr-FR")); } void OnSaved(IContentService sender, ContentSavedEventArgs e) @@ -74,8 +74,8 @@ namespace Umbraco.Tests.Services Assert.AreSame(document, saved); - Assert.IsTrue(e.HasSavedCulture(saved, "fr-FR")); - Assert.IsFalse(e.HasSavedCulture(saved, "en-UK")); + Assert.IsTrue(e.HasSavedCulture(saved, "en-US")); + Assert.IsFalse(e.HasSavedCulture(saved, "fr-FR")); } ContentService.Saving += OnSaving;