Fixes up issues when tracking dirty changes on numerical or empty string values because json.net converts numerical to long and we were setting those values on the Property.Value which means that comparing long -> int will always return false and thus the property is flagged as dirty. Same goes with string and null when dealing with an object. This is all fixed up now and have added another method to see if we shold actually persist any changes for content when saving. This all relates to fixing: U4-5510 Previewing a content item saves that item

This commit is contained in:
Shannon
2014-10-21 13:12:31 +10:00
parent 95c0f80df4
commit 967030a9c4
7 changed files with 107 additions and 17 deletions

View File

@@ -14,6 +14,12 @@ namespace Umbraco.Core.Models.EntityBase
[DataContract(IsReference = true)]
public abstract class TracksChangesEntityBase : IRememberBeingDirty
{
//TODO: This needs to go on to ICanBeDirty http://issues.umbraco.org/issue/U4-5662
public virtual IEnumerable<string> GetDirtyProperties()
{
return _propertyChangedInfo.Where(x => x.Value).Select(x => x.Key);
}
/// <summary>
/// Tracks the properties that have changed
/// </summary>
@@ -139,11 +145,12 @@ namespace Umbraco.Core.Models.EntityBase
/// save a document type, nearly all properties are flagged as dirty just because we've 'reset' them, but they are all set
/// to the same value, so it's really not dirty.
/// </remarks>
internal bool SetPropertyValueAndDetectChanges<T>(Func<T, T> setValue, T value, PropertyInfo propertySelector)
internal virtual bool SetPropertyValueAndDetectChanges<T>(Func<T, T> setValue, T value, PropertyInfo propertySelector)
{
var initVal = value;
var newVal = setValue(value);
if (!Equals(initVal, newVal))
if (Equals(initVal, newVal) == false)
{
OnPropertyChanged(propertySelector);
return true;