merge with 6.1.0
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.CodeAnnotations;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
@@ -8,6 +9,8 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
public static class UmbracoObjectTypesExtensions
|
||||
{
|
||||
private static readonly Dictionary<UmbracoObjectTypes, Guid> UmbracoObjectTypeCache = new Dictionary<UmbracoObjectTypes,Guid>();
|
||||
|
||||
/// <summary>
|
||||
/// Get an UmbracoObjectTypes value from it's name
|
||||
/// </summary>
|
||||
@@ -45,10 +48,15 @@ namespace Umbraco.Core.Models
|
||||
/// <returns>a GUID value of the UmbracoObjectTypes</returns>
|
||||
public static Guid GetGuid(this UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
if (UmbracoObjectTypeCache.ContainsKey(umbracoObjectType))
|
||||
return UmbracoObjectTypeCache[umbracoObjectType];
|
||||
|
||||
var attribute = umbracoObjectType.GetType().FirstAttribute<UmbracoObjectTypeAttribute>();
|
||||
if (attribute == null)
|
||||
return Guid.Empty;
|
||||
|
||||
UmbracoObjectTypeCache.Add(umbracoObjectType, attribute.ObjectId);
|
||||
|
||||
return attribute.ObjectId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Globalization;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal class UmbracoEntityFactory : IEntityFactory<UmbracoEntity, NodeDto>
|
||||
internal class UmbracoEntityFactory : IEntityFactory<UmbracoEntity, EntityRepository.UmbracoEntityDto>
|
||||
{
|
||||
public UmbracoEntity BuildEntity(NodeDto dto)
|
||||
public UmbracoEntity BuildEntity(EntityRepository.UmbracoEntityDto dto)
|
||||
{
|
||||
var entity = new UmbracoEntity(dto.Trashed)
|
||||
{
|
||||
@@ -20,15 +20,15 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
ParentId = dto.ParentId,
|
||||
Path = dto.Path,
|
||||
SortOrder = dto.SortOrder,
|
||||
HasChildren = false,
|
||||
IsPublished = false
|
||||
HasChildren = dto.Children > 0,
|
||||
IsPublished = dto.HasPublishedVersion.HasValue && dto.HasPublishedVersion.Value > 0
|
||||
};
|
||||
return entity;
|
||||
}
|
||||
|
||||
public NodeDto BuildDto(UmbracoEntity entity)
|
||||
public EntityRepository.UmbracoEntityDto BuildDto(UmbracoEntity entity)
|
||||
{
|
||||
var node = new NodeDto
|
||||
var node = new EntityRepository.UmbracoEntityDto
|
||||
{
|
||||
CreateDate = entity.CreateDate,
|
||||
Level = short.Parse(entity.Level.ToString(CultureInfo.InvariantCulture)),
|
||||
|
||||
57
src/Umbraco.Core/Persistence/Mappers/UmbracoEntityMapper.cs
Normal file
57
src/Umbraco.Core/Persistence/Mappers/UmbracoEntityMapper.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Mappers
|
||||
{
|
||||
[MapperFor(typeof (IUmbracoEntity))]
|
||||
public sealed class UmbracoEntityMapper : BaseMapper
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache =
|
||||
new ConcurrentDictionary<string, DtoMapModel>();
|
||||
|
||||
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
|
||||
// otherwise that would fail because there is no public constructor.
|
||||
public UmbracoEntityMapper()
|
||||
{
|
||||
BuildMap();
|
||||
}
|
||||
|
||||
#region Overrides of BaseMapper
|
||||
|
||||
internal override void BuildMap()
|
||||
{
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.Id, dto => dto.NodeId);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.CreateDate, dto => dto.CreateDate);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.Level, dto => dto.Level);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.ParentId, dto => dto.ParentId);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.Path, dto => dto.Path);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.SortOrder, dto => dto.SortOrder);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.Name, dto => dto.Text);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.Trashed, dto => dto.Trashed);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.Key, dto => dto.UniqueId);
|
||||
CacheMap<IUmbracoEntity, NodeDto>(src => src.CreatorId, dto => dto.UserId);
|
||||
}
|
||||
|
||||
internal override string Map(string propertyName)
|
||||
{
|
||||
if (!PropertyInfoCache.ContainsKey(propertyName))
|
||||
return string.Empty;
|
||||
|
||||
var dtoTypeProperty = PropertyInfoCache[propertyName];
|
||||
|
||||
return base.GetColumnName(dtoTypeProperty.Type, dtoTypeProperty.PropertyInfo);
|
||||
}
|
||||
|
||||
internal override void CacheMap<TSource, TDestination>(Expression<Func<TSource, object>> sourceMember,
|
||||
Expression<Func<TDestination, object>> destinationMember)
|
||||
{
|
||||
var property = base.ResolveMapping(sourceMember, destinationMember);
|
||||
PropertyInfoCache.AddOrUpdate(property.SourcePropertyName, property, (x, y) => property);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -468,6 +468,9 @@ namespace Umbraco.Core.Persistence.Querying
|
||||
if(fieldType == typeof(DateTime))
|
||||
return "'" + EscapeParam(((DateTime)value).ToString(CultureInfo.InvariantCulture)) + "'";
|
||||
|
||||
if (fieldType == typeof(bool))
|
||||
return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture);
|
||||
|
||||
return ShouldQuoteValue(fieldType)
|
||||
? "'" + EscapeParam(value) + "'"
|
||||
: value.ToString();
|
||||
|
||||
@@ -19,18 +19,10 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
internal class EntityRepository : DisposableObject, IEntityRepository
|
||||
{
|
||||
private readonly IDatabaseUnitOfWork _work;
|
||||
private readonly IDictionary<Guid, Func<IUmbracoEntity, IUmbracoEntity>> _propertyHandler;
|
||||
|
||||
public EntityRepository(IDatabaseUnitOfWork work)
|
||||
{
|
||||
_work = work;
|
||||
_propertyHandler = new Dictionary<Guid, Func<IUmbracoEntity, IUmbracoEntity>>
|
||||
{
|
||||
{
|
||||
new Guid(Constants.ObjectTypes.Document),
|
||||
UpdateIsPublished
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,35 +45,28 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
public virtual IUmbracoEntity Get(int id)
|
||||
{
|
||||
var sql = GetBaseWhere(id);
|
||||
var nodeDto = _work.Database.FirstOrDefault<NodeDto>(sql);
|
||||
var sql = GetBaseWhere(GetBase, false, id);
|
||||
var nodeDto = _work.Database.FirstOrDefault<UmbracoEntityDto>(sql);
|
||||
if (nodeDto == null)
|
||||
return null;
|
||||
|
||||
var factory = new UmbracoEntityFactory();
|
||||
var entity = factory.BuildEntity(nodeDto);
|
||||
|
||||
//TODO Update HasChildren and IsPublished
|
||||
if (_propertyHandler.ContainsKey(entity.NodeObjectTypeId))
|
||||
{
|
||||
return _propertyHandler[entity.NodeObjectTypeId](entity);
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public virtual IUmbracoEntity Get(int id, Guid objectTypeId)
|
||||
{
|
||||
var sql = GetBaseWhere(objectTypeId, id);
|
||||
var nodeDto = _work.Database.FirstOrDefault<NodeDto>(sql);
|
||||
bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document);
|
||||
var sql = GetBaseWhere(GetBase, isContent, objectTypeId, id).Append(GetGroupBy());
|
||||
var nodeDto = _work.Database.FirstOrDefault<UmbracoEntityDto>(sql);
|
||||
if (nodeDto == null)
|
||||
return null;
|
||||
|
||||
var factory = new UmbracoEntityFactory();
|
||||
var entity = factory.BuildEntity(nodeDto);
|
||||
|
||||
//TODO Update HasChildren and IsPublished
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -96,15 +81,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
else
|
||||
{
|
||||
var sql = GetBaseWhere(objectTypeId);
|
||||
var dtos = _work.Database.Fetch<NodeDto>(sql);
|
||||
bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document);
|
||||
var sql = GetBaseWhere(GetBase, isContent, objectTypeId).Append(GetGroupBy());
|
||||
var dtos = _work.Database.Fetch<UmbracoEntityDto>(sql);
|
||||
|
||||
var factory = new UmbracoEntityFactory();
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
var entity = factory.BuildEntity(dto);
|
||||
//TODO Update HasChildren and IsPublished properties
|
||||
yield return entity;
|
||||
}
|
||||
}
|
||||
@@ -112,80 +97,102 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
public virtual IEnumerable<IUmbracoEntity> GetByQuery(IQuery<IUmbracoEntity> query)
|
||||
{
|
||||
var sqlClause = GetBaseQuery();
|
||||
var sqlClause = GetBase(false);
|
||||
var translator = new SqlTranslator<IUmbracoEntity>(sqlClause, query);
|
||||
var sql = translator.Translate();
|
||||
var sql = translator.Translate().Append(GetGroupBy());
|
||||
|
||||
var dtos = _work.Database.Fetch<NodeDto>(sql);
|
||||
var dtos = _work.Database.Fetch<UmbracoEntityDto>(sql);
|
||||
|
||||
var factory = new UmbracoEntityFactory();
|
||||
var list = dtos.Select(factory.BuildEntity).Cast<IUmbracoEntity>().ToList();
|
||||
|
||||
//TODO Update HasChildren and IsPublished properties
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<IUmbracoEntity> GetByQuery(IQuery<IUmbracoEntity> query, Guid objectTypeId)
|
||||
{
|
||||
var sqlClause = GetBaseWhere(objectTypeId);
|
||||
bool isContent = objectTypeId == new Guid(Constants.ObjectTypes.Document);
|
||||
var sqlClause = GetBaseWhere(GetBase, isContent, objectTypeId);
|
||||
var translator = new SqlTranslator<IUmbracoEntity>(sqlClause, query);
|
||||
var sql = translator.Translate();
|
||||
var sql = translator.Translate().Append(GetGroupBy());
|
||||
|
||||
var dtos = _work.Database.Fetch<NodeDto>(sql);
|
||||
var dtos = _work.Database.Fetch<UmbracoEntityDto>(sql);
|
||||
|
||||
var factory = new UmbracoEntityFactory();
|
||||
var list = dtos.Select(factory.BuildEntity).Cast<IUmbracoEntity>().ToList();
|
||||
|
||||
//TODO Update HasChildren and IsPublished properties
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void UpdateHasChildren(IUmbracoEntity entity)
|
||||
{}
|
||||
|
||||
private IUmbracoEntity UpdateIsPublished(IUmbracoEntity entity)
|
||||
{
|
||||
var umbracoEntity = entity as UmbracoEntity;
|
||||
if (umbracoEntity != null)
|
||||
{
|
||||
umbracoEntity.IsPublished = true;
|
||||
return umbracoEntity;
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
#region Sql Statements
|
||||
|
||||
protected virtual Sql GetBaseQuery()
|
||||
protected virtual Sql GetBase(bool isContent)
|
||||
{
|
||||
var columns = new List<object>
|
||||
{
|
||||
"main.id",
|
||||
"main.trashed",
|
||||
"main.parentID",
|
||||
"main.nodeUser",
|
||||
"main.level",
|
||||
"main.path",
|
||||
"main.sortOrder",
|
||||
"main.uniqueID",
|
||||
"main.text",
|
||||
"main.nodeObjectType",
|
||||
"main.createDate",
|
||||
"COUNT(parent.parentID) as children",
|
||||
isContent
|
||||
? "SUM(CONVERT(int, document.published)) as published"
|
||||
: "SUM(0) as published"
|
||||
};
|
||||
|
||||
var sql = new Sql()
|
||||
.Select(columns.ToArray())
|
||||
.From("FROM umbracoNode main")
|
||||
.LeftJoin("umbracoNode parent").On("parent.parentID = main.id");
|
||||
|
||||
|
||||
//NOTE Should this account for newest = 1 ? Scenarios: unsaved, saved not published, published
|
||||
|
||||
if (isContent)
|
||||
sql.LeftJoin("cmsDocument document").On("document.nodeId = main.id");
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected virtual Sql GetBaseWhere(Func<bool, Sql> baseQuery, bool isContent, Guid id)
|
||||
{
|
||||
var sql = baseQuery(isContent)
|
||||
.Where("main.nodeObjectType = @NodeObjectType", new {NodeObjectType = id});
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected virtual Sql GetBaseWhere(Func<bool, Sql> baseQuery, bool isContent, int id)
|
||||
{
|
||||
var sql = baseQuery(isContent)
|
||||
.Where("main.id = @Id", new {Id = id})
|
||||
.Append(GetGroupBy());
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected virtual Sql GetBaseWhere(Func<bool, Sql> baseQuery, bool isContent, Guid objectId, int id)
|
||||
{
|
||||
var sql = baseQuery(isContent)
|
||||
.Where("main.id = @Id AND main.nodeObjectType = @NodeObjectType",
|
||||
new {Id = id, NodeObjectType = objectId});
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected virtual Sql GetGroupBy()
|
||||
{
|
||||
var sql = new Sql()
|
||||
.From<NodeDto>();
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected virtual Sql GetBaseWhere(Guid id)
|
||||
{
|
||||
var sql = GetBaseQuery()
|
||||
.Where<NodeDto>(x => x.NodeObjectType == id);
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected virtual Sql GetBaseWhere(int id)
|
||||
{
|
||||
var sql = GetBaseQuery()
|
||||
.Where<NodeDto>(x => x.NodeId == id);
|
||||
return sql;
|
||||
}
|
||||
|
||||
protected virtual Sql GetBaseWhere(Guid objectId, int id)
|
||||
{
|
||||
var sql = GetBaseWhere(objectId)
|
||||
.Where<NodeDto>(x => x.NodeId == id);
|
||||
.GroupBy("main.id", "main.trashed", "main.parentID", "main.nodeUser", "main.level",
|
||||
"main.path", "main.sortOrder", "main.uniqueID", "main.text",
|
||||
"main.nodeObjectType", "main.createDate")
|
||||
.OrderBy("main.sortOrder");
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -201,5 +208,19 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
UnitOfWork.DisposeIfDisposable();
|
||||
}
|
||||
|
||||
#region umbracoNode POCO - Extends NodeDto
|
||||
[TableName("umbracoNode")]
|
||||
[PrimaryKey("id")]
|
||||
[ExplicitColumns]
|
||||
internal class UmbracoEntityDto : NodeDto
|
||||
{
|
||||
[Column("children")]
|
||||
public int Children { get; set; }
|
||||
|
||||
[Column("published")]
|
||||
public int? HasPublishedVersion { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,6 @@ using System.Security.Permissions;
|
||||
[assembly: InternalsVisibleTo("Umbraco.Web")]
|
||||
[assembly: InternalsVisibleTo("Umbraco.Web.UI")]
|
||||
[assembly: InternalsVisibleTo("UmbracoExamine")]
|
||||
[assembly: InternalsVisibleTo("Umbraco.Courier.Persistence")]
|
||||
[assembly: InternalsVisibleTo("Umbraco.Courier.Persistence")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Concorde.Sync")]
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.CodeAnnotations;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -13,18 +14,15 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
private readonly IDatabaseUnitOfWorkProvider _uowProvider;
|
||||
private readonly RepositoryFactory _repositoryFactory;
|
||||
|
||||
public EntityService()
|
||||
: this(new RepositoryFactory())
|
||||
{ }
|
||||
|
||||
public EntityService(RepositoryFactory repositoryFactory)
|
||||
: this(new PetaPocoUnitOfWorkProvider(), repositoryFactory)
|
||||
{ }
|
||||
|
||||
public EntityService(IDatabaseUnitOfWorkProvider provider)
|
||||
: this(provider, new RepositoryFactory())
|
||||
{ }
|
||||
private readonly Dictionary<string, UmbracoObjectTypes> _supportedObjectTypes = new Dictionary<string, UmbracoObjectTypes>
|
||||
{
|
||||
{typeof(IDataTypeDefinition).FullName, UmbracoObjectTypes.DataType},
|
||||
{typeof(IContent).FullName, UmbracoObjectTypes.Document},
|
||||
{typeof(IContentType).FullName, UmbracoObjectTypes.DocumentType},
|
||||
{typeof(IMedia).FullName, UmbracoObjectTypes.Media},
|
||||
{typeof(IMediaType).FullName, UmbracoObjectTypes.MediaType},
|
||||
{typeof(ITemplate).FullName, UmbracoObjectTypes.Template}
|
||||
};
|
||||
|
||||
public EntityService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory)
|
||||
{
|
||||
@@ -51,6 +49,34 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
var objectType = GetObjectType(id);
|
||||
|
||||
//TODO Implementing loading from the various services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an UmbracoEntity by its Id and UmbracoObjectType, and optionally loads the complete object graph.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// By default this will load the base type <see cref="IUmbracoEntity"/> with a minimum set of properties.
|
||||
/// </returns>
|
||||
/// <param name="id">Id of the object to retrieve</param>
|
||||
/// <param name="umbracoObjectType">UmbracoObjectType of the entity to retrieve</param>
|
||||
/// <param name="loadBaseType">Optional bool to load the complete object graph when set to <c>False</c>.</param>
|
||||
/// <returns>An <see cref="IUmbracoEntity"/></returns>
|
||||
public virtual IUmbracoEntity Get(int id, UmbracoObjectTypes umbracoObjectType, bool loadBaseType = true)
|
||||
{
|
||||
if (loadBaseType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.Get(id, objectTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO Implementing loading from the various services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -75,15 +101,23 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
Mandate.That<NotSupportedException>(_supportedObjectTypes.ContainsKey(typeof (T).FullName), () =>
|
||||
{
|
||||
throw
|
||||
new NotSupportedException
|
||||
("The passed in type is not supported");
|
||||
});
|
||||
var objectType = _supportedObjectTypes[typeof(T).FullName];
|
||||
|
||||
//TODO Implementing loading from the various services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the parent of entity by its id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="id">Id of the entity to retrieve the Parent for</param>
|
||||
/// <returns>An <see cref="IUmbracoEntity"/></returns>
|
||||
public virtual IUmbracoEntity GetParent(int id)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
@@ -97,10 +131,29 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the parent of entity by its id and UmbracoObjectType
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="id">Id of the entity to retrieve the Parent for</param>
|
||||
/// <param name="umbracoObjectType">UmbracoObjectType of the parent to retrieve</param>
|
||||
/// <returns>An <see cref="IUmbracoEntity"/></returns>
|
||||
public virtual IUmbracoEntity GetParent(int id, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
var entity = repository.Get(id);
|
||||
if (entity.ParentId == -1 || entity.ParentId == -20 || entity.ParentId == -21)
|
||||
return null;
|
||||
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
return repository.Get(entity.ParentId, objectTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of children by the parents Id
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the parent to retrieve children for</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetChildren(int id)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
@@ -113,10 +166,28 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets a collection of children by the parents Id and UmbracoObjectType
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="id">Id of the parent to retrieve children for</param>
|
||||
/// <param name="umbracoObjectType">UmbracoObjectType of the children to retrieve</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetChildren(int id, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
var query = Query<IUmbracoEntity>.Builder.Where(x => x.ParentId == id);
|
||||
var contents = repository.GetByQuery(query, objectTypeId);
|
||||
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of descendents by the parents Id
|
||||
/// </summary>
|
||||
/// <param name="id">Id of entity to retrieve descendents for</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetDescendents(int id)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
@@ -130,13 +201,32 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets a collection of descendents by the parents Id
|
||||
/// </summary>
|
||||
/// <param name="objectType"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetRootEntities(UmbracoObjectTypes objectType)
|
||||
/// <param name="id">Id of entity to retrieve descendents for</param>
|
||||
/// <param name="umbracoObjectType">UmbracoObjectType of the descendents to retrieve</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetDescendents(int id, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
var objectTypeId = objectType.GetGuid();
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
var entity = repository.Get(id);
|
||||
var query = Query<IUmbracoEntity>.Builder.Where(x => x.Path.StartsWith(entity.Path) && x.Id != id);
|
||||
var entities = repository.GetByQuery(query, objectTypeId);
|
||||
|
||||
return entities;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of the entities at the root, which corresponds to the entities with a Parent Id of -1.
|
||||
/// </summary>
|
||||
/// <param name="umbracoObjectType">UmbracoObjectType of the root entities to retrieve</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetRootEntities(UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
var query = Query<IUmbracoEntity>.Builder.Where(x => x.ParentId == -1);
|
||||
@@ -147,25 +237,30 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets a collection of all <see cref="IUmbracoEntity"/> of a given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
/// <typeparam name="T">Type of the entities to retrieve</typeparam>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetAll<T>() where T : IUmbracoEntity
|
||||
{
|
||||
//TODO Implement this so the type passed in is verified against types on UmbracoObjectTypes
|
||||
//and then used to get all through the method below.
|
||||
throw new NotImplementedException();
|
||||
Mandate.That<NotSupportedException>(_supportedObjectTypes.ContainsKey(typeof(T).FullName), () =>
|
||||
{
|
||||
throw new NotSupportedException
|
||||
("The passed in type is not supported");
|
||||
});
|
||||
var objectType = _supportedObjectTypes[typeof (T).FullName];
|
||||
|
||||
return GetAll(objectType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets a collection of all <see cref="IUmbracoEntity"/> of a given type.
|
||||
/// </summary>
|
||||
/// <param name="objectType"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetAll(UmbracoObjectTypes objectType)
|
||||
/// <param name="umbracoObjectType">UmbracoObjectType of the entities to return</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetAll(UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
var objectTypeId = objectType.GetGuid();
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetAll(objectTypeId);
|
||||
@@ -173,10 +268,10 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets a collection of <see cref="IUmbracoEntity"/>
|
||||
/// </summary>
|
||||
/// <param name="objectTypeId"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="objectTypeId">Guid id of the UmbracoObjectType</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetAll(Guid objectTypeId)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateEntityRepository(_uowProvider.GetUnitOfWork()))
|
||||
@@ -186,48 +281,61 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the UmbracoObjectType from the integer id of an IUmbracoEntity.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="id">Id of the entity</param>
|
||||
/// <returns><see cref="UmbracoObjectTypes"/></returns>
|
||||
public virtual UmbracoObjectTypes GetObjectType(int id)
|
||||
{
|
||||
//TODO Implement so the entity is fetched from the db and then the Guid is used to resolve the UmbracoObjectType
|
||||
throw new NotImplementedException();
|
||||
using (var uow = _uowProvider.GetUnitOfWork())
|
||||
{
|
||||
var sql = new Sql().Select("nodeObjectType").From<NodeDto>().Where<NodeDto>(x => x.NodeId == id);
|
||||
var nodeObjectTypeId = uow.Database.ExecuteScalar<string>(sql);
|
||||
var objectTypeId = new Guid(nodeObjectTypeId);
|
||||
return UmbracoObjectTypesExtensions.GetUmbracoObjectType(objectTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the UmbracoObjectType from an IUmbracoEntity.
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="entity"><see cref="IUmbracoEntity"/></param>
|
||||
/// <returns><see cref="UmbracoObjectTypes"/></returns>
|
||||
public virtual UmbracoObjectTypes GetObjectType(IUmbracoEntity entity)
|
||||
{
|
||||
//TODO Implement this so the entity is cast to UmbracoEntity - if valid get the guid id and then resolve the UmbracoObjectType
|
||||
//otherwise fetch the IUmbracoEntity from the db and do it similar to above.
|
||||
throw new NotImplementedException();
|
||||
var entityImpl = entity as UmbracoEntity;
|
||||
if (entityImpl == null)
|
||||
return GetObjectType(entity.Id);
|
||||
|
||||
return UmbracoObjectTypesExtensions.GetUmbracoObjectType(entityImpl.NodeObjectTypeId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the Type of an entity by its Id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Type GetModelType(int id)
|
||||
/// <param name="id">Id of the entity</param>
|
||||
/// <returns>Type of the entity</returns>
|
||||
public virtual Type GetEntityType(int id)
|
||||
{
|
||||
//TODO Implement so the IUmbracoEntity is fetched from the db and then used to resolve the real type, ie. IContent, IMedia etc.
|
||||
throw new NotImplementedException();
|
||||
var objectType = GetObjectType(id);
|
||||
return GetEntityType(objectType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the Type of an entity by its <see cref="UmbracoObjectTypes"/>
|
||||
/// </summary>
|
||||
/// <param name="objectType"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Type GetModelType(UmbracoObjectTypes objectType)
|
||||
/// <param name="umbracoObjectType"><see cref="UmbracoObjectTypes"/></param>
|
||||
/// <returns>Type of the entity</returns>
|
||||
public virtual Type GetEntityType(UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
//TODO Implement so the real type is returned fro the UmbracoObjectType's attribute.
|
||||
throw new NotImplementedException();
|
||||
var attribute = umbracoObjectType.GetType().FirstAttribute<UmbracoObjectTypeAttribute>();
|
||||
if (attribute == null)
|
||||
throw new NullReferenceException("The passed in UmbracoObjectType does not contain an UmbracoObjectTypeAttribute, which is used to retrieve the Type.");
|
||||
|
||||
if(attribute.ModelType == null)
|
||||
throw new NullReferenceException("The passed in UmbracoObjectType does not contain a Type definition");
|
||||
|
||||
return attribute.ModelType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +291,7 @@ namespace Umbraco.Core.Services
|
||||
contentType.AllowedAsRoot = infoElement.Element("AllowAtRoot").Value.ToLowerInvariant().Equals("true");
|
||||
|
||||
UpdateContentTypesAllowedTemplates(contentType, infoElement.Element("AllowedTemplates"), defaultTemplateElement);
|
||||
UpdateContentTypesTabs(contentType, documentType.Element("Tab"));
|
||||
UpdateContentTypesTabs(contentType, documentType.Element("Tabs"));
|
||||
UpdateContentTypesProperties(contentType, documentType.Element("GenericProperties"));
|
||||
|
||||
return contentType;
|
||||
@@ -375,14 +375,12 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
dataTypeDefinition = dataTypeDefinitions.First();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(
|
||||
String.Format(
|
||||
"Packager: Error handling creation of PropertyType '{0}'. Could not find DataTypeDefintion with unique id '{1}' nor one referencing the DataType with control id '{2}'.",
|
||||
property.Element("Name").Value, dataTypeDefinitionId, dataTypeId));
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility, if no datatype with that ID can be found, we're letting this fail silently.
|
||||
// This means that the property will not be created.
|
||||
if(dataTypeDefinition == null)
|
||||
continue;
|
||||
|
||||
var propertyType = new PropertyType(dataTypeDefinition)
|
||||
{
|
||||
|
||||
@@ -311,18 +311,11 @@ namespace Umbraco.Core.Sync
|
||||
{
|
||||
if (servers == null) throw new ArgumentNullException("servers");
|
||||
if (refresher == null) throw new ArgumentNullException("refresher");
|
||||
Type arrayType = null;
|
||||
if (ids != null)
|
||||
|
||||
Type arrayType;
|
||||
if (!ValidateIdArray(ids, out arrayType))
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
if (!(id is int) && (!(id is Guid)))
|
||||
throw new ArgumentException("The id must be either an int or a Guid");
|
||||
if (arrayType == null)
|
||||
arrayType = id.GetType();
|
||||
if (arrayType != id.GetType())
|
||||
throw new ArgumentException("The array must contain the same type of " + arrayType);
|
||||
}
|
||||
throw new ArgumentException("The id must be either an int or a Guid");
|
||||
}
|
||||
|
||||
//Now, check if we are using Distrubuted calls. If there are no servers in the list then we
|
||||
@@ -336,6 +329,35 @@ namespace Umbraco.Core.Sync
|
||||
|
||||
EnsureLazyUsernamePasswordDelegateResolved();
|
||||
|
||||
PerformDistributedCall(servers, refresher, dispatchType, ids, arrayType, jsonPayload);
|
||||
}
|
||||
|
||||
private bool ValidateIdArray(IEnumerable<object> ids, out Type arrayType)
|
||||
{
|
||||
arrayType = null;
|
||||
if (ids != null)
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
if (!(id is int) && (!(id is Guid)))
|
||||
return false; //
|
||||
if (arrayType == null)
|
||||
arrayType = id.GetType();
|
||||
if (arrayType != id.GetType())
|
||||
throw new ArgumentException("The array must contain the same type of " + arrayType);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void PerformDistributedCall(
|
||||
IEnumerable<IServerAddress> servers,
|
||||
ICacheRefresher refresher,
|
||||
MessageType dispatchType,
|
||||
IEnumerable<object> ids = null,
|
||||
Type idArrayType = null,
|
||||
string jsonPayload = null)
|
||||
{
|
||||
//We are using distributed calls, so lets make them...
|
||||
try
|
||||
{
|
||||
@@ -351,6 +373,7 @@ namespace Umbraco.Core.Sync
|
||||
LogStartDispatch();
|
||||
|
||||
// Go through each configured node submitting a request asynchronously
|
||||
//NOTE: 'asynchronously' in this case does not mean that it will continue while we give the page back to the user!
|
||||
foreach (var n in servers)
|
||||
{
|
||||
//set the server address
|
||||
@@ -363,14 +386,19 @@ namespace Umbraco.Core.Sync
|
||||
asyncResultsList.Add(
|
||||
cacheRefresher.BeginRefreshByJson(
|
||||
refresher.UniqueIdentifier, jsonPayload, _login, _password, null, null));
|
||||
break;
|
||||
break;
|
||||
case MessageType.RefreshAll:
|
||||
asyncResultsList.Add(
|
||||
cacheRefresher.BeginRefreshAll(
|
||||
refresher.UniqueIdentifier, _login, _password, null, null));
|
||||
break;
|
||||
case MessageType.RefreshById:
|
||||
if (arrayType == typeof(int))
|
||||
if (idArrayType == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot refresh by id if the idArrayType is null");
|
||||
}
|
||||
|
||||
if (idArrayType == typeof(int))
|
||||
{
|
||||
var serializer = new JavaScriptSerializer();
|
||||
var jsonIds = serializer.Serialize(ids.Cast<int>().ToArray());
|
||||
@@ -384,9 +412,9 @@ namespace Umbraco.Core.Sync
|
||||
//so we'll just iterate
|
||||
asyncResultsList.AddRange(
|
||||
ids.Select(i => cacheRefresher.BeginRefreshByGuid(
|
||||
refresher.UniqueIdentifier, (Guid) i, _login, _password, null, null)));
|
||||
refresher.UniqueIdentifier, (Guid)i, _login, _password, null, null)));
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case MessageType.RemoveById:
|
||||
//we don't currently support bulk removing so we'll iterate
|
||||
@@ -420,7 +448,12 @@ namespace Umbraco.Core.Sync
|
||||
cacheRefresher.EndRefreshAll(t);
|
||||
break;
|
||||
case MessageType.RefreshById:
|
||||
if (arrayType == typeof(int))
|
||||
if (idArrayType == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot refresh by id if the idArrayType is null");
|
||||
}
|
||||
|
||||
if (idArrayType == typeof(int))
|
||||
{
|
||||
cacheRefresher.EndRefreshById(t);
|
||||
}
|
||||
|
||||
@@ -309,6 +309,7 @@
|
||||
<Compile Include="Persistence\Mappers\RelationMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\RelationTypeMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\ServerRegistrationMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\UmbracoEntityMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\UserMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\UserTypeMapper.cs" />
|
||||
<Compile Include="Persistence\Migrations\IMigration.cs" />
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Umbraco.Tests.Persistence.Querying
|
||||
.InnerJoin("[umbracoNode]")
|
||||
.On("[cmsContentType].[nodeId] = [umbracoNode].[id]")
|
||||
.Where("[umbracoNode].[nodeObjectType] = 'a2cb7800-f571-4787-9638-bc48539a0efb'")
|
||||
.Where("[cmsDocumentType].[IsDefault] = 'True'");
|
||||
.Where("[cmsDocumentType].[IsDefault] = 1");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
@@ -53,7 +53,7 @@ namespace Umbraco.Tests.Persistence.Querying
|
||||
.InnerJoin("[umbracoNode]")
|
||||
.On("[cmsContentType].[nodeId] = [umbracoNode].[id]")
|
||||
.Where("[umbracoNode].[nodeObjectType] = 'a2cb7800-f571-4787-9638-bc48539a0efb'")
|
||||
.Where("[cmsDocumentType].[IsDefault] = 'True'")
|
||||
.Where("[cmsDocumentType].[IsDefault] = 1")
|
||||
.Where("[umbracoNode].[id] = 1050");
|
||||
|
||||
var sql = new Sql();
|
||||
|
||||
@@ -32,4 +32,4 @@ using System.Security;
|
||||
[assembly: InternalsVisibleTo("Umbraco.Web.UI")]
|
||||
[assembly: InternalsVisibleTo("Umbraco.Courier.Persistence")]
|
||||
[assembly: InternalsVisibleTo("umbraco.webservices")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Concorde.Sync")]
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace umbraco.controls
|
||||
// zb-00036 #29889 : fix property types getter to get the right set of properties
|
||||
// ge : had a bit of a corrupt db and got weird NRE errors so rewrote this to catch the error and rethrow with detail
|
||||
var propertyTypes = tab.GetPropertyTypes(_content.ContentType.Id);
|
||||
foreach (var propertyType in propertyTypes)
|
||||
foreach (var propertyType in propertyTypes.OrderBy(x => x.SortOrder))
|
||||
{
|
||||
var property = _content.getProperty(propertyType);
|
||||
if (property != null && tabPage != null)
|
||||
|
||||
@@ -193,6 +193,7 @@ namespace umbraco.controls
|
||||
|
||||
// reload content type (due to caching)
|
||||
LoadContentType();
|
||||
BindTabs();
|
||||
|
||||
BindDataGenericProperties(true);
|
||||
|
||||
@@ -648,7 +649,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
|
||||
propertyType.DataTypeDefinitionId = dataTypeDefinition.Id;
|
||||
propertyType.DataTypeId = dataTypeDefinition.ControlId;
|
||||
|
||||
if (propertyType.PropertyGroupId.Value != gpw.GenricPropertyControl.Tab)
|
||||
if (propertyType.PropertyGroupId == null || propertyType.PropertyGroupId.Value != gpw.GenricPropertyControl.Tab)
|
||||
{
|
||||
if (gpw.GenricPropertyControl.Tab == 0)
|
||||
{
|
||||
@@ -893,7 +894,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
|
||||
dt.Columns.Add("id");
|
||||
dt.Columns.Add("order");
|
||||
|
||||
foreach (var grp in _contentType.PropertyTypeGroups)
|
||||
foreach (var grp in _contentType.PropertyTypeGroups.OrderBy(p => p.SortOrder))
|
||||
{
|
||||
if (grp.ContentTypeId == _contentType.Id && grp.ParentId == 0)
|
||||
{
|
||||
|
||||
@@ -76,7 +76,8 @@ namespace umbraco.editorControls
|
||||
base.Text = "";//Resets the text-field in case the value is removed
|
||||
|
||||
int integer;//The value will only be parsed if it contains a valid value
|
||||
if (int.TryParse(value, NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out integer))
|
||||
|
||||
if (int.TryParse(value, NumberStyles.AllowThousands | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out integer))
|
||||
{
|
||||
base.Text = integer.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user