Merge branch 'temp8' into temp8-U4-11220

This commit is contained in:
Stephan
2018-04-25 17:38:36 +02:00
7 changed files with 104 additions and 113 deletions

View File

@@ -275,6 +275,19 @@ namespace Umbraco.Core.Models
if (ValidateAll().Any()) if (ValidateAll().Any())
return false; return false;
// Name and PublishName are managed by the repository, but Names and PublishNames
// must be managed here as they depend on the existing / supported variations.
if (string.IsNullOrWhiteSpace(Name))
throw new InvalidOperationException($"Cannot publish invariant culture without a name.");
PublishName = Name;
foreach (var (languageId, name) in Names)
{
if (string.IsNullOrWhiteSpace(name))
throw new InvalidOperationException($"Cannot publish {languageId} culture without a name.");
SetPublishName(languageId, name);
}
// property.PublishAllValues only deals with supported variations (if any) // property.PublishAllValues only deals with supported variations (if any)
foreach (var property in Properties) foreach (var property in Properties)
property.PublishAllValues(); property.PublishAllValues();
@@ -298,15 +311,21 @@ namespace Umbraco.Core.Models
// the values we want to publish should be valid // the values we want to publish should be valid
if (Validate(languageId, segment).Any()) if (Validate(languageId, segment).Any())
return false; return false;
// Name and PublishName are managed by the repository, but Names and PublishNames
// must be managed here as they depend on the existing / supported variations.
if (segment == null)
{
var name = GetName(languageId);
if (string.IsNullOrWhiteSpace(name))
throw new InvalidOperationException($"Cannot publish {languageId?.ToString() ?? "invariant"} culture without a name.");
SetPublishName(languageId, name);
}
// property.PublishValue throws on invalid variation, so filter them out // property.PublishValue throws on invalid variation, so filter them out
foreach (var property in Properties.Where(x => x.PropertyType.ValidateVariation(languageId, segment, throwIfInvalid: false))) foreach (var property in Properties.Where(x => x.PropertyType.ValidateVariation(languageId, segment, throwIfInvalid: false)))
property.PublishValue(languageId, segment); property.PublishValue(languageId, segment);
// Name and PublishName are managed by the repository, but Names and PublishNames
// must be managed here as they depend on the existing / supported variations.
SetPublishName(languageId, GetName(languageId));
_publishedState = PublishedState.Publishing; _publishedState = PublishedState.Publishing;
return true; return true;
} }
@@ -317,15 +336,18 @@ namespace Umbraco.Core.Models
// the values we want to publish should be valid // the values we want to publish should be valid
if (ValidateCulture(languageId).Any()) if (ValidateCulture(languageId).Any())
return false; return false;
// Name and PublishName are managed by the repository, but Names and PublishNames
// must be managed here as they depend on the existing / supported variations.
var name = GetName(languageId);
if (string.IsNullOrWhiteSpace(name))
throw new InvalidOperationException($"Cannot publish {languageId?.ToString() ?? "invariant"} culture without a name.");
SetPublishName(languageId, name);
// property.PublishCultureValues only deals with supported variations (if any) // property.PublishCultureValues only deals with supported variations (if any)
foreach (var property in Properties) foreach (var property in Properties)
property.PublishCultureValues(languageId); property.PublishCultureValues(languageId);
// Name and PublishName are managed by the repository, but Names and PublishNames
// must be managed here as they depend on the existing / supported variations.
SetPublishName(languageId, GetName(languageId));
_publishedState = PublishedState.Publishing; _publishedState = PublishedState.Publishing;
return true; return true;
} }

View File

@@ -20,6 +20,7 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Scoping; using Umbraco.Core.Scoping;
using Umbraco.Core.Services; using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement; using Umbraco.Core.Services.Implement;
using static Umbraco.Core.Persistence.NPocoSqlExtensions.Statics;
namespace Umbraco.Core.Persistence.Repositories.Implement namespace Umbraco.Core.Persistence.Repositories.Implement
{ {
@@ -852,7 +853,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected virtual string EnsureUniqueNodeName(int parentId, string nodeName, int id = 0) protected virtual string EnsureUniqueNodeName(int parentId, string nodeName, int id = 0)
{ {
var template = SqlContext.Templates.Get("Umbraco.Core.VersionableRepository.EnsureUniqueNodeName", tsql => tsql var template = SqlContext.Templates.Get("Umbraco.Core.VersionableRepository.EnsureUniqueNodeName", tsql => tsql
.Select<NodeDto>(x => NPocoSqlExtensions.Statics.Alias(x.NodeId, "id"), x => NPocoSqlExtensions.Statics.Alias(x.Text, "name")) .Select<NodeDto>(x => Alias(x.NodeId, "id"), x => Alias(x.Text, "name"))
.From<NodeDto>() .From<NodeDto>()
.Where<NodeDto>(x => x.NodeObjectType == SqlTemplate.Arg<Guid>("nodeObjectType") && x.ParentId == SqlTemplate.Arg<int>("parentId"))); .Where<NodeDto>(x => x.NodeObjectType == SqlTemplate.Arg<Guid>("nodeObjectType") && x.ParentId == SqlTemplate.Arg<int>("parentId")));

View File

@@ -15,6 +15,7 @@ using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Scoping; using Umbraco.Core.Scoping;
using Umbraco.Core.Services; using Umbraco.Core.Services;
using static Umbraco.Core.Persistence.NPocoSqlExtensions.Statics;
namespace Umbraco.Core.Persistence.Repositories.Implement namespace Umbraco.Core.Persistence.Repositories.Implement
{ {
@@ -280,7 +281,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
private string EnsureUniqueNodeName(string nodeName, int id = 0) private string EnsureUniqueNodeName(string nodeName, int id = 0)
{ {
var template = SqlContext.Templates.Get("Umbraco.Core.DataTypeDefinitionRepository.EnsureUniqueNodeName", tsql => tsql var template = SqlContext.Templates.Get("Umbraco.Core.DataTypeDefinitionRepository.EnsureUniqueNodeName", tsql => tsql
.Select<NodeDto>(x => NPocoSqlExtensions.Statics.Alias(x.NodeId, "id"), x => NPocoSqlExtensions.Statics.Alias(x.Text, "name")) .Select<NodeDto>(x => Alias(x.NodeId, "id"), x => Alias(x.Text, "name"))
.From<NodeDto>() .From<NodeDto>()
.Where<NodeDto>(x => x.NodeObjectType == SqlTemplate.Arg<Guid>("nodeObjectType"))); .Where<NodeDto>(x => x.NodeObjectType == SqlTemplate.Arg<Guid>("nodeObjectType")));

View File

@@ -8,6 +8,7 @@ using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Dtos;
using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Scoping; using Umbraco.Core.Scoping;
using static Umbraco.Core.Persistence.NPocoSqlExtensions.Statics;
namespace Umbraco.Core.Persistence.Repositories.Implement namespace Umbraco.Core.Persistence.Repositories.Implement
{ {
@@ -128,7 +129,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var dtos = page.Items; var dtos = page.Items;
var entities = dtos.Select(x => BuildEntity(isContent, isMedia, x)).ToArray(); var entities = dtos.Select(x => BuildEntity(isContent, isMedia, x)).ToArray();
//TODO: For isContent will we need to build up the variation info? //TODO: For isContent will we need to build up the variation info?
if (isMedia) if (isMedia)
BuildProperties(entities, dtos); BuildProperties(entities, dtos);
@@ -144,35 +145,36 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
return dto == null ? null : BuildEntity(false, false, dto); return dto == null ? null : BuildEntity(false, false, dto);
} }
private IEntitySlim GetEntity(Sql<ISqlContext> sql, bool isContent, bool isMedia)
{
//isContent is going to return a 1:M result now with the variants so we need to do different things
if (isContent)
{
var dtos = Database.FetchOneToMany<ContentEntityDto>(
ddto => ddto.VariationInfo,
ddto => ddto.VersionId,
sql);
return dtos.Count == 0 ? null : BuildDocumentEntity(dtos[0]);
}
var dto = Database.FirstOrDefault<BaseDto>(sql);
if (dto == null) return null;
var entity = BuildEntity(false, isMedia, dto);
if (isMedia)
BuildProperties(entity, dto);
return entity;
}
public IEntitySlim Get(Guid key, Guid objectTypeId) public IEntitySlim Get(Guid key, Guid objectTypeId)
{ {
var isContent = objectTypeId == Constants.ObjectTypes.Document || objectTypeId == Constants.ObjectTypes.DocumentBlueprint; var isContent = objectTypeId == Constants.ObjectTypes.Document || objectTypeId == Constants.ObjectTypes.DocumentBlueprint;
var isMedia = objectTypeId == Constants.ObjectTypes.Media; var isMedia = objectTypeId == Constants.ObjectTypes.Media;
var sql = GetFullSqlForEntityType(isContent, isMedia, objectTypeId, key); var sql = GetFullSqlForEntityType(isContent, isMedia, objectTypeId, key);
return GetEntity(sql, isContent, isMedia);
//isContent is going to return a 1:M result now with the variants so we need to do different things
if (isContent)
{
var dtos = Database.FetchOneToMany<ContentEntityDto>(
dto => dto.VariationInfo,
dto => dto.VersionId,
sql);
if (dtos.Count == 0) return null;
return BuildDocumentEntity(dtos[0]);
}
else
{
var dto = Database.FirstOrDefault<BaseDto>(sql);
if (dto == null) return null;
var entity = BuildEntity(isContent, isMedia, dto);
if (isMedia)
BuildProperties(entity, dto);
return entity;
}
} }
public virtual IEntitySlim Get(int id) public virtual IEntitySlim Get(int id)
@@ -188,30 +190,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var isMedia = objectTypeId == Constants.ObjectTypes.Media; var isMedia = objectTypeId == Constants.ObjectTypes.Media;
var sql = GetFullSqlForEntityType(isContent, isMedia, objectTypeId, id); var sql = GetFullSqlForEntityType(isContent, isMedia, objectTypeId, id);
return GetEntity(sql, isContent, isMedia);
//isContent is going to return a 1:M result now with the variants so we need to do different things
if (isContent)
{
var dtos = Database.FetchOneToMany<ContentEntityDto>(
dto => dto.VariationInfo,
dto => dto.VersionId,
sql);
if (dtos.Count == 0) return null;
return BuildDocumentEntity(dtos[0]);
}
else
{
var dto = Database.FirstOrDefault<BaseDto>(sql);
if (dto == null) return null;
var entity = BuildEntity(isContent, isMedia, dto);
if (isMedia)
BuildProperties(entity, dto);
return entity;
}
} }
public virtual IEnumerable<IEntitySlim> GetAll(Guid objectType, params int[] ids) public virtual IEnumerable<IEntitySlim> GetAll(Guid objectType, params int[] ids)
@@ -228,36 +207,38 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
: PerformGetAll(objectType); : PerformGetAll(objectType);
} }
private IEnumerable<IEntitySlim> GetEntities(Sql<ISqlContext> sql, bool isContent, bool isMedia)
{
//isContent is going to return a 1:M result now with the variants so we need to do different things
if (isContent)
{
var cdtos = Database.FetchOneToMany<ContentEntityDto>(
dto => dto.VariationInfo,
dto => dto.VersionId,
sql);
return cdtos.Count == 0
? Enumerable.Empty<IEntitySlim>()
: cdtos.Select(BuildDocumentEntity).ToArray();
}
var dtos = Database.Fetch<BaseDto>(sql);
if (dtos.Count == 0) return Enumerable.Empty<IEntitySlim>();
var entities = dtos.Select(x => BuildEntity(false, isMedia, x)).ToArray();
if (isMedia)
BuildProperties(entities, dtos);
return entities;
}
private IEnumerable<IEntitySlim> PerformGetAll(Guid objectType, Action<Sql<ISqlContext>> filter = null) private IEnumerable<IEntitySlim> PerformGetAll(Guid objectType, Action<Sql<ISqlContext>> filter = null)
{ {
var isContent = objectType == Constants.ObjectTypes.Document || objectType == Constants.ObjectTypes.DocumentBlueprint; var isContent = objectType == Constants.ObjectTypes.Document || objectType == Constants.ObjectTypes.DocumentBlueprint;
var isMedia = objectType == Constants.ObjectTypes.Media; var isMedia = objectType == Constants.ObjectTypes.Media;
var sql = GetFullSqlForEntityType(isContent, isMedia, objectType, filter); var sql = GetFullSqlForEntityType(isContent, isMedia, objectType, filter);
return GetEntities(sql, isContent, isMedia);
//isContent is going to return a 1:M result now with the variants so we need to do different things
if (isContent)
{
var dtos = Database.FetchOneToMany<ContentEntityDto>(
dto => dto.VariationInfo,
dto => dto.VersionId,
sql);
if (dtos.Count == 0) return Enumerable.Empty<IEntitySlim>();
var entities = dtos.Select(x => BuildDocumentEntity(x)).ToArray();
return entities;
}
else
{
var dtos = Database.Fetch<BaseDto>(sql);
if (dtos.Count == 0) return Enumerable.Empty<IEntitySlim>();
var entities = dtos.Select(x => BuildEntity(isContent, isMedia, x)).ToArray();
if (isMedia)
BuildProperties(entities, dtos);
return entities;
}
} }
public virtual IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params int[] ids) public virtual IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params int[] ids)
@@ -302,30 +283,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
sql = translator.Translate(); sql = translator.Translate();
sql = AddGroupBy(isContent, isMedia, sql); sql = AddGroupBy(isContent, isMedia, sql);
//isContent is going to return a 1:M result now with the variants so we need to do different things return GetEntities(sql, isContent, isMedia);
if (isContent)
{
var dtos = Database.FetchOneToMany<ContentEntityDto>(
dto => dto.VariationInfo,
dto => dto.VersionId,
sql);
if (dtos.Count == 0) return Enumerable.Empty<IEntitySlim>();
var entities = dtos.Select(x => BuildDocumentEntity(x)).ToArray();
return entities;
}
else
{
var dtos = Database.Fetch<BaseDto>(sql);
if (dtos.Count == 0) return Enumerable.Empty<IEntitySlim>();
var entities = dtos.Select(x => BuildEntity(isContent, isMedia, x)).ToArray();
if (isMedia)
BuildProperties(entities, dtos);
return entities;
}
} }
public UmbracoObjectTypes GetObjectType(int id) public UmbracoObjectTypes GetObjectType(int id)
@@ -554,9 +512,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
.AndSelect<DocumentDto>(x => x.Published, x => x.Edited) .AndSelect<DocumentDto>(x => x.Published, x => x.Edited)
//This MUST come last in the select statements since we will end up with a 1:M query //This MUST come last in the select statements since we will end up with a 1:M query
.AndSelect<ContentVersionCultureVariationDto>( .AndSelect<ContentVersionCultureVariationDto>(
x => NPocoSqlExtensions.Statics.Alias(x.Id, "versionCultureId"), x => Alias(x.Id, "versionCultureId"),
x => NPocoSqlExtensions.Statics.Alias(x.LanguageId, "versionCultureLangId"), x => Alias(x.LanguageId, "versionCultureLangId"),
x => NPocoSqlExtensions.Statics.Alias(x.Name, "versionCultureName")); x => Alias(x.Name, "versionCultureName"));
} }
} }

View File

@@ -286,7 +286,7 @@ AnotherContentFinder
public void GetDataEditors() public void GetDataEditors()
{ {
var types = _typeLoader.GetDataEditors(); var types = _typeLoader.GetDataEditors();
Assert.AreEqual(42, types.Count()); Assert.AreEqual(43, types.Count());
} }
[Test] [Test]

View File

@@ -236,6 +236,8 @@ namespace Umbraco.Tests.Models
// can publish value // can publish value
// and get edited and published values // and get edited and published values
Assert.Throws<InvalidOperationException>(() => content.PublishValues(1)); // no name
content.SetName(1, "name-fr");
content.PublishValues(1); content.PublishValues(1);
Assert.AreEqual("b", content.GetValue("prop")); Assert.AreEqual("b", content.GetValue("prop"));
Assert.IsNull(content.GetValue("prop", published: true)); Assert.IsNull(content.GetValue("prop", published: true));

View File

@@ -163,7 +163,7 @@ namespace Umbraco.Web.Models.Mapping
// fixme not so clean really // fixme not so clean really
var isPublishing = typeof(IContentType).IsAssignableFrom(typeof(TDestination)); var isPublishing = typeof(IContentType).IsAssignableFrom(typeof(TDestination));
return mapping mapping = mapping
//only map id if set to something higher then zero //only map id if set to something higher then zero
.ForMember(dest => dest.Id, opt => opt.Condition(src => (Convert.ToInt32(src.Id) > 0))) .ForMember(dest => dest.Id, opt => opt.Condition(src => (Convert.ToInt32(src.Id) > 0)))
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => Convert.ToInt32(src.Id))) .ForMember(dest => dest.Id, opt => opt.MapFrom(src => Convert.ToInt32(src.Id)))
@@ -179,10 +179,15 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dest => dest.PropertyGroups, opt => opt.Ignore()) .ForMember(dest => dest.PropertyGroups, opt => opt.Ignore())
.ForMember(dest => dest.NoGroupPropertyTypes, opt => opt.Ignore()) .ForMember(dest => dest.NoGroupPropertyTypes, opt => opt.Ignore())
// ignore, composition is managed in AfterMapContentTypeSaveToEntity // ignore, composition is managed in AfterMapContentTypeSaveToEntity
.ForMember(dest => dest.ContentTypeComposition, opt => opt.Ignore()) .ForMember(dest => dest.ContentTypeComposition, opt => opt.Ignore());
.ForMember(dto => dto.Variations, opt => opt.ResolveUsing<ContentTypeVariationsResolver<TSource, TSourcePropertyType, TDestination>>())
// ignore for members
mapping = typeof(TDestination) == typeof(IMemberType)
? mapping.ForMember(dto => dto.Variations, opt => opt.Ignore())
: mapping.ForMember(dto => dto.Variations, opt => opt.ResolveUsing<ContentTypeVariationsResolver<TSource, TSourcePropertyType, TDestination>>());
mapping = mapping
.ForMember( .ForMember(
dest => dest.AllowedContentTypes, dest => dest.AllowedContentTypes,
opt => opt.MapFrom(src => src.AllowedContentTypes.Select((t, i) => new ContentTypeSort(t, i)))) opt => opt.MapFrom(src => src.AllowedContentTypes.Select((t, i) => new ContentTypeSort(t, i))))
@@ -257,6 +262,8 @@ namespace Umbraco.Web.Models.Mapping
// because all property collections were rebuilt, there is no need to remove // because all property collections were rebuilt, there is no need to remove
// some old properties, they are just gone and will be cleared by the repository // some old properties, they are just gone and will be cleared by the repository
}); });
return mapping;
} }
private static PropertyGroup MapSaveGroup<TPropertyType>(PropertyGroupBasic<TPropertyType> sourceGroup, IEnumerable<PropertyGroup> destOrigGroups) private static PropertyGroup MapSaveGroup<TPropertyType>(PropertyGroupBasic<TPropertyType> sourceGroup, IEnumerable<PropertyGroup> destOrigGroups)