diff --git a/src/Umbraco.Core/Models/ContentScheduleCollection.cs b/src/Umbraco.Core/Models/ContentScheduleCollection.cs index 5f0a09285f..f1628f1645 100644 --- a/src/Umbraco.Core/Models/ContentScheduleCollection.cs +++ b/src/Umbraco.Core/Models/ContentScheduleCollection.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Models { public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneable, IEquatable { - //underlying storage for the collection backed by a sorted list so that the schedule is always in order of date + //underlying storage for the collection backed by a sorted list so that the schedule is always in order of date and that duplicate dates per culture are not allowed private readonly Dictionary> _schedule = new Dictionary>(StringComparer.InvariantCultureIgnoreCase); @@ -173,13 +173,11 @@ namespace Umbraco.Core.Models return Enumerable.Empty(); } - //fixme - should this just return IEnumerable since the culture is part of the ContentSchedule object already? /// - /// Returns all schedules for both invariant and variant cultures + /// Returns all schedules registered /// /// - public IReadOnlyDictionary> FullSchedule => _schedule.ToDictionary(x => x.Key, x => (IEnumerable)x.Value.Values); - //public IEnumerable FullSchedule => _schedule.SelectMany(x => x.Value.Values); + public IReadOnlyList FullSchedule => _schedule.SelectMany(x => x.Value.Values).ToList(); public object DeepClone() { @@ -203,8 +201,8 @@ namespace Umbraco.Core.Models public bool Equals(ContentScheduleCollection other) { - var thisSched = this.FullSchedule; - var thatSched = other.FullSchedule; + var thisSched = this._schedule; + var thatSched = other._schedule; var equal = false; if (thisSched.Count == thatSched.Count) diff --git a/src/Umbraco.Core/Persistence/Factories/ContentBaseFactory.cs b/src/Umbraco.Core/Persistence/Factories/ContentBaseFactory.cs index d821195df5..e7f8cc0094 100644 --- a/src/Umbraco.Core/Persistence/Factories/ContentBaseFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/ContentBaseFactory.cs @@ -176,20 +176,18 @@ namespace Umbraco.Core.Persistence.Factories public static IEnumerable BuildScheduleDto(IContent entity, ILanguageRepository languageRepository) { var schedule = new List(); - foreach (var schedByCulture in entity.ContentSchedule.FullSchedule) + foreach(var s in entity.ContentSchedule.FullSchedule) { - foreach (var cultureSched in schedByCulture.Value) + schedule.Add(new ContentScheduleDto { - schedule.Add(new ContentScheduleDto - { - Action = cultureSched.Change.ToString(), - Date = cultureSched.Date, - NodeId = entity.Id, - LanguageId = languageRepository.GetIdByIsoCode(schedByCulture.Key, false), - Id = cultureSched.Id - }); - } + Action = s.Change.ToString(), + Date = s.Date, + NodeId = entity.Id, + LanguageId = languageRepository.GetIdByIsoCode(s.Culture, false), + Id = s.Id + }); } + return schedule; } diff --git a/src/Umbraco.Core/Services/Implement/ContentService.cs b/src/Umbraco.Core/Services/Implement/ContentService.cs index 58f3cf2d3d..c1616308b3 100644 --- a/src/Umbraco.Core/Services/Implement/ContentService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentService.cs @@ -2475,9 +2475,7 @@ namespace Umbraco.Core.Services.Implement // they should be removed so they don't interrupt an unpublish // otherwise it would remain released == published - var pastReleases = content.ContentSchedule.FullSchedule.SelectMany(x => x.Value) - .Where(x => x.Change == ContentScheduleChange.End && x.Date <= DateTime.Now) - .ToList(); + var pastReleases = content.ContentSchedule.GetPending(ContentScheduleChange.End, DateTime.Now); foreach (var p in pastReleases) content.ContentSchedule.Remove(p); if (pastReleases.Count > 0) diff --git a/src/Umbraco.Tests/Models/ContentScheduleTests.cs b/src/Umbraco.Tests/Models/ContentScheduleTests.cs index 345c345bd4..59df7f4d01 100644 --- a/src/Umbraco.Tests/Models/ContentScheduleTests.cs +++ b/src/Umbraco.Tests/Models/ContentScheduleTests.cs @@ -92,7 +92,7 @@ namespace Umbraco.Tests.Models Assert.AreEqual(1, schedule.GetSchedule(ContentScheduleChange.Start).Count()); Assert.AreEqual(1, schedule.GetSchedule("en-US", ContentScheduleChange.End).Count()); Assert.AreEqual(1, schedule.GetSchedule("en-US", ContentScheduleChange.Start).Count()); - Assert.AreEqual(2, schedule.FullSchedule.Count()); + Assert.AreEqual(3, schedule.FullSchedule.Count()); schedule.Clear("en-US", ContentScheduleChange.End); diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index fbcadb3ddc..305ef68f28 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -355,7 +355,7 @@ namespace Umbraco.Tests.Services content = contentService.GetById(content.Id); var sched = content.ContentSchedule.FullSchedule; Assert.AreEqual(1, sched.Count()); - Assert.AreEqual(1, sched[string.Empty].Count()); + Assert.AreEqual(1, sched.Count(x => x.Culture == string.Empty)); content.ContentSchedule.Clear(ContentScheduleChange.End); contentService.Save(content, Constants.Security.SuperUserId);