Refactoring legacy Content, Property and propertytype though still a WIP.

This commit is contained in:
Morten Christensen
2012-12-17 15:07:08 -01:00
parent 9420a858c8
commit 806c2a7ea4
4 changed files with 84 additions and 24 deletions

View File

@@ -91,18 +91,13 @@ namespace umbraco.cms.businesslogic
[Obsolete("Deprecated, Use Umbraco.Core.Services.ContentService.GetByIdVersion() or Umbraco.Core.Services.MediaService.GetByIdVersion()", false)]
public static Content GetContentFromVersion(Guid version)
{
int id =
ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar<int>(
"Select ContentId from cmsContentVersion where versionId = @VersionId", new {VersionId = version});
var content = ApplicationContext.Current.Services.ContentService.GetByIdVersion(id, version);
var content = ApplicationContext.Current.Services.ContentService.GetByVersion(version);
if (content != null)
{
return new Content(content);
}
//TODO Change to use GetByIdVersion once that method has been implemented in the MediaService
var media = ApplicationContext.Current.Services.MediaService.GetById(id);
var media = ApplicationContext.Current.Services.MediaService.GetByVersion(version);
return new Content(media);
}
@@ -285,7 +280,7 @@ namespace umbraco.cms.businesslogic
/// </summary>
/// <param name="alias">Propertyalias (defined in the documenttype)</param>
/// <returns>The property with the given alias</returns>
public Property getProperty(string alias)
public virtual Property getProperty(string alias)
{
ContentType ct = this.ContentType;
if (ct == null)
@@ -301,7 +296,7 @@ namespace umbraco.cms.businesslogic
/// </summary>
/// <param name="pt">PropertyType</param>
/// <returns>The property with the given propertytype</returns>
public Property getProperty(PropertyType pt)
public virtual Property getProperty(PropertyType pt)
{
EnsureProperties();
@@ -318,7 +313,7 @@ namespace umbraco.cms.businesslogic
/// <param name="pt">The PropertyType of the Property</param>
/// <param name="versionId">The version of the document on which the property should be add'ed</param>
/// <returns>The new Property</returns>
public Property addProperty(PropertyType pt, Guid versionId)
public virtual Property addProperty(PropertyType pt, Guid versionId)
{
ClearLoadedProperties();
@@ -486,6 +481,7 @@ namespace umbraco.cms.businesslogic
if (_contentType == null)
_contentType = ContentType.GetContentType(InitContentType);
_version = InitVersion;
_versionDate = InitVersionDate;
_contentTypeIcon = InitContentTypeIcon;
@@ -500,12 +496,9 @@ namespace umbraco.cms.businesslogic
SqlHelper.ExecuteNonQuery("insert into cmsContent (nodeId,ContentType) values (" + this.Id + "," + ct.Id + ")");
createNewVersion(DateTime.Now);
}
/// <summary>
/// Method for creating a new version of the data associated to the Content.
///
/// Method for creating a new version of the data associated to the Content.
/// </summary>
/// <returns>The new version Id</returns>
protected Guid createNewVersion(DateTime versionDate = default(DateTime))
@@ -657,6 +650,12 @@ namespace umbraco.cms.businesslogic
{
m_LoadedProperties = new Properties();
if (_contentBase != null)
{
m_LoadedProperties.AddRange(_contentBase.Properties.Select(x => new Property(x)));
return;
}
if (this.ContentType == null)
return;

View File

@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Runtime.CompilerServices;
using System.Xml;
using Umbraco.Core;
using Umbraco.Core.Persistence;
using umbraco.DataLayer;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.datatype;
using umbraco.cms.businesslogic.propertytype;
namespace umbraco.cms.businesslogic.property
{
@@ -16,7 +16,9 @@ namespace umbraco.cms.businesslogic.property
/// </summary>
public class Property
{
private propertytype.PropertyType _pt;
private Umbraco.Core.Models.PropertyType _propertyType;
private Umbraco.Core.Models.Property _property;
private PropertyType _pt;
private interfaces.IData _data;
private int _id;
@@ -42,12 +44,26 @@ namespace umbraco.cms.businesslogic.property
public Property(int Id)
{
_id = Id;
_pt = umbraco.cms.businesslogic.propertytype.PropertyType.GetPropertyType(
SqlHelper.ExecuteScalar<int>("select propertytypeid from cmsPropertyData where id = @id", SqlHelper.CreateParameter("@id", Id)));
_pt = PropertyType.GetPropertyType(
SqlHelper.ExecuteScalar<int>("select propertytypeid from cmsPropertyData where id = @id",
SqlHelper.CreateParameter("@id", Id)));
_data = _pt.DataTypeDefinition.DataType.Data;
_data.PropertyId = Id;
}
internal Property(Umbraco.Core.Models.Property property)
{
_id = property.Id;
_property = property;
_propertyType = property.PropertyType;
var dataTypeDefinition = DataTypeDefinition.GetDataTypeDefinition(property.PropertyType.DataTypeId);
_data = dataTypeDefinition.DataType.Data;
//Just to ensure that there is a PropertyType available
_pt = PropertyType.GetPropertyType(property.PropertyTypeId);
}
public Guid VersionId
{
get
@@ -65,7 +81,13 @@ namespace umbraco.cms.businesslogic.property
}
public propertytype.PropertyType PropertyType
{
get { return _pt; }
get
{
/*if (_propertyType != null)
return new PropertyType(_propertyType);*/
return _pt;
}
}
public object Value

View File

@@ -22,8 +22,6 @@ namespace umbraco.cms.businesslogic.propertytype
{
#region Declarations
private static string _connstring = GlobalSettings.DbDSN;
private static readonly object propertyTypeCacheSyncLock = new object();
private static readonly string UmbracoPropertyTypeCacheKey = "UmbracoPropertyTypeCache";
private readonly int _contenttypeid;
@@ -38,6 +36,8 @@ namespace umbraco.cms.businesslogic.propertytype
private int _propertyTypeGroup;
private string _validationRegExp = "";
private Umbraco.Core.Models.PropertyType _propertyType;
#endregion
protected static ISqlHelper SqlHelper
@@ -73,6 +73,24 @@ namespace umbraco.cms.businesslogic.propertytype
}
}
internal PropertyType(Umbraco.Core.Models.PropertyType propertyType)
{
_propertyType = propertyType;
//_contenttypeid
//_propertyTypeGroup
//_tabId
_mandatory = propertyType.Mandatory;
_sortOrder = propertyType.SortOrder;
_alias = propertyType.Alias;
_name = propertyType.Name;
_validationRegExp = propertyType.ValidationRegExp;
_DataTypeId = propertyType.DataTypeId;
_description = propertyType.Description;
}
#endregion
#region Properties
@@ -112,6 +130,7 @@ namespace umbraco.cms.businesslogic.propertytype
InvalidateCache();
}
}
public int PropertyTypeGroup
{
get { return _propertyTypeGroup; }

View File

@@ -873,6 +873,12 @@ and node.nodeObjectType='C66BA18E-EAF3-4CFF-8A22-41B16D66A972'");
if (!e.Cancel)
{
//NOTE This seems to currently override the data set in the content control
foreach (var property in GenericProperties)
{
//Content.SetValue(property.PropertyType.Alias, property.Value);
}
ApplicationContext.Current.Services.ContentService.Save(Content);
base.Save();
@@ -1219,13 +1225,27 @@ and node.nodeObjectType='C66BA18E-EAF3-4CFF-8A22-41B16D66A972'");
#endregion
#region Public Methods - Overides Content for legacy api refactor
public override Property getProperty(string alias)
{
var prop = Content.Properties.FirstOrDefault(x => x.Alias == alias);
return new Property(prop);
}
public override Property getProperty(propertytype.PropertyType pt)
{
var prop = Content.Properties.FirstOrDefault(x => x.Alias == pt.Alias);
return new Property(prop);
}
#endregion
#region Protected Methods
[Obsolete("Deprecated", false)]
protected override void setupNode()
{
var content = Version == Guid.Empty
? ApplicationContext.Current.Services.ContentService.GetById(Id)
: ApplicationContext.Current.Services.ContentService.GetByIdVersion(Id, Version);
: ApplicationContext.Current.Services.ContentService.GetByVersion(Version);
if(content == null)
throw new ArgumentException(string.Format("No Document exists with id '{0}'", Id));