2nd attempt: U4-2514 Checkboxlist prevalues in packages broken
This commit is contained in:
@@ -9,6 +9,7 @@ using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -286,7 +287,7 @@ namespace Umbraco.Core.Services
|
||||
var properties = from property in element.Elements()
|
||||
where property.Attribute("isDoc") == null
|
||||
select property;
|
||||
|
||||
|
||||
IContent content = parent == null
|
||||
? new Content(nodeName, parentId, contentType)
|
||||
{
|
||||
@@ -303,12 +304,33 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
string propertyTypeAlias = isLegacySchema ? property.Attribute("alias").Value : property.Name.LocalName;
|
||||
if (content.HasProperty(propertyTypeAlias))
|
||||
content.SetValue(propertyTypeAlias, property.Value);
|
||||
{
|
||||
var propertyValue = property.Value;
|
||||
|
||||
var propertyType = contentType.PropertyTypes.FirstOrDefault(pt => pt.Alias == propertyTypeAlias);
|
||||
if (propertyType != null && propertyType.DataTypeId == new Guid(Constants.PropertyEditors.CheckBoxList))
|
||||
{
|
||||
var database = ApplicationContext.Current.DatabaseContext.Database;
|
||||
var dtos = database.Fetch<DataTypePreValueDto>("WHERE datatypeNo" + "deId = @Id", new { Id = propertyType.DataTypeDefinitionId });
|
||||
|
||||
var propertyValueList = new List<string>();
|
||||
foreach (var preValue in propertyValue.Split(','))
|
||||
{
|
||||
propertyValueList.Add(dtos.Single(x => x.Value == preValue).Id.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
propertyValue = string.Join(",", propertyValueList.ToArray());
|
||||
}
|
||||
|
||||
content.SetValue(propertyTypeAlias, propertyValue);
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region ContentTypes
|
||||
|
||||
@@ -1,48 +1,49 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Logging;
|
||||
using umbraco.DataLayer;
|
||||
|
||||
namespace umbraco.editorControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for cms.businesslogic.datatype.DefaultDataKeyValue.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Summary description for cms.businesslogic.datatype.DefaultDataKeyValue.
|
||||
/// </summary>
|
||||
public class DefaultDataKeyValue : cms.businesslogic.datatype.DefaultData
|
||||
{
|
||||
public DefaultDataKeyValue(cms.businesslogic.datatype.BaseDataType DataType) : base(DataType)
|
||||
{}
|
||||
/// <summary>
|
||||
/// Ov
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public override System.Xml.XmlNode ToXMl(System.Xml.XmlDocument d)
|
||||
{
|
||||
// Get the value from
|
||||
var v = "";
|
||||
try
|
||||
{
|
||||
// Don't query if there's nothing to query for..
|
||||
if (string.IsNullOrWhiteSpace(Value.ToString()) == false)
|
||||
{
|
||||
var dr = SqlHelper.ExecuteReader("Select [value] from cmsDataTypeprevalues where id in (" + SqlHelper.EscapeString(Value.ToString()) + ")");
|
||||
{
|
||||
public DefaultDataKeyValue(cms.businesslogic.datatype.BaseDataType DataType)
|
||||
: base(DataType)
|
||||
{ }
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
if (v.Length == 0)
|
||||
v += dr.GetString("value");
|
||||
else
|
||||
v += "," + dr.GetString("value");
|
||||
}
|
||||
dr.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<DefaultDataKeyValue>("An exception occurred converting the property data to XML", ex);
|
||||
}
|
||||
return d.CreateCDataSection(v);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the values of from cmsDataTypePreValues table by id and puts them into a CDATA section
|
||||
/// </summary>
|
||||
/// <param name="xmlDocument"></param>
|
||||
/// <returns></returns>
|
||||
public override System.Xml.XmlNode ToXMl(System.Xml.XmlDocument xmlDocument)
|
||||
{
|
||||
var value = string.Empty;
|
||||
try
|
||||
{
|
||||
// Don't query if there's nothing to query for..
|
||||
if (string.IsNullOrWhiteSpace(Value.ToString()) == false)
|
||||
{
|
||||
var dr = SqlHelper.ExecuteReader(string.Format("Select [value] from cmsDataTypeprevalues where id in ({0})", SqlHelper.EscapeString(Value.ToString())));
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
value += value.Length == 0
|
||||
? dr.GetString("value")
|
||||
: string.Format(",{0}", dr.GetString("value"));
|
||||
}
|
||||
|
||||
dr.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<DefaultDataKeyValue>("An exception occurred converting the property data to XML", ex);
|
||||
}
|
||||
|
||||
return xmlDocument.CreateCDataSection(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user