Changes FullSchedule to just be a list

This commit is contained in:
Shannon
2018-11-08 13:15:56 +11:00
parent c4bce9ecb5
commit 99a8d899e0
5 changed files with 17 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ namespace Umbraco.Core.Models
{
public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneable, IEquatable<ContentScheduleCollection>
{
//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<string, SortedList<DateTime, ContentSchedule>> _schedule
= new Dictionary<string, SortedList<DateTime, ContentSchedule>>(StringComparer.InvariantCultureIgnoreCase);
@@ -173,13 +173,11 @@ namespace Umbraco.Core.Models
return Enumerable.Empty<ContentSchedule>();
}
//fixme - should this just return IEnumerable<ContentSchedule> since the culture is part of the ContentSchedule object already?
/// <summary>
/// Returns all schedules for both invariant and variant cultures
/// Returns all schedules registered
/// </summary>
/// <returns></returns>
public IReadOnlyDictionary<string, IEnumerable<ContentSchedule>> FullSchedule => _schedule.ToDictionary(x => x.Key, x => (IEnumerable<ContentSchedule>)x.Value.Values);
//public IEnumerable<ContentSchedule> FullSchedule => _schedule.SelectMany(x => x.Value.Values);
public IReadOnlyList<ContentSchedule> 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)

View File

@@ -176,20 +176,18 @@ namespace Umbraco.Core.Persistence.Factories
public static IEnumerable<ContentScheduleDto> BuildScheduleDto(IContent entity, ILanguageRepository languageRepository)
{
var schedule = new List<ContentScheduleDto>();
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;
}

View File

@@ -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)

View File

@@ -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);

View File

@@ -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);