Gets publish names tracking changes, adds unit tests

This commit is contained in:
Shannon
2018-10-18 21:12:55 +11:00
parent ba186144a0
commit 6cd9102fac
5 changed files with 164 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
@@ -88,6 +89,7 @@ namespace Umbraco.Core.Models
public readonly PropertyInfo PublishedSelector = ExpressionHelper.GetPropertyInfo<Content, bool>(x => x.Published);
public readonly PropertyInfo ReleaseDateSelector = ExpressionHelper.GetPropertyInfo<Content, DateTime?>(x => x.ReleaseDate);
public readonly PropertyInfo ExpireDateSelector = ExpressionHelper.GetPropertyInfo<Content, DateTime?>(x => x.ExpireDate);
public readonly PropertyInfo PublishNamesSelector = ExpressionHelper.GetPropertyInfo<Content, IReadOnlyCollection<CultureName>>(x => x.PublishNames);
}
/// <summary>
@@ -222,7 +224,7 @@ namespace Umbraco.Core.Models
public bool IsCulturePublished(string culture)
// just check _publishInfos
// a non-available culture could not become published anyways
=> _publishInfos != null && _publishInfos.Contains(culture);
=> _publishInfos != null && _publishInfos.Contains(culture);
/// <inheritdoc />
public bool WasCulturePublished(string culture)
@@ -268,9 +270,10 @@ namespace Umbraco.Core.Models
throw new ArgumentNullOrEmptyException(nameof(culture));
if (_publishInfos == null)
{
_publishInfos = new CultureNameCollection();
//TODO: Track changes?
_publishInfos.CollectionChanged += PublishNamesCollectionChanged;
}
_publishInfos.AddOrUpdate(culture, name, date);
}
@@ -314,6 +317,16 @@ namespace Umbraco.Core.Models
}
}
/// <summary>
/// Event handler for when the culture names collection is modified
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PublishNamesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(Ps.Value.PublishNamesSelector);
}
[IgnoreDataMember]
public int PublishedVersionId { get; internal set; }
@@ -430,7 +443,8 @@ namespace Umbraco.Core.Models
// take care of the published state
_publishedState = _published ? PublishedState.Published : PublishedState.Unpublished;
// take care of publish infos
// Make a copy of the _publishInfos, this is purely so that we can detect
// if this entity's previous culture publish state (regardless of the rememberDirty flag)
_publishInfosOrig = _publishInfos == null
? null
: new CultureNameCollection(_publishInfos);

View File

@@ -14,12 +14,27 @@ namespace Umbraco.Core.Models
private string _name;
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
public CultureName(string culture, string name, DateTime date)
/// <summary>
/// Used for cloning without change tracking
/// </summary>
/// <param name="culture"></param>
/// <param name="name"></param>
/// <param name="date"></param>
private CultureName(string culture, string name, DateTime date)
: this(culture)
{
_name = name;
_date = date;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="culture"></param>
public CultureName(string culture)
{
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("message", nameof(culture));
Culture = culture;
_name = name;
_date = date;
}
public string Culture { get; private set; }

View File

@@ -56,7 +56,11 @@ namespace Umbraco.Core.Models
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, found, found));
}
else
Add(new CultureName(culture, name, date));
Add(new CultureName(culture)
{
Name = name,
Date = date
});
}
/// <summary>