Changes PetaPoco UOW to use a Queue instead of trying to order by a date which even in ticks is sometimes the same. Changes some content ext to accept the service it needs instead of relying on the app ctx singleton and obsoletes others. Fixes ContentBase.ContentTypeId to check if the Id has been set on it's true ContentTypeBase which is required with the new foreign key to insert entities (this was actually a bug without the foreign key). Updates media/content services with paging to use parameters correctly. Fixes tests.

This commit is contained in:
Shannon
2014-10-01 10:18:51 +10:00
parent 228c8ac8e0
commit 863e8b5024
10 changed files with 114 additions and 93 deletions

View File

@@ -51,7 +51,7 @@ namespace Umbraco.Core.Models
_parentId = new Lazy<int>(() => parentId);
_name = name;
_contentTypeId = int.Parse(contentType.Id.ToString(CultureInfo.InvariantCulture));
_contentTypeId = contentType.Id;
_properties = properties;
_properties.EnsurePropertyTypes(PropertyTypes);
_additionalData = new Dictionary<string, object>();
@@ -75,7 +75,7 @@ namespace Umbraco.Core.Models
_parentId = new Lazy<int>(() => parent.Id);
_name = name;
_contentTypeId = int.Parse(contentType.Id.ToString(CultureInfo.InvariantCulture));
_contentTypeId = contentType.Id;
_properties = properties;
_properties.EnsurePropertyTypes(PropertyTypes);
_additionalData = new Dictionary<string, object>();
@@ -234,7 +234,16 @@ namespace Umbraco.Core.Models
[DataMember]
public virtual int ContentTypeId
{
get { return _contentTypeId; }
get
{
//There will be cases where this has not been updated to reflect the true content type ID.
//This will occur when inserting new content.
if (_contentTypeId == 0 && ContentTypeBase != null && ContentTypeBase.HasIdentity)
{
_contentTypeId = ContentTypeBase.Id;
}
return _contentTypeId;
}
protected set
{
SetPropertyValueAndDetectChanges(o =>

View File

@@ -530,6 +530,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets the <see cref="IProfile"/> for the Creator of this media item.
/// </summary>
[Obsolete("Use the overload that declares the IUserService to use")]
public static IProfile GetCreatorProfile(this IMedia media)
{
return ApplicationContext.Current.Services.UserService.GetProfileById(media.CreatorId);
@@ -546,6 +547,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets the <see cref="IProfile"/> for the Creator of this content item.
/// </summary>
[Obsolete("Use the overload that declares the IUserService to use")]
public static IProfile GetCreatorProfile(this IContentBase content)
{
return ApplicationContext.Current.Services.UserService.GetProfileById(content.CreatorId);
@@ -562,6 +564,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets the <see cref="IProfile"/> for the Writer of this content.
/// </summary>
[Obsolete("Use the overload that declares the IUserService to use")]
public static IProfile GetWriterProfile(this IContent content)
{
return ApplicationContext.Current.Services.UserService.GetProfileById(content.WriterId);
@@ -720,14 +723,16 @@ namespace Umbraco.Core.Models
#endregion
#region XML methods
/// <summary>
/// Creates the full xml representation for the <see cref="IContent"/> object and all of it's descendants
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <param name="packagingService"></param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
internal static XElement ToDeepXml(this IContent content)
internal static XElement ToDeepXml(this IContent content, IPackagingService packagingService)
{
return ApplicationContext.Current.Services.PackagingService.Export(content, true, raiseEvents: false);
return packagingService.Export(content, true, raiseEvents: false);
}
/// <summary>
@@ -735,29 +740,54 @@ namespace Umbraco.Core.Models
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IContent content)
{
return ApplicationContext.Current.Services.PackagingService.Export(content, raiseEvents: false);
}
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <param name="packagingService"></param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content, IPackagingService packagingService)
{
return packagingService.Export(content, raiseEvents: false);
}
/// <summary>
/// Creates the xml representation for the <see cref="IMedia"/> object
/// </summary>
/// <param name="media"><see cref="IContent"/> to generate xml for</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IMedia media)
{
return ApplicationContext.Current.Services.PackagingService.Export(media, raiseEvents: false);
}
/// <summary>
/// Creates the xml representation for the <see cref="IMedia"/> object
/// </summary>
/// <param name="media"><see cref="IContent"/> to generate xml for</param>
/// <param name="packagingService"></param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IMedia media, IPackagingService packagingService)
{
return packagingService.Export(media, raiseEvents: false);
}
/// <summary>
/// Creates the full xml representation for the <see cref="IMedia"/> object and all of it's descendants
/// </summary>
/// <param name="media"><see cref="IMedia"/> to generate xml for</param>
/// <param name="packagingService"></param>
/// <returns>Xml representation of the passed in <see cref="IMedia"/></returns>
internal static XElement ToDeepXml(this IMedia media)
internal static XElement ToDeepXml(this IMedia media, IPackagingService packagingService)
{
return ApplicationContext.Current.Services.PackagingService.Export(media, true, raiseEvents: false);
return packagingService.Export(media, true, raiseEvents: false);
}
/// <summary>
@@ -766,6 +796,7 @@ namespace Umbraco.Core.Models
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <param name="isPreview">Boolean indicating whether the xml should be generated for preview</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IContent content, bool isPreview)
{
//TODO Do a proper implementation of this
@@ -773,15 +804,41 @@ namespace Umbraco.Core.Models
return content.ToXml();
}
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <param name="packagingService"></param>
/// <param name="isPreview">Boolean indicating whether the xml should be generated for preview</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content, IPackagingService packagingService, bool isPreview)
{
//TODO Do a proper implementation of this
//If current IContent is published we should get latest unpublished version
return content.ToXml(packagingService);
}
/// <summary>
/// Creates the xml representation for the <see cref="IMember"/> object
/// </summary>
/// <param name="member"><see cref="IMember"/> to generate xml for</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IMember member)
{
return ((PackagingService)(ApplicationContext.Current.Services.PackagingService)).Export(member);
}
/// <summary>
/// Creates the xml representation for the <see cref="IMember"/> object
/// </summary>
/// <param name="member"><see cref="IMember"/> to generate xml for</param>
/// <param name="packagingService"></param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IMember member, IPackagingService packagingService)
{
return ((PackagingService)(packagingService)).Export(member);
}
#endregion
}
}

View File

@@ -310,7 +310,7 @@ namespace Umbraco.Core.Persistence.Repositories
if (totalRecords > 0)
{
//Crete the inner paged query that was used above to get the paged result, we'll use that as the inner sub query
var args = sqlNodeIds.Arguments;
var args = sqlNodeIdsWithSort.Arguments;
string sqlStringCount, sqlStringPage;
Database.BuildPageQueries<TDto>(pageIndex * pageSize, pageSize, sqlNodeIdsWithSort.SQL, ref args, out sqlStringCount, out sqlStringPage);

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Core.Persistence.UnitOfWork
internal Guid InstanceId { get; private set; }
private Guid _key;
private readonly List<Operation> _operations = new List<Operation>();
private readonly Queue<Operation> _operations = new Queue<Operation>();
/// <summary>
/// Creates a new unit of work instance
@@ -40,14 +40,13 @@ namespace Umbraco.Core.Persistence.UnitOfWork
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
public void RegisterAdded(IEntity entity, IUnitOfWorkRepository repository)
{
_operations.Add(
new Operation
{
Entity = entity,
ProcessDate = DateTime.Now,
Repository = repository,
Type = TransactionType.Insert
});
_operations.Enqueue(new Operation
{
Entity = entity,
ProcessDate = DateTime.Now,
Repository = repository,
Type = TransactionType.Insert
});
}
/// <summary>
@@ -57,14 +56,14 @@ namespace Umbraco.Core.Persistence.UnitOfWork
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
public void RegisterChanged(IEntity entity, IUnitOfWorkRepository repository)
{
_operations.Add(
new Operation
{
Entity = entity,
ProcessDate = DateTime.Now,
Repository = repository,
Type = TransactionType.Update
});
_operations.Enqueue(
new Operation
{
Entity = entity,
ProcessDate = DateTime.Now,
Repository = repository,
Type = TransactionType.Update
});
}
/// <summary>
@@ -74,14 +73,14 @@ namespace Umbraco.Core.Persistence.UnitOfWork
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
public void RegisterRemoved(IEntity entity, IUnitOfWorkRepository repository)
{
_operations.Add(
new Operation
{
Entity = entity,
ProcessDate = DateTime.Now,
Repository = repository,
Type = TransactionType.Delete
});
_operations.Enqueue(
new Operation
{
Entity = entity,
ProcessDate = DateTime.Now,
Repository = repository,
Type = TransactionType.Delete
});
}
/// <summary>
@@ -107,8 +106,9 @@ namespace Umbraco.Core.Persistence.UnitOfWork
{
using (var transaction = Database.GetTransaction())
{
foreach (var operation in _operations.OrderBy(o => o.ProcessDate))
while (_operations.Count > 0)
{
var operation = _operations.Dequeue();
switch (operation.Type)
{
case TransactionType.Insert:

View File

@@ -37,7 +37,7 @@ namespace Umbraco.Core.Services
private readonly IDatabaseUnitOfWorkProvider _uowProvider;
private Dictionary<string, IContentType> _importedContentTypes;
private IPackageInstallation _packageInstallation;
private readonly IUserService userService;
private readonly IUserService _userService;
public PackagingService(IContentService contentService,
@@ -60,7 +60,7 @@ namespace Umbraco.Core.Services
_localizationService = localizationService;
_repositoryFactory = repositoryFactory;
_uowProvider = uowProvider;
_userService = userService;
_importedContentTypes = new Dictionary<string, IContentType>();
}
@@ -84,7 +84,7 @@ namespace Umbraco.Core.Services
}
var exporter = new EntityXmlSerializer();
var xml = exporter.Serialize(_contentService, _dataTypeService, userService, content, deep);
var xml = exporter.Serialize(_contentService, _dataTypeService, _userService, content, deep);
if(raiseEvents)
ExportedContent.RaiseEvent(new ExportEventArgs<IContent>(content, xml, false), this);
@@ -1220,7 +1220,7 @@ namespace Umbraco.Core.Services
}
var exporter = new EntityXmlSerializer();
var xml = exporter.Serialize(_mediaService, _dataTypeService, userService, media, deep);
var xml = exporter.Serialize(_mediaService, _dataTypeService, _userService, media, deep);
if(raiseEvents)
ExportedMedia.RaiseEvent(new ExportEventArgs<IMedia>(media, xml, false), this);

View File

@@ -139,6 +139,7 @@ namespace Umbraco.Tests.Persistence
using (Transaction transaction = Database.GetTransaction())
{
Database.CreateTable<NodeDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<ContentDto>();
Database.CreateTable<ContentVersionDto>();
@@ -153,6 +154,7 @@ namespace Umbraco.Tests.Persistence
using (Transaction transaction = Database.GetTransaction())
{
Database.CreateTable<NodeDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<ContentDto>();
Database.CreateTable<ContentXmlDto>();
@@ -232,6 +234,7 @@ namespace Umbraco.Tests.Persistence
using (Transaction transaction = Database.GetTransaction())
{
Database.CreateTable<NodeDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<ContentDto>();
Database.CreateTable<TemplateDto>();
Database.CreateTable<DocumentDto>();
@@ -311,6 +314,7 @@ namespace Umbraco.Tests.Persistence
using (Transaction transaction = Database.GetTransaction())
{
Database.CreateTable<NodeDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<ContentDto>();
Database.CreateTable<MemberDto>();
@@ -325,6 +329,7 @@ namespace Umbraco.Tests.Persistence
using (Transaction transaction = Database.GetTransaction())
{
Database.CreateTable<NodeDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<ContentDto>();
Database.CreateTable<MemberDto>();
Database.CreateTable<Member2MemberGroupDto>();
@@ -354,6 +359,7 @@ namespace Umbraco.Tests.Persistence
using (Transaction transaction = Database.GetTransaction())
{
Database.CreateTable<NodeDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<ContentDto>();
Database.CreateTable<ContentVersionDto>();
Database.CreateTable<PreviewXmlDto>();
@@ -480,6 +486,7 @@ namespace Umbraco.Tests.Persistence
using (Transaction transaction = Database.GetTransaction())
{
Database.CreateTable<NodeDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<ContentDto>();
Database.CreateTable<ContentTypeDto>();
Database.CreateTable<DataTypeDto>();

View File

@@ -285,7 +285,7 @@ namespace Umbraco.Tests
public void Resolves_Attributed_Trees()
{
var trees = PluginManager.Current.ResolveAttributedTrees();
Assert.AreEqual(19, trees.Count());
Assert.AreEqual(18, trees.Count());
}
[Test]

View File

@@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using umbraco.cms.presentation.Trees;
using Constants = Umbraco.Core.Constants;
using Umbraco.Web.WebApi.Filters;
using Umbraco.Web.Mvc;
using umbraco.cms.businesslogic.template;
using Umbraco.Web.Models.Trees;
//namespace Umbraco.Web.Trees
//{
// [UmbracoApplicationAuthorize(Constants.Applications.Settings)]
// [Tree(Constants.Applications.Settings, Constants.Trees.Templates, "Templates")]
// [PluginController("UmbracoTrees")]
// [CoreTree]
// public class TemplateTreeController : TreeController
// {
// protected override Models.Trees.MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
// {
// return new Models.Trees.MenuItemCollection();
// }
// protected override Models.Trees.TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
// {
// IEnumerable<Umbraco.Core.Models.EntityBase.IUmbracoEntity> templates;
// var nodes = new TreeNodeCollection();
// if (id == "-1")
// templates = Services.EntityService.GetRootEntities(Core.Models.UmbracoObjectTypes.Template);
// else
// templates = Services.EntityService.GetChildren(int.Parse(id), Core.Models.UmbracoObjectTypes.Template);
// foreach (var t in templates)
// {
// var node = CreateTreeNode(t.Id.ToString(), t.ParentId.ToString(), queryStrings, t.Name);
// node.Icon = "icon-newspaper-alt";
// node.HasChildren = Services.EntityService.GetChildren(t.Id, Core.Models.UmbracoObjectTypes.Template).Any();
// if (node.HasChildren)
// node.Icon = "icon-newspaper";
// nodes.Add(node);
// }
// return nodes;
// }
// }
//}

View File

@@ -76,7 +76,7 @@ namespace UmbracoExamine.DataServices
var xmlContent = XDocument.Parse("<content></content>");
foreach (var c in _applicationContext.Services.ContentService.GetRootContent())
{
xmlContent.Root.Add(c.ToDeepXml());
xmlContent.Root.Add(c.ToDeepXml(_applicationContext.Services.PackagingService));
}
var result = ((IEnumerable)xmlContent.XPathEvaluate(xpath)).Cast<XElement>();
return result.ToXDocument();

View File

@@ -45,7 +45,7 @@ namespace UmbracoExamine.DataServices
var xmlMedia = XDocument.Parse("<media></media>");
foreach (var m in _services.MediaService.GetRootMedia())
{
xmlMedia.Root.Add(m.ToDeepXml());
xmlMedia.Root.Add(m.ToDeepXml(_services.PackagingService));
}
var result = ((IEnumerable)xmlMedia.XPathEvaluate(xpath)).Cast<XElement>();
return result.ToXDocument();