U4-4575 - property converters use wrong source value

This commit is contained in:
Stephan
2014-04-02 16:00:08 +02:00
parent 53c0bd6938
commit 8371105c10
3 changed files with 81 additions and 10 deletions

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
namespace Umbraco.Web.Models
{
public static class PublishedProperty
{
/// <summary>
/// Maps a collection of Property to a collection of IPublishedProperty for a specified collection of PublishedPropertyType.
/// </summary>
/// <param name="propertyTypes">The published property types.</param>
/// <param name="properties">The properties.</param>
/// <param name="map">A mapping function.</param>
/// <returns>A collection of IPublishedProperty corresponding to the collection of PublishedPropertyType
/// and taking values from the collection of Property.</returns>
/// <remarks>Ensures that all conversions took place correctly.</remarks>
internal static IEnumerable<IPublishedProperty> MapProperties(
IEnumerable<PublishedPropertyType> propertyTypes, IEnumerable<Property> properties,
Func<PublishedPropertyType, Property, object, IPublishedProperty> map)
{
var peResolver = DataTypesResolver.Current;
var dtService = ApplicationContext.Current.Services.DataTypeService;
return MapProperties(propertyTypes, properties, peResolver, dtService, map);
}
/// <summary>
/// Maps a collection of Property to a collection of IPublishedProperty for a specified collection of PublishedPropertyType.
/// </summary>
/// <param name="propertyTypes">The published property types.</param>
/// <param name="properties">The properties.</param>
/// <param name="map">A mapping function.</param>
/// <param name="dataTypesResolver">A DataTypesResolver instance.</param>
/// <param name="dataTypeService">An IDataTypeService instance.</param>
/// <returns>A collection of IPublishedProperty corresponding to the collection of PublishedPropertyType
/// and taking values from the collection of Property.</returns>
/// <remarks>Ensures that all conversions took place correctly.</remarks>
internal static IEnumerable<IPublishedProperty> MapProperties(
IEnumerable<PublishedPropertyType> propertyTypes, IEnumerable<Property> properties,
DataTypesResolver dataTypesResolver, IDataTypeService dataTypeService,
Func<PublishedPropertyType, Property, object, IPublishedProperty> map)
{
return propertyTypes
.Select(x =>
{
var p = properties.SingleOrDefault(xx => xx.Alias == x.PropertyTypeAlias);
var v = p == null || p.Value == null ? null : p.Value;
if (v != null)
{
var dataType = dataTypesResolver.DataTypes.SingleOrDefault(qq => qq.Id == x.PropertyEditorGuid);
if (dataType != null)
{
var data = dataType.Data;
data.Value = v;
var n = data.ToXMl(new XmlDocument());
v = n.InnerXml;
}
}
// fixme - means that the IPropertyValueConverter will always get a string
// fixme and never an int or DateTime that's in the DB unless the value editor has
// fixme a way to say it's OK to use what's in the DB?
return map(x, p, v);
});
}
}
}

View File

@@ -18,7 +18,7 @@ namespace Umbraco.Web.PublishedCache
private readonly IMember _member;
private readonly MembershipUser _membershipUser;
private readonly List<IPublishedProperty> _properties;
private readonly IPublishedProperty[] _properties;
private readonly PublishedContentType _publishedMemberType;
public MemberPublishedContent(IMember member, MembershipUser membershipUser)
@@ -28,19 +28,14 @@ namespace Umbraco.Web.PublishedCache
_member = member;
_membershipUser = membershipUser;
_properties = new List<IPublishedProperty>();
_publishedMemberType = PublishedContentType.Get(PublishedItemType.Member, _member.ContentTypeAlias);
if (_publishedMemberType == null)
{
throw new InvalidOperationException("Could not get member type with alias " + _member.ContentTypeAlias);
}
foreach (var propType in _publishedMemberType.PropertyTypes)
{
var val = _member.Properties.Any(x => x.Alias == propType.PropertyTypeAlias) == false
? string.Empty
: _member.Properties[propType.PropertyTypeAlias].Value;
_properties.Add(new RawValueProperty(propType, val ?? string.Empty));
}
_properties = PublishedProperty.MapProperties(_publishedMemberType.PropertyTypes, _member.Properties,
(t, p, v) => new RawValueProperty(t, v ?? string.Empty))
.ToArray();
}
#region Membership provider member properties

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@@ -300,6 +300,7 @@
<Compile Include="Models\ChangingPasswordModel.cs" />
<Compile Include="Models\IRenderModel.cs" />
<Compile Include="Models\PostRedirectModel.cs" />
<Compile Include="Models\PublishedProperty.cs" />
<Compile Include="Mvc\RedirectToUmbracoUrlResult.cs" />
<Compile Include="PublishedCache\MemberPublishedContent.cs" />
<Compile Include="PublishedCache\RawValueProperty.cs" />