AB4227 - Moved Persistence.Factories
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Models.Membership
|
||||
{
|
||||
internal static class UserGroupExtensions
|
||||
{
|
||||
public static IReadOnlyUserGroup ToReadOnlyGroup(this IUserGroup group)
|
||||
{
|
||||
//this will generally always be the case
|
||||
var readonlyGroup = group as IReadOnlyUserGroup;
|
||||
if (readonlyGroup != null) return readonlyGroup;
|
||||
|
||||
//otherwise create one
|
||||
return new ReadOnlyUserGroup(group.Id, group.Name, group.Icon, group.StartContentId, group.StartMediaId, group.Alias, group.AllowedSections, group.Permissions);
|
||||
}
|
||||
|
||||
public static bool IsSystemUserGroup(this IUserGroup group) =>
|
||||
IsSystemUserGroup(group.Alias);
|
||||
|
||||
public static bool IsSystemUserGroup(this IReadOnlyUserGroup group) =>
|
||||
IsSystemUserGroup(group.Alias);
|
||||
|
||||
public static IReadOnlyUserGroup ToReadOnlyGroup(this UserGroupDto group)
|
||||
{
|
||||
return new ReadOnlyUserGroup(group.Id, group.Name, group.Icon,
|
||||
group.StartContentId, group.StartMediaId, group.Alias,
|
||||
group.UserGroup2AppDtos.Select(x => x.AppAlias).ToArray(),
|
||||
group.DefaultPermissions == null ? Enumerable.Empty<string>() : group.DefaultPermissions.ToCharArray().Select(x => x.ToString()));
|
||||
}
|
||||
|
||||
private static bool IsSystemUserGroup(this string groupAlias)
|
||||
{
|
||||
return groupAlias == Constants.Security.AdminGroupAlias
|
||||
|| groupAlias == Constants.Security.SensitiveDataGroupAlias
|
||||
|| groupAlias == Constants.Security.TranslatorGroupAlias;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class AuditEntryFactory
|
||||
{
|
||||
public static IEnumerable<IAuditEntry> BuildEntities(IEnumerable<AuditEntryDto> dtos)
|
||||
{
|
||||
return dtos.Select(BuildEntity).ToList();
|
||||
}
|
||||
|
||||
public static IAuditEntry BuildEntity(AuditEntryDto dto)
|
||||
{
|
||||
var entity = new AuditEntry
|
||||
{
|
||||
Id = dto.Id,
|
||||
PerformingUserId = dto.PerformingUserId,
|
||||
PerformingDetails = dto.PerformingDetails,
|
||||
PerformingIp = dto.PerformingIp,
|
||||
EventDateUtc = dto.EventDateUtc,
|
||||
AffectedUserId = dto.AffectedUserId,
|
||||
AffectedDetails = dto.AffectedDetails,
|
||||
EventType = dto.EventType,
|
||||
EventDetails = dto.EventDetails
|
||||
};
|
||||
|
||||
//on initial construction we don't want to have dirty properties tracked
|
||||
// http://issues.umbraco.org/issue/U4-1946
|
||||
entity.ResetDirtyProperties(false);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static AuditEntryDto BuildDto(IAuditEntry entity)
|
||||
{
|
||||
return new AuditEntryDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
PerformingUserId = entity.PerformingUserId,
|
||||
PerformingDetails = entity.PerformingDetails,
|
||||
PerformingIp = entity.PerformingIp,
|
||||
EventDateUtc = entity.EventDateUtc,
|
||||
AffectedUserId = entity.AffectedUserId,
|
||||
AffectedDetails = entity.AffectedDetails,
|
||||
EventType = entity.EventType,
|
||||
EventDetails = entity.EventDetails
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class ConsentFactory
|
||||
{
|
||||
public static IEnumerable<IConsent> BuildEntities(IEnumerable<ConsentDto> dtos)
|
||||
{
|
||||
var ix = new Dictionary<string, Consent>();
|
||||
var output = new List<Consent>();
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
var k = dto.Source + "::" + dto.Context + "::" + dto.Action;
|
||||
|
||||
var consent = new Consent
|
||||
{
|
||||
Id = dto.Id,
|
||||
Current = dto.Current,
|
||||
CreateDate = dto.CreateDate,
|
||||
Source = dto.Source,
|
||||
Context = dto.Context,
|
||||
Action = dto.Action,
|
||||
State = (ConsentState) dto.State, // assume value is valid
|
||||
Comment = dto.Comment
|
||||
};
|
||||
|
||||
//on initial construction we don't want to have dirty properties tracked
|
||||
// http://issues.umbraco.org/issue/U4-1946
|
||||
consent.ResetDirtyProperties(false);
|
||||
|
||||
if (ix.TryGetValue(k, out var current))
|
||||
{
|
||||
if (current.HistoryInternal == null)
|
||||
current.HistoryInternal = new List<IConsent>();
|
||||
current.HistoryInternal.Add(consent);
|
||||
}
|
||||
else
|
||||
{
|
||||
ix[k] = consent;
|
||||
output.Add(consent);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public static ConsentDto BuildDto(IConsent entity)
|
||||
{
|
||||
return new ConsentDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
Current = entity.Current,
|
||||
CreateDate = entity.CreateDate,
|
||||
Source = entity.Source,
|
||||
Context = entity.Context,
|
||||
Action = entity.Action,
|
||||
State = (int) entity.State,
|
||||
Comment = entity.Comment
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,327 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal class ContentBaseFactory
|
||||
{
|
||||
private static readonly Regex MediaPathPattern = new Regex(@"(/media/.+?)(?:['""]|$)", RegexOptions.Compiled);
|
||||
|
||||
/// <summary>
|
||||
/// Builds an IContent item from a dto and content type.
|
||||
/// </summary>
|
||||
public static Content BuildEntity(DocumentDto dto, IContentType contentType)
|
||||
{
|
||||
var contentDto = dto.ContentDto;
|
||||
var nodeDto = contentDto.NodeDto;
|
||||
var documentVersionDto = dto.DocumentVersionDto;
|
||||
var contentVersionDto = documentVersionDto.ContentVersionDto;
|
||||
var publishedVersionDto = dto.PublishedVersionDto;
|
||||
|
||||
var content = new Content(nodeDto.Text, nodeDto.ParentId, contentType);
|
||||
|
||||
try
|
||||
{
|
||||
content.DisableChangeTracking();
|
||||
|
||||
content.Id = dto.NodeId;
|
||||
content.Key = nodeDto.UniqueId;
|
||||
content.VersionId = contentVersionDto.Id;
|
||||
|
||||
content.Name = contentVersionDto.Text;
|
||||
|
||||
content.Path = nodeDto.Path;
|
||||
content.Level = nodeDto.Level;
|
||||
content.ParentId = nodeDto.ParentId;
|
||||
content.SortOrder = nodeDto.SortOrder;
|
||||
content.Trashed = nodeDto.Trashed;
|
||||
|
||||
content.CreatorId = nodeDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
content.WriterId = contentVersionDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
content.CreateDate = nodeDto.CreateDate;
|
||||
content.UpdateDate = contentVersionDto.VersionDate;
|
||||
|
||||
content.Published = dto.Published;
|
||||
content.Edited = dto.Edited;
|
||||
|
||||
// TODO: shall we get published infos or not?
|
||||
//if (dto.Published)
|
||||
if (publishedVersionDto != null)
|
||||
{
|
||||
content.PublishedVersionId = publishedVersionDto.Id;
|
||||
content.PublishDate = publishedVersionDto.ContentVersionDto.VersionDate;
|
||||
content.PublishName = publishedVersionDto.ContentVersionDto.Text;
|
||||
content.PublisherId = publishedVersionDto.ContentVersionDto.UserId;
|
||||
}
|
||||
|
||||
// templates = ignored, managed by the repository
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
content.ResetDirtyProperties(false);
|
||||
return content;
|
||||
}
|
||||
finally
|
||||
{
|
||||
content.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds an IMedia item from a dto and content type.
|
||||
/// </summary>
|
||||
public static Models.Media BuildEntity(ContentDto dto, IMediaType contentType)
|
||||
{
|
||||
var nodeDto = dto.NodeDto;
|
||||
var contentVersionDto = dto.ContentVersionDto;
|
||||
|
||||
var content = new Models.Media(nodeDto.Text, nodeDto.ParentId, contentType);
|
||||
|
||||
try
|
||||
{
|
||||
content.DisableChangeTracking();
|
||||
|
||||
content.Id = dto.NodeId;
|
||||
content.Key = nodeDto.UniqueId;
|
||||
content.VersionId = contentVersionDto.Id;
|
||||
|
||||
// TODO: missing names?
|
||||
|
||||
content.Path = nodeDto.Path;
|
||||
content.Level = nodeDto.Level;
|
||||
content.ParentId = nodeDto.ParentId;
|
||||
content.SortOrder = nodeDto.SortOrder;
|
||||
content.Trashed = nodeDto.Trashed;
|
||||
|
||||
content.CreatorId = nodeDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
content.WriterId = contentVersionDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
content.CreateDate = nodeDto.CreateDate;
|
||||
content.UpdateDate = contentVersionDto.VersionDate;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
content.ResetDirtyProperties(false);
|
||||
return content;
|
||||
}
|
||||
finally
|
||||
{
|
||||
content.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds an IMedia item from a dto and content type.
|
||||
/// </summary>
|
||||
public static Member BuildEntity(MemberDto dto, IMemberType contentType)
|
||||
{
|
||||
var nodeDto = dto.ContentDto.NodeDto;
|
||||
var contentVersionDto = dto.ContentVersionDto;
|
||||
|
||||
var content = new Member(nodeDto.Text, dto.Email, dto.LoginName, dto.Password, contentType);
|
||||
|
||||
try
|
||||
{
|
||||
content.DisableChangeTracking();
|
||||
|
||||
content.Id = dto.NodeId;
|
||||
content.Key = nodeDto.UniqueId;
|
||||
content.VersionId = contentVersionDto.Id;
|
||||
|
||||
// TODO: missing names?
|
||||
|
||||
content.Path = nodeDto.Path;
|
||||
content.Level = nodeDto.Level;
|
||||
content.ParentId = nodeDto.ParentId;
|
||||
content.SortOrder = nodeDto.SortOrder;
|
||||
content.Trashed = nodeDto.Trashed;
|
||||
|
||||
content.CreatorId = nodeDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
content.WriterId = contentVersionDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
content.CreateDate = nodeDto.CreateDate;
|
||||
content.UpdateDate = contentVersionDto.VersionDate;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
content.ResetDirtyProperties(false);
|
||||
return content;
|
||||
}
|
||||
finally
|
||||
{
|
||||
content.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a dto from an IContent item.
|
||||
/// </summary>
|
||||
public static DocumentDto BuildDto(IContent entity, Guid objectType)
|
||||
{
|
||||
var contentDto = BuildContentDto(entity, objectType);
|
||||
|
||||
var dto = new DocumentDto
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
Published = entity.Published,
|
||||
ContentDto = contentDto,
|
||||
DocumentVersionDto = BuildDocumentVersionDto(entity, contentDto)
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
public static IEnumerable<(ContentSchedule Model, ContentScheduleDto Dto)> BuildScheduleDto(IContent entity, ILanguageRepository languageRepository)
|
||||
{
|
||||
return entity.ContentSchedule.FullSchedule.Select(x =>
|
||||
(x, new ContentScheduleDto
|
||||
{
|
||||
Action = x.Action.ToString(),
|
||||
Date = x.Date,
|
||||
NodeId = entity.Id,
|
||||
LanguageId = languageRepository.GetIdByIsoCode(x.Culture, false),
|
||||
Id = x.Id
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a dto from an IMedia item.
|
||||
/// </summary>
|
||||
public static MediaDto BuildDto(IMedia entity)
|
||||
{
|
||||
var contentDto = BuildContentDto(entity, Constants.ObjectTypes.Media);
|
||||
|
||||
var dto = new MediaDto
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
ContentDto = contentDto,
|
||||
MediaVersionDto = BuildMediaVersionDto(entity, contentDto)
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a dto from an IMember item.
|
||||
/// </summary>
|
||||
public static MemberDto BuildDto(IMember entity)
|
||||
{
|
||||
var contentDto = BuildContentDto(entity, Constants.ObjectTypes.Member);
|
||||
|
||||
var dto = new MemberDto
|
||||
{
|
||||
Email = entity.Email,
|
||||
LoginName = entity.Username,
|
||||
NodeId = entity.Id,
|
||||
Password = entity.RawPasswordValue,
|
||||
|
||||
ContentDto = contentDto,
|
||||
ContentVersionDto = BuildContentVersionDto(entity, contentDto)
|
||||
};
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static ContentDto BuildContentDto(IContentBase entity, Guid objectType)
|
||||
{
|
||||
var dto = new ContentDto
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
ContentTypeId = entity.ContentTypeId,
|
||||
|
||||
NodeDto = BuildNodeDto(entity, objectType)
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static NodeDto BuildNodeDto(IContentBase entity, Guid objectType)
|
||||
{
|
||||
var dto = new NodeDto
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
UniqueId = entity.Key,
|
||||
ParentId = entity.ParentId,
|
||||
Level = Convert.ToInt16(entity.Level),
|
||||
Path = entity.Path,
|
||||
SortOrder = entity.SortOrder,
|
||||
Trashed = entity.Trashed,
|
||||
UserId = entity.CreatorId,
|
||||
Text = entity.Name,
|
||||
NodeObjectType = objectType,
|
||||
CreateDate = entity.CreateDate
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
// always build the current / VersionPk dto
|
||||
// we're never going to build / save old versions (which are immutable)
|
||||
private static ContentVersionDto BuildContentVersionDto(IContentBase entity, ContentDto contentDto)
|
||||
{
|
||||
var dto = new ContentVersionDto
|
||||
{
|
||||
Id = entity.VersionId,
|
||||
NodeId = entity.Id,
|
||||
VersionDate = entity.UpdateDate,
|
||||
UserId = entity.WriterId,
|
||||
Current = true, // always building the current one
|
||||
Text = entity.Name,
|
||||
|
||||
ContentDto = contentDto
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
// always build the current / VersionPk dto
|
||||
// we're never going to build / save old versions (which are immutable)
|
||||
private static DocumentVersionDto BuildDocumentVersionDto(IContent entity, ContentDto contentDto)
|
||||
{
|
||||
var dto = new DocumentVersionDto
|
||||
{
|
||||
Id = entity.VersionId,
|
||||
TemplateId = entity.TemplateId,
|
||||
Published = false, // always building the current, unpublished one
|
||||
|
||||
ContentVersionDto = BuildContentVersionDto(entity, contentDto)
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static MediaVersionDto BuildMediaVersionDto(IMedia entity, ContentDto contentDto)
|
||||
{
|
||||
// try to get a path from the string being stored for media
|
||||
// TODO: only considering umbracoFile
|
||||
|
||||
TryMatch(entity.GetValue<string>("umbracoFile"), out var path);
|
||||
|
||||
var dto = new MediaVersionDto
|
||||
{
|
||||
Id = entity.VersionId,
|
||||
Path = path,
|
||||
|
||||
ContentVersionDto = BuildContentVersionDto(entity, contentDto)
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
// TODO: this should NOT be here?!
|
||||
// more dark magic ;-(
|
||||
internal static bool TryMatch(string text, out string path)
|
||||
{
|
||||
// In v8 we should allow exposing this via the property editor in a much nicer way so that the property editor
|
||||
// can tell us directly what any URL is for a given property if it contains an asset
|
||||
|
||||
path = null;
|
||||
if (string.IsNullOrWhiteSpace(text)) return false;
|
||||
|
||||
var m = MediaPathPattern.Match(text);
|
||||
if (!m.Success || m.Groups.Count != 2) return false;
|
||||
|
||||
path = m.Groups[1].Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
// factory for
|
||||
// IContentType (document types)
|
||||
// IMediaType (media types)
|
||||
// IMemberType (member types)
|
||||
//
|
||||
internal static class ContentTypeFactory
|
||||
{
|
||||
#region IContentType
|
||||
|
||||
public static IContentType BuildContentTypeEntity(IShortStringHelper shortStringHelper, ContentTypeDto dto)
|
||||
{
|
||||
var contentType = new ContentType(shortStringHelper, dto.NodeDto.ParentId);
|
||||
|
||||
try
|
||||
{
|
||||
contentType.DisableChangeTracking();
|
||||
|
||||
BuildCommonEntity(contentType, dto);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
contentType.ResetDirtyProperties(false);
|
||||
return contentType;
|
||||
}
|
||||
finally
|
||||
{
|
||||
contentType.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMediaType
|
||||
|
||||
public static IMediaType BuildMediaTypeEntity(IShortStringHelper shortStringHelper, ContentTypeDto dto)
|
||||
{
|
||||
var contentType = new MediaType(shortStringHelper, dto.NodeDto.ParentId);
|
||||
try
|
||||
{
|
||||
contentType.DisableChangeTracking();
|
||||
|
||||
BuildCommonEntity(contentType, dto);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
contentType.ResetDirtyProperties(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
contentType.EnableChangeTracking();
|
||||
}
|
||||
|
||||
return contentType;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMemberType
|
||||
|
||||
public static IMemberType BuildMemberTypeEntity(IShortStringHelper shortStringHelper, ContentTypeDto dto)
|
||||
{
|
||||
var contentType = new MemberType(shortStringHelper, dto.NodeDto.ParentId);
|
||||
try
|
||||
{
|
||||
contentType.DisableChangeTracking();
|
||||
BuildCommonEntity(contentType, dto, false);
|
||||
contentType.ResetDirtyProperties(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
contentType.EnableChangeTracking();
|
||||
}
|
||||
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public static IEnumerable<MemberPropertyTypeDto> BuildMemberPropertyTypeDtos(IMemberType entity)
|
||||
{
|
||||
var memberType = entity as MemberType;
|
||||
if (memberType == null || memberType.PropertyTypes.Any() == false)
|
||||
return Enumerable.Empty<MemberPropertyTypeDto>();
|
||||
|
||||
var dtos = memberType.PropertyTypes.Select(x => new MemberPropertyTypeDto
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
PropertyTypeId = x.Id,
|
||||
CanEdit = memberType.MemberCanEditProperty(x.Alias),
|
||||
ViewOnProfile = memberType.MemberCanViewProperty(x.Alias),
|
||||
IsSensitive = memberType.IsSensitiveProperty(x.Alias)
|
||||
}).ToList();
|
||||
return dtos;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Common
|
||||
|
||||
private static void BuildCommonEntity(ContentTypeBase entity, ContentTypeDto dto, bool setVariations = true)
|
||||
{
|
||||
entity.Id = dto.NodeDto.NodeId;
|
||||
entity.Key = dto.NodeDto.UniqueId;
|
||||
entity.Alias = dto.Alias;
|
||||
entity.Name = dto.NodeDto.Text;
|
||||
entity.Icon = dto.Icon;
|
||||
entity.Thumbnail = dto.Thumbnail;
|
||||
entity.SortOrder = dto.NodeDto.SortOrder;
|
||||
entity.Description = dto.Description;
|
||||
entity.CreateDate = dto.NodeDto.CreateDate;
|
||||
entity.UpdateDate = dto.NodeDto.CreateDate;
|
||||
entity.Path = dto.NodeDto.Path;
|
||||
entity.Level = dto.NodeDto.Level;
|
||||
entity.CreatorId = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
entity.AllowedAsRoot = dto.AllowAtRoot;
|
||||
entity.IsContainer = dto.IsContainer;
|
||||
entity.IsElement = dto.IsElement;
|
||||
entity.Trashed = dto.NodeDto.Trashed;
|
||||
|
||||
if (setVariations)
|
||||
entity.Variations = (ContentVariation) dto.Variations;
|
||||
}
|
||||
|
||||
public static ContentTypeDto BuildContentTypeDto(IContentTypeBase entity)
|
||||
{
|
||||
Guid nodeObjectType;
|
||||
if (entity is IContentType)
|
||||
nodeObjectType = Constants.ObjectTypes.DocumentType;
|
||||
else if (entity is IMediaType)
|
||||
nodeObjectType = Constants.ObjectTypes.MediaType;
|
||||
else if (entity is IMemberType)
|
||||
nodeObjectType = Constants.ObjectTypes.MemberType;
|
||||
else
|
||||
throw new Exception("Invalid entity.");
|
||||
|
||||
var contentTypeDto = new ContentTypeDto
|
||||
{
|
||||
Alias = entity.Alias,
|
||||
Description = entity.Description,
|
||||
Icon = entity.Icon,
|
||||
Thumbnail = entity.Thumbnail,
|
||||
NodeId = entity.Id,
|
||||
AllowAtRoot = entity.AllowedAsRoot,
|
||||
IsContainer = entity.IsContainer,
|
||||
IsElement = entity.IsElement,
|
||||
Variations = (byte) entity.Variations,
|
||||
NodeDto = BuildNodeDto(entity, nodeObjectType)
|
||||
};
|
||||
return contentTypeDto;
|
||||
}
|
||||
|
||||
private static NodeDto BuildNodeDto(IUmbracoEntity entity, Guid nodeObjectType)
|
||||
{
|
||||
var nodeDto = new NodeDto
|
||||
{
|
||||
CreateDate = entity.CreateDate,
|
||||
NodeId = entity.Id,
|
||||
Level = short.Parse(entity.Level.ToString(CultureInfo.InvariantCulture)),
|
||||
NodeObjectType = nodeObjectType,
|
||||
ParentId = entity.ParentId,
|
||||
Path = entity.Path,
|
||||
SortOrder = entity.SortOrder,
|
||||
Text = entity.Name,
|
||||
Trashed = false,
|
||||
UniqueId = entity.Key,
|
||||
UserId = entity.CreatorId
|
||||
};
|
||||
return nodeDto;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Current = Umbraco.Core.Composing.Current;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class DataTypeFactory
|
||||
{
|
||||
public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger, IIOHelper ioHelper)
|
||||
{
|
||||
if (!editors.TryGet(dto.EditorAlias, out var editor))
|
||||
{
|
||||
logger.Warn(typeof(DataType), "Could not find an editor with alias {EditorAlias}, treating as Label."
|
||||
+" The site may fail to boot and / or load data types and run.", dto.EditorAlias);
|
||||
//convert to label
|
||||
editor = new LabelPropertyEditor(logger, ioHelper, Current.Services.DataTypeService, Current.Services.TextService, Current.Services.LocalizationService, Current.ShortStringHelper);
|
||||
}
|
||||
|
||||
var dataType = new DataType(editor);
|
||||
|
||||
try
|
||||
{
|
||||
dataType.DisableChangeTracking();
|
||||
|
||||
dataType.CreateDate = dto.NodeDto.CreateDate;
|
||||
dataType.DatabaseType = dto.DbType.EnumParse<ValueStorageType>(true);
|
||||
dataType.Id = dto.NodeId;
|
||||
dataType.Key = dto.NodeDto.UniqueId;
|
||||
dataType.Level = dto.NodeDto.Level;
|
||||
dataType.UpdateDate = dto.NodeDto.CreateDate;
|
||||
dataType.Name = dto.NodeDto.Text;
|
||||
dataType.ParentId = dto.NodeDto.ParentId;
|
||||
dataType.Path = dto.NodeDto.Path;
|
||||
dataType.SortOrder = dto.NodeDto.SortOrder;
|
||||
dataType.Trashed = dto.NodeDto.Trashed;
|
||||
dataType.CreatorId = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId;
|
||||
|
||||
dataType.SetLazyConfiguration(dto.Configuration);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
dataType.ResetDirtyProperties(false);
|
||||
return dataType;
|
||||
}
|
||||
finally
|
||||
{
|
||||
dataType.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static DataTypeDto BuildDto(IDataType entity)
|
||||
{
|
||||
var dataTypeDto = new DataTypeDto
|
||||
{
|
||||
EditorAlias = entity.EditorAlias,
|
||||
NodeId = entity.Id,
|
||||
DbType = entity.DatabaseType.ToString(),
|
||||
Configuration = ConfigurationEditor.ToDatabase(entity.Configuration),
|
||||
NodeDto = BuildNodeDto(entity)
|
||||
};
|
||||
|
||||
return dataTypeDto;
|
||||
}
|
||||
|
||||
private static NodeDto BuildNodeDto(IDataType entity)
|
||||
{
|
||||
var nodeDto = new NodeDto
|
||||
{
|
||||
CreateDate = entity.CreateDate,
|
||||
NodeId = entity.Id,
|
||||
Level = Convert.ToInt16(entity.Level),
|
||||
NodeObjectType = Constants.ObjectTypes.DataType,
|
||||
ParentId = entity.ParentId,
|
||||
Path = entity.Path,
|
||||
SortOrder = entity.SortOrder,
|
||||
Text = entity.Name,
|
||||
Trashed = entity.Trashed,
|
||||
UniqueId = entity.Key,
|
||||
UserId = entity.CreatorId
|
||||
};
|
||||
|
||||
return nodeDto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class DictionaryItemFactory
|
||||
{
|
||||
#region Implementation of IEntityFactory<DictionaryItem,DictionaryDto>
|
||||
|
||||
public static IDictionaryItem BuildEntity(DictionaryDto dto)
|
||||
{
|
||||
var item = new DictionaryItem(dto.Parent, dto.Key);
|
||||
|
||||
try
|
||||
{
|
||||
item.DisableChangeTracking();
|
||||
|
||||
item.Id = dto.PrimaryKey;
|
||||
item.Key = dto.UniqueId;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
item.ResetDirtyProperties(false);
|
||||
return item;
|
||||
}
|
||||
finally
|
||||
{
|
||||
item.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static DictionaryDto BuildDto(IDictionaryItem entity)
|
||||
{
|
||||
return new DictionaryDto
|
||||
{
|
||||
UniqueId = entity.Key,
|
||||
Key = entity.ItemKey,
|
||||
Parent = entity.ParentId,
|
||||
PrimaryKey = entity.Id,
|
||||
LanguageTextDtos = BuildLanguageTextDtos(entity)
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static List<LanguageTextDto> BuildLanguageTextDtos(IDictionaryItem entity)
|
||||
{
|
||||
var list = new List<LanguageTextDto>();
|
||||
foreach (var translation in entity.Translations)
|
||||
{
|
||||
var text = new LanguageTextDto
|
||||
{
|
||||
LanguageId = translation.LanguageId,
|
||||
UniqueId = translation.Key,
|
||||
Value = translation.Value
|
||||
};
|
||||
|
||||
if (translation.HasIdentity)
|
||||
text.PrimaryKey = translation.Id;
|
||||
|
||||
list.Add(text);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class DictionaryTranslationFactory
|
||||
{
|
||||
#region Implementation of IEntityFactory<DictionaryTranslation,LanguageTextDto>
|
||||
|
||||
public static IDictionaryTranslation BuildEntity(LanguageTextDto dto, Guid uniqueId)
|
||||
{
|
||||
var item = new DictionaryTranslation(dto.LanguageId, dto.Value, uniqueId);
|
||||
|
||||
try
|
||||
{
|
||||
item.DisableChangeTracking();
|
||||
|
||||
item.Id = dto.PrimaryKey;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
item.ResetDirtyProperties(false);
|
||||
return item;
|
||||
}
|
||||
finally
|
||||
{
|
||||
item.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static LanguageTextDto BuildDto(IDictionaryTranslation entity, Guid uniqueId)
|
||||
{
|
||||
var text = new LanguageTextDto
|
||||
{
|
||||
LanguageId = entity.LanguageId,
|
||||
UniqueId = uniqueId,
|
||||
Value = entity.Value
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
text.PrimaryKey = entity.Id;
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class ExternalLoginFactory
|
||||
{
|
||||
public static IIdentityUserLogin BuildEntity(ExternalLoginDto dto)
|
||||
{
|
||||
var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId, dto.CreateDate);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
entity.ResetDirtyProperties(false);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static ExternalLoginDto BuildDto(IIdentityUserLogin entity)
|
||||
{
|
||||
var dto = new ExternalLoginDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
CreateDate = entity.CreateDate,
|
||||
LoginProvider = entity.LoginProvider,
|
||||
ProviderKey = entity.ProviderKey,
|
||||
UserId = entity.UserId
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using System.Globalization;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class LanguageFactory
|
||||
{
|
||||
public static ILanguage BuildEntity(IGlobalSettings globalSettings, LanguageDto dto)
|
||||
{
|
||||
var lang = new Language(globalSettings, dto.IsoCode)
|
||||
{
|
||||
CultureName = dto.CultureName,
|
||||
Id = dto.Id,
|
||||
IsDefault = dto.IsDefault,
|
||||
IsMandatory = dto.IsMandatory,
|
||||
FallbackLanguageId = dto.FallbackLanguageId
|
||||
};
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
lang.ResetDirtyProperties(false);
|
||||
return lang;
|
||||
}
|
||||
|
||||
public static LanguageDto BuildDto(ILanguage entity)
|
||||
{
|
||||
var dto = new LanguageDto
|
||||
{
|
||||
CultureName = entity.CultureName,
|
||||
IsoCode = entity.IsoCode,
|
||||
IsDefault = entity.IsDefault,
|
||||
IsMandatory = entity.IsMandatory,
|
||||
FallbackLanguageId = entity.FallbackLanguageId
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
{
|
||||
dto.Id = short.Parse(entity.Id.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class MacroFactory
|
||||
{
|
||||
public static IMacro BuildEntity(IShortStringHelper shortStringHelper, MacroDto dto)
|
||||
{
|
||||
var model = new Macro(shortStringHelper, dto.Id, dto.UniqueId, dto.UseInEditor, dto.RefreshRate, dto.Alias, dto.Name, dto.CacheByPage, dto.CachePersonalized, dto.DontRender, dto.MacroSource, (MacroTypes)dto.MacroType);
|
||||
|
||||
try
|
||||
{
|
||||
model.DisableChangeTracking();
|
||||
|
||||
foreach (var p in dto.MacroPropertyDtos.EmptyNull())
|
||||
{
|
||||
model.Properties.Add(new MacroProperty(p.Id, p.UniqueId, p.Alias, p.Name, p.SortOrder, p.EditorAlias));
|
||||
}
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
model.ResetDirtyProperties(false);
|
||||
return model;
|
||||
}
|
||||
finally
|
||||
{
|
||||
model.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static MacroDto BuildDto(IMacro entity)
|
||||
{
|
||||
var dto = new MacroDto
|
||||
{
|
||||
UniqueId = entity.Key,
|
||||
Alias = entity.Alias,
|
||||
CacheByPage = entity.CacheByPage,
|
||||
CachePersonalized = entity.CacheByMember,
|
||||
DontRender = entity.DontRender,
|
||||
Name = entity.Name,
|
||||
MacroSource = entity.MacroSource,
|
||||
RefreshRate = entity.CacheDuration,
|
||||
UseInEditor = entity.UseInEditor,
|
||||
MacroPropertyDtos = BuildPropertyDtos(entity),
|
||||
MacroType = (int)entity.MacroType
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = int.Parse(entity.Id.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static List<MacroPropertyDto> BuildPropertyDtos(IMacro entity)
|
||||
{
|
||||
var list = new List<MacroPropertyDto>();
|
||||
foreach (var p in entity.Properties)
|
||||
{
|
||||
var text = new MacroPropertyDto
|
||||
{
|
||||
UniqueId = p.Key,
|
||||
Alias = p.Alias,
|
||||
Name = p.Name,
|
||||
Macro = entity.Id,
|
||||
SortOrder = (byte)p.SortOrder,
|
||||
EditorAlias = p.EditorAlias,
|
||||
Id = p.Id
|
||||
};
|
||||
|
||||
list.Add(text);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class MemberGroupFactory
|
||||
{
|
||||
|
||||
private static readonly Guid _nodeObjectTypeId;
|
||||
|
||||
static MemberGroupFactory()
|
||||
{
|
||||
_nodeObjectTypeId = Constants.ObjectTypes.MemberGroup;
|
||||
}
|
||||
|
||||
#region Implementation of IEntityFactory<ITemplate,TemplateDto>
|
||||
|
||||
public static IMemberGroup BuildEntity(NodeDto dto)
|
||||
{
|
||||
var group = new MemberGroup();
|
||||
|
||||
try
|
||||
{
|
||||
group.DisableChangeTracking();
|
||||
|
||||
group.CreateDate = dto.CreateDate;
|
||||
group.Id = dto.NodeId;
|
||||
group.Key = dto.UniqueId;
|
||||
group.Name = dto.Text;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
group.ResetDirtyProperties(false);
|
||||
return group;
|
||||
}
|
||||
finally
|
||||
{
|
||||
group.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static NodeDto BuildDto(IMemberGroup entity)
|
||||
{
|
||||
var dto = new NodeDto
|
||||
{
|
||||
CreateDate = entity.CreateDate,
|
||||
NodeId = entity.Id,
|
||||
Level = 0,
|
||||
NodeObjectType = _nodeObjectTypeId,
|
||||
ParentId = -1,
|
||||
Path = "",
|
||||
SortOrder = 0,
|
||||
Text = entity.Name,
|
||||
Trashed = false,
|
||||
UniqueId = entity.Key,
|
||||
UserId = entity.CreatorId
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
{
|
||||
dto.NodeId = entity.Id;
|
||||
dto.Path = "-1," + entity.Id;
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class PropertyFactory
|
||||
{
|
||||
public static IEnumerable<IProperty> BuildEntities(IPropertyType[] propertyTypes, IReadOnlyCollection<PropertyDataDto> dtos, int publishedVersionId, ILanguageRepository languageRepository)
|
||||
{
|
||||
var properties = new List<IProperty>();
|
||||
var xdtos = dtos.GroupBy(x => x.PropertyTypeId).ToDictionary(x => x.Key, x => (IEnumerable<PropertyDataDto>)x);
|
||||
|
||||
foreach (var propertyType in propertyTypes)
|
||||
{
|
||||
var values = new List<Property.InitialPropertyValue>();
|
||||
int propertyId = default;
|
||||
|
||||
// see notes in BuildDtos - we always have edit+published dtos
|
||||
if (xdtos.TryGetValue(propertyType.Id, out var propDtos))
|
||||
{
|
||||
foreach (var propDto in propDtos)
|
||||
{
|
||||
propertyId = propDto.Id;
|
||||
values.Add(new Property.InitialPropertyValue(languageRepository.GetIsoCodeById(propDto.LanguageId), propDto.Segment, propDto.VersionId == publishedVersionId, propDto.Value));
|
||||
}
|
||||
}
|
||||
|
||||
var property = Property.CreateWithValues(propertyId, propertyType, values.ToArray());
|
||||
properties.Add(property);
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static PropertyDataDto BuildDto(int versionId, IProperty property, int? languageId, string segment, object value)
|
||||
{
|
||||
var dto = new PropertyDataDto { VersionId = versionId, PropertyTypeId = property.PropertyTypeId };
|
||||
|
||||
if (languageId.HasValue)
|
||||
dto.LanguageId = languageId;
|
||||
|
||||
if (segment != null)
|
||||
dto.Segment = segment;
|
||||
|
||||
if (property.ValueStorageType == ValueStorageType.Integer)
|
||||
{
|
||||
if (value is bool || property.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.Aliases.Boolean)
|
||||
{
|
||||
dto.IntegerValue = value != null && string.IsNullOrEmpty(value.ToString()) ? 0 : Convert.ToInt32(value);
|
||||
}
|
||||
else if (value != null && string.IsNullOrWhiteSpace(value.ToString()) == false && int.TryParse(value.ToString(), out var val))
|
||||
{
|
||||
dto.IntegerValue = val;
|
||||
}
|
||||
}
|
||||
else if (property.ValueStorageType == ValueStorageType.Decimal && value != null)
|
||||
{
|
||||
if (decimal.TryParse(value.ToString(), out var val))
|
||||
{
|
||||
dto.DecimalValue = val; // property value should be normalized already
|
||||
}
|
||||
}
|
||||
else if (property.ValueStorageType == ValueStorageType.Date && value != null && string.IsNullOrWhiteSpace(value.ToString()) == false)
|
||||
{
|
||||
if (DateTime.TryParse(value.ToString(), out var date))
|
||||
{
|
||||
dto.DateValue = date;
|
||||
}
|
||||
}
|
||||
else if (property.ValueStorageType == ValueStorageType.Ntext && value != null)
|
||||
{
|
||||
dto.TextValue = value.ToString();
|
||||
}
|
||||
else if (property.ValueStorageType == ValueStorageType.Nvarchar && value != null)
|
||||
{
|
||||
dto.VarcharValue = value.ToString();
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a collection of <see cref="PropertyDataDto"/> from a collection of <see cref="Property"/>
|
||||
/// </summary>
|
||||
/// <param name="contentVariation">
|
||||
/// The <see cref="ContentVariation"/> of the entity containing the collection of <see cref="Property"/>
|
||||
/// </param>
|
||||
/// <param name="currentVersionId"></param>
|
||||
/// <param name="publishedVersionId"></param>
|
||||
/// <param name="properties">The properties to map</param>
|
||||
/// <param name="languageRepository"></param>
|
||||
/// <param name="edited">out parameter indicating that one or more properties have been edited</param>
|
||||
/// <param name="editedCultures">
|
||||
/// Out parameter containing a collection of edited cultures when the contentVariation varies by culture.
|
||||
/// The value of this will be used to populate the edited cultures in the umbracoDocumentCultureVariation table.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<PropertyDataDto> BuildDtos(ContentVariation contentVariation, int currentVersionId, int publishedVersionId, IEnumerable<IProperty> properties,
|
||||
ILanguageRepository languageRepository, out bool edited,
|
||||
out HashSet<string> editedCultures)
|
||||
{
|
||||
var propertyDataDtos = new List<PropertyDataDto>();
|
||||
edited = false;
|
||||
editedCultures = null; // don't allocate unless necessary
|
||||
string defaultCulture = null; //don't allocate unless necessary
|
||||
|
||||
var entityVariesByCulture = contentVariation.VariesByCulture();
|
||||
|
||||
// create dtos for each property values, but only for values that do actually exist
|
||||
// ie have a non-null value, everything else is just ignored and won't have a db row
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
if (property.PropertyType.SupportsPublishing)
|
||||
{
|
||||
//create the resulting hashset if it's not created and the entity varies by culture
|
||||
if (entityVariesByCulture && editedCultures == null)
|
||||
editedCultures = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// publishing = deal with edit and published values
|
||||
foreach (var propertyValue in property.Values)
|
||||
{
|
||||
var isInvariantValue = propertyValue.Culture == null;
|
||||
var isCultureValue = propertyValue.Culture != null && propertyValue.Segment == null;
|
||||
|
||||
// deal with published value
|
||||
if (propertyValue.PublishedValue != null && publishedVersionId > 0)
|
||||
propertyDataDtos.Add(BuildDto(publishedVersionId, property, languageRepository.GetIdByIsoCode(propertyValue.Culture), propertyValue.Segment, propertyValue.PublishedValue));
|
||||
|
||||
// deal with edit value
|
||||
if (propertyValue.EditedValue != null)
|
||||
propertyDataDtos.Add(BuildDto(currentVersionId, property, languageRepository.GetIdByIsoCode(propertyValue.Culture), propertyValue.Segment, propertyValue.EditedValue));
|
||||
|
||||
// property.Values will contain ALL of it's values, both variant and invariant which will be populated if the
|
||||
// administrator has previously changed the property type to be variant vs invariant.
|
||||
// We need to check for this scenario here because otherwise the editedCultures and edited flags
|
||||
// will end up incorrectly set in the umbracoDocumentCultureVariation table so here we need to
|
||||
// only process edited cultures based on the current value type and how the property varies.
|
||||
// The above logic will still persist the currently saved property value for each culture in case the admin
|
||||
// decides to swap the property's variance again, in which case the edited flag will be recalculated.
|
||||
|
||||
if (property.PropertyType.VariesByCulture() && isInvariantValue || !property.PropertyType.VariesByCulture() && isCultureValue)
|
||||
continue;
|
||||
|
||||
// use explicit equals here, else object comparison fails at comparing eg strings
|
||||
var sameValues = propertyValue.PublishedValue == null ? propertyValue.EditedValue == null : propertyValue.PublishedValue.Equals(propertyValue.EditedValue);
|
||||
|
||||
edited |= !sameValues;
|
||||
|
||||
if (entityVariesByCulture && !sameValues)
|
||||
{
|
||||
if (isCultureValue)
|
||||
{
|
||||
editedCultures.Add(propertyValue.Culture); // report culture as edited
|
||||
}
|
||||
else if (isInvariantValue)
|
||||
{
|
||||
// flag culture as edited if it contains an edited invariant property
|
||||
if (defaultCulture == null)
|
||||
defaultCulture = languageRepository.GetDefaultIsoCode();
|
||||
|
||||
editedCultures.Add(defaultCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var propertyValue in property.Values)
|
||||
{
|
||||
// not publishing = only deal with edit values
|
||||
if (propertyValue.EditedValue != null)
|
||||
propertyDataDtos.Add(BuildDto(currentVersionId, property, languageRepository.GetIdByIsoCode(propertyValue.Culture), propertyValue.Segment, propertyValue.EditedValue));
|
||||
}
|
||||
edited = true;
|
||||
}
|
||||
}
|
||||
|
||||
return propertyDataDtos;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class PropertyGroupFactory
|
||||
{
|
||||
|
||||
#region Implementation of IEntityFactory<IEnumerable<PropertyGroup>,IEnumerable<TabDto>>
|
||||
|
||||
public static IEnumerable<PropertyGroup> BuildEntity(IEnumerable<PropertyTypeGroupDto> groupDtos,
|
||||
bool isPublishing,
|
||||
int contentTypeId,
|
||||
DateTime createDate,
|
||||
DateTime updateDate,
|
||||
Func<string, ValueStorageType, string, PropertyType> propertyTypeCtor)
|
||||
{
|
||||
// groupDtos contains all the groups, those that are defined on the current
|
||||
// content type, and those that are inherited from composition content types
|
||||
var propertyGroups = new PropertyGroupCollection();
|
||||
foreach (var groupDto in groupDtos)
|
||||
{
|
||||
var group = new PropertyGroup(isPublishing);
|
||||
|
||||
try
|
||||
{
|
||||
group.DisableChangeTracking();
|
||||
|
||||
// if the group is defined on the current content type,
|
||||
// assign its identifier, else it will be zero
|
||||
if (groupDto.ContentTypeNodeId == contentTypeId)
|
||||
group.Id = groupDto.Id;
|
||||
|
||||
group.Name = groupDto.Text;
|
||||
group.SortOrder = groupDto.SortOrder;
|
||||
group.PropertyTypes = new PropertyTypeCollection(isPublishing);
|
||||
group.Key = groupDto.UniqueId;
|
||||
|
||||
//Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded
|
||||
var typeDtos = groupDto.PropertyTypeDtos.Where(x => x.Id > 0);
|
||||
foreach (var typeDto in typeDtos)
|
||||
{
|
||||
var tempGroupDto = groupDto;
|
||||
var propertyType = propertyTypeCtor(typeDto.DataTypeDto.EditorAlias,
|
||||
typeDto.DataTypeDto.DbType.EnumParse<ValueStorageType>(true),
|
||||
typeDto.Alias);
|
||||
|
||||
try
|
||||
{
|
||||
propertyType.DisableChangeTracking();
|
||||
|
||||
propertyType.Alias = typeDto.Alias;
|
||||
propertyType.DataTypeId = typeDto.DataTypeId;
|
||||
propertyType.DataTypeKey = typeDto.DataTypeDto.NodeDto.UniqueId;
|
||||
propertyType.Description = typeDto.Description;
|
||||
propertyType.Id = typeDto.Id;
|
||||
propertyType.Key = typeDto.UniqueId;
|
||||
propertyType.Name = typeDto.Name;
|
||||
propertyType.Mandatory = typeDto.Mandatory;
|
||||
propertyType.MandatoryMessage = typeDto.MandatoryMessage;
|
||||
propertyType.SortOrder = typeDto.SortOrder;
|
||||
propertyType.ValidationRegExp = typeDto.ValidationRegExp;
|
||||
propertyType.ValidationRegExpMessage = typeDto.ValidationRegExpMessage;
|
||||
propertyType.PropertyGroupId = new Lazy<int>(() => tempGroupDto.Id);
|
||||
propertyType.CreateDate = createDate;
|
||||
propertyType.UpdateDate = updateDate;
|
||||
propertyType.Variations = (ContentVariation)typeDto.Variations;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
propertyType.ResetDirtyProperties(false);
|
||||
group.PropertyTypes.Add(propertyType);
|
||||
}
|
||||
finally
|
||||
{
|
||||
propertyType.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
group.ResetDirtyProperties(false);
|
||||
propertyGroups.Add(group);
|
||||
}
|
||||
finally
|
||||
{
|
||||
group.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
return propertyGroups;
|
||||
}
|
||||
|
||||
public static IEnumerable<PropertyTypeGroupDto> BuildDto(IEnumerable<PropertyGroup> entity)
|
||||
{
|
||||
return entity.Select(BuildGroupDto).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal static PropertyTypeGroupDto BuildGroupDto(PropertyGroup propertyGroup, int contentTypeId)
|
||||
{
|
||||
var dto = new PropertyTypeGroupDto
|
||||
{
|
||||
ContentTypeNodeId = contentTypeId,
|
||||
SortOrder = propertyGroup.SortOrder,
|
||||
Text = propertyGroup.Name,
|
||||
UniqueId = propertyGroup.Key
|
||||
};
|
||||
|
||||
if (propertyGroup.HasIdentity)
|
||||
dto.Id = propertyGroup.Id;
|
||||
|
||||
dto.PropertyTypeDtos = propertyGroup.PropertyTypes.Select(propertyType => BuildPropertyTypeDto(propertyGroup.Id, propertyType, contentTypeId)).ToList();
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
internal static PropertyTypeDto BuildPropertyTypeDto(int tabId, IPropertyType propertyType, int contentTypeId)
|
||||
{
|
||||
var propertyTypeDto = new PropertyTypeDto
|
||||
{
|
||||
Alias = propertyType.Alias,
|
||||
ContentTypeId = contentTypeId,
|
||||
DataTypeId = propertyType.DataTypeId,
|
||||
Description = propertyType.Description,
|
||||
Mandatory = propertyType.Mandatory,
|
||||
MandatoryMessage = propertyType.MandatoryMessage,
|
||||
Name = propertyType.Name,
|
||||
SortOrder = propertyType.SortOrder,
|
||||
ValidationRegExp = propertyType.ValidationRegExp,
|
||||
ValidationRegExpMessage = propertyType.ValidationRegExpMessage,
|
||||
UniqueId = propertyType.Key,
|
||||
Variations = (byte)propertyType.Variations
|
||||
};
|
||||
|
||||
if (tabId != default)
|
||||
{
|
||||
propertyTypeDto.PropertyTypeGroupId = tabId;
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyTypeDto.PropertyTypeGroupId = null;
|
||||
}
|
||||
|
||||
if (propertyType.HasIdentity)
|
||||
propertyTypeDto.Id = propertyType.Id;
|
||||
|
||||
return propertyTypeDto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class PublicAccessEntryFactory
|
||||
{
|
||||
public static PublicAccessEntry BuildEntity(AccessDto dto)
|
||||
{
|
||||
var entity = new PublicAccessEntry(dto.Id, dto.NodeId, dto.LoginNodeId, dto.NoAccessNodeId,
|
||||
dto.Rules.Select(x => new PublicAccessRule(x.Id, x.AccessId)
|
||||
{
|
||||
RuleValue = x.RuleValue,
|
||||
RuleType = x.RuleType,
|
||||
CreateDate = x.CreateDate,
|
||||
UpdateDate = x.UpdateDate
|
||||
}))
|
||||
{
|
||||
CreateDate = dto.CreateDate,
|
||||
UpdateDate = dto.UpdateDate
|
||||
};
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
entity.ResetDirtyProperties(false);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static AccessDto BuildDto(PublicAccessEntry entity)
|
||||
{
|
||||
var dto = new AccessDto
|
||||
{
|
||||
Id = entity.Key,
|
||||
NoAccessNodeId = entity.NoAccessNodeId,
|
||||
LoginNodeId = entity.LoginNodeId,
|
||||
NodeId = entity.ProtectedNodeId,
|
||||
CreateDate = entity.CreateDate,
|
||||
UpdateDate = entity.UpdateDate,
|
||||
Rules = entity.Rules.Select(x => new AccessRuleDto
|
||||
{
|
||||
AccessId = x.AccessEntryId,
|
||||
Id = x.Key,
|
||||
RuleValue = x.RuleValue,
|
||||
RuleType = x.RuleType,
|
||||
CreateDate = x.CreateDate,
|
||||
UpdateDate = x.UpdateDate
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class RelationFactory
|
||||
{
|
||||
public static IRelation BuildEntity(RelationDto dto, IRelationType relationType)
|
||||
{
|
||||
var entity = new Relation(dto.ParentId, dto.ChildId, dto.ParentObjectType, dto.ChildObjectType, relationType);
|
||||
|
||||
try
|
||||
{
|
||||
entity.DisableChangeTracking();
|
||||
|
||||
entity.Comment = dto.Comment;
|
||||
entity.CreateDate = dto.Datetime;
|
||||
entity.Id = dto.Id;
|
||||
entity.UpdateDate = dto.Datetime;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
entity.ResetDirtyProperties(false);
|
||||
return entity;
|
||||
}
|
||||
finally
|
||||
{
|
||||
entity.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static RelationDto BuildDto(IRelation entity)
|
||||
{
|
||||
var dto = new RelationDto
|
||||
{
|
||||
ChildId = entity.ChildId,
|
||||
Comment = string.IsNullOrEmpty(entity.Comment) ? string.Empty : entity.Comment,
|
||||
Datetime = entity.CreateDate,
|
||||
ParentId = entity.ParentId,
|
||||
RelationType = entity.RelationType.Id
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = entity.Id;
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class RelationTypeFactory
|
||||
{
|
||||
#region Implementation of IEntityFactory<RelationType,RelationTypeDto>
|
||||
|
||||
public static IRelationType BuildEntity(RelationTypeDto dto)
|
||||
{
|
||||
var entity = new RelationType(dto.Name, dto.Alias, dto.Dual, dto.ChildObjectType, dto.ParentObjectType);
|
||||
|
||||
try
|
||||
{
|
||||
entity.DisableChangeTracking();
|
||||
|
||||
entity.Id = dto.Id;
|
||||
entity.Key = dto.UniqueId;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
entity.ResetDirtyProperties(false);
|
||||
return entity;
|
||||
}
|
||||
finally
|
||||
{
|
||||
entity.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static RelationTypeDto BuildDto(IRelationType entity)
|
||||
{
|
||||
var dto = new RelationTypeDto
|
||||
{
|
||||
Alias = entity.Alias,
|
||||
ChildObjectType = entity.ChildObjectType,
|
||||
Dual = entity.IsBidirectional,
|
||||
Name = entity.Name,
|
||||
ParentObjectType = entity.ParentObjectType,
|
||||
UniqueId = entity.Key
|
||||
};
|
||||
if (entity.HasIdentity)
|
||||
{
|
||||
dto.Id = entity.Id;
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class ServerRegistrationFactory
|
||||
{
|
||||
public static ServerRegistration BuildEntity(ServerRegistrationDto dto)
|
||||
{
|
||||
var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive, dto.IsMaster);
|
||||
// reset dirty initial properties (U4-1946)
|
||||
model.ResetDirtyProperties(false);
|
||||
return model;
|
||||
}
|
||||
|
||||
public static ServerRegistrationDto BuildDto(IServerRegistration entity)
|
||||
{
|
||||
var dto = new ServerRegistrationDto
|
||||
{
|
||||
ServerAddress = entity.ServerAddress,
|
||||
DateRegistered = entity.CreateDate,
|
||||
IsActive = entity.IsActive,
|
||||
IsMaster = ((ServerRegistration) entity).IsMaster,
|
||||
DateAccessed = entity.UpdateDate,
|
||||
ServerIdentity = entity.ServerIdentity
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = entity.Id;
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class TagFactory
|
||||
{
|
||||
public static ITag BuildEntity(TagDto dto)
|
||||
{
|
||||
var entity = new Tag(dto.Id, dto.Group, dto.Text, dto.LanguageId) { NodeCount = dto.NodeCount };
|
||||
// reset dirty initial properties (U4-1946)
|
||||
entity.ResetDirtyProperties(false);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static TagDto BuildDto(ITag entity)
|
||||
{
|
||||
return new TagDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
Group = entity.Group,
|
||||
Text = entity.Text,
|
||||
LanguageId = entity.LanguageId
|
||||
//Key = entity.Group + "/" + entity.Text // de-normalize
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class TemplateFactory
|
||||
{
|
||||
|
||||
#region Implementation of IEntityFactory<ITemplate,TemplateDto>
|
||||
|
||||
public static Template BuildEntity(IShortStringHelper shortStringHelper, TemplateDto dto, IEnumerable<IUmbracoEntity> childDefinitions, Func<File, string> getFileContent)
|
||||
{
|
||||
var template = new Template(shortStringHelper, dto.NodeDto.Text, dto.Alias, getFileContent);
|
||||
|
||||
try
|
||||
{
|
||||
template.DisableChangeTracking();
|
||||
|
||||
template.CreateDate = dto.NodeDto.CreateDate;
|
||||
template.Id = dto.NodeId;
|
||||
template.Key = dto.NodeDto.UniqueId;
|
||||
template.Path = dto.NodeDto.Path;
|
||||
|
||||
template.IsMasterTemplate = childDefinitions.Any(x => x.ParentId == dto.NodeId);
|
||||
|
||||
if (dto.NodeDto.ParentId > 0)
|
||||
template.MasterTemplateId = new Lazy<int>(() => dto.NodeDto.ParentId);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
template.ResetDirtyProperties(false);
|
||||
return template;
|
||||
}
|
||||
finally
|
||||
{
|
||||
template.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static TemplateDto BuildDto(Template entity, Guid? nodeObjectTypeId,int primaryKey)
|
||||
{
|
||||
var dto = new TemplateDto
|
||||
{
|
||||
Alias = entity.Alias,
|
||||
NodeDto = BuildNodeDto(entity, nodeObjectTypeId)
|
||||
};
|
||||
|
||||
if (entity.MasterTemplateId != null && entity.MasterTemplateId.Value > 0)
|
||||
{
|
||||
dto.NodeDto.ParentId = entity.MasterTemplateId.Value;
|
||||
}
|
||||
|
||||
if (entity.HasIdentity)
|
||||
{
|
||||
dto.NodeId = entity.Id;
|
||||
dto.PrimaryKey = primaryKey;
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static NodeDto BuildNodeDto(Template entity,Guid? nodeObjectTypeId)
|
||||
{
|
||||
var nodeDto = new NodeDto
|
||||
{
|
||||
CreateDate = entity.CreateDate,
|
||||
NodeId = entity.Id,
|
||||
Level = 1,
|
||||
NodeObjectType = nodeObjectTypeId,
|
||||
ParentId = entity.MasterTemplateId.Value,
|
||||
Path = entity.Path,
|
||||
Text = entity.Name,
|
||||
Trashed = false,
|
||||
UniqueId = entity.Key
|
||||
};
|
||||
|
||||
return nodeDto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class UserFactory
|
||||
{
|
||||
public static IUser BuildEntity(IGlobalSettings globalSettings, UserDto dto)
|
||||
{
|
||||
var guidId = dto.Id.ToGuid();
|
||||
|
||||
var user = new User(globalSettings, dto.Id, dto.UserName, dto.Email, dto.Login,dto.Password,
|
||||
dto.UserGroupDtos.Select(x => x.ToReadOnlyGroup()).ToArray(),
|
||||
dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Content).Select(x => x.StartNode).ToArray(),
|
||||
dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Media).Select(x => x.StartNode).ToArray());
|
||||
|
||||
try
|
||||
{
|
||||
user.DisableChangeTracking();
|
||||
|
||||
user.Key = guidId;
|
||||
user.IsLockedOut = dto.NoConsole;
|
||||
user.IsApproved = dto.Disabled == false;
|
||||
user.Language = dto.UserLanguage;
|
||||
user.SecurityStamp = dto.SecurityStampToken;
|
||||
user.FailedPasswordAttempts = dto.FailedLoginAttempts ?? 0;
|
||||
user.LastLockoutDate = dto.LastLockoutDate ?? DateTime.MinValue;
|
||||
user.LastLoginDate = dto.LastLoginDate ?? DateTime.MinValue;
|
||||
user.LastPasswordChangeDate = dto.LastPasswordChangeDate ?? DateTime.MinValue;
|
||||
user.CreateDate = dto.CreateDate;
|
||||
user.UpdateDate = dto.UpdateDate;
|
||||
user.Avatar = dto.Avatar;
|
||||
user.EmailConfirmedDate = dto.EmailConfirmedDate;
|
||||
user.InvitedDate = dto.InvitedDate;
|
||||
user.TourData = dto.TourData;
|
||||
|
||||
// we should never get user with ID zero from database, except
|
||||
// when upgrading from v7 - mark that user so that we do not
|
||||
// save it back to database (as that would create a *new* user)
|
||||
// see also: UserRepository.PersistNewItem
|
||||
if (dto.Id == 0)
|
||||
user.AdditionalData["IS_V7_ZERO"] = true;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
user.ResetDirtyProperties(false);
|
||||
|
||||
return user;
|
||||
}
|
||||
finally
|
||||
{
|
||||
user.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static UserDto BuildDto(IUser entity)
|
||||
{
|
||||
var dto = new UserDto
|
||||
{
|
||||
Disabled = entity.IsApproved == false,
|
||||
Email = entity.Email,
|
||||
Login = entity.Username,
|
||||
NoConsole = entity.IsLockedOut,
|
||||
Password = entity.RawPasswordValue,
|
||||
UserLanguage = entity.Language,
|
||||
UserName = entity.Name,
|
||||
SecurityStampToken = entity.SecurityStamp,
|
||||
FailedLoginAttempts = entity.FailedPasswordAttempts,
|
||||
LastLockoutDate = entity.LastLockoutDate == DateTime.MinValue ? (DateTime?)null : entity.LastLockoutDate,
|
||||
LastLoginDate = entity.LastLoginDate == DateTime.MinValue ? (DateTime?)null : entity.LastLoginDate,
|
||||
LastPasswordChangeDate = entity.LastPasswordChangeDate == DateTime.MinValue ? (DateTime?)null : entity.LastPasswordChangeDate,
|
||||
CreateDate = entity.CreateDate,
|
||||
UpdateDate = entity.UpdateDate,
|
||||
Avatar = entity.Avatar,
|
||||
EmailConfirmedDate = entity.EmailConfirmedDate,
|
||||
InvitedDate = entity.InvitedDate,
|
||||
TourData = entity.TourData
|
||||
};
|
||||
|
||||
foreach (var startNodeId in entity.StartContentIds)
|
||||
{
|
||||
dto.UserStartNodeDtos.Add(new UserStartNodeDto
|
||||
{
|
||||
StartNode = startNodeId,
|
||||
StartNodeType = (int)UserStartNodeDto.StartNodeTypeValue.Content,
|
||||
UserId = entity.Id
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var startNodeId in entity.StartMediaIds)
|
||||
{
|
||||
dto.UserStartNodeDtos.Add(new UserStartNodeDto
|
||||
{
|
||||
StartNode = startNodeId,
|
||||
StartNodeType = (int)UserStartNodeDto.StartNodeTypeValue.Media,
|
||||
UserId = entity.Id
|
||||
});
|
||||
}
|
||||
|
||||
if (entity.HasIdentity)
|
||||
{
|
||||
dto.Id = entity.Id.SafeCast<int>();
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class UserGroupFactory
|
||||
{
|
||||
public static IUserGroup BuildEntity(IShortStringHelper shortStringHelper, UserGroupDto dto)
|
||||
{
|
||||
var userGroup = new UserGroup(shortStringHelper, dto.UserCount, dto.Alias, dto.Name,
|
||||
dto.DefaultPermissions.IsNullOrWhiteSpace()
|
||||
? Enumerable.Empty<string>()
|
||||
: dto.DefaultPermissions.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList(),
|
||||
dto.Icon);
|
||||
|
||||
try
|
||||
{
|
||||
userGroup.DisableChangeTracking();
|
||||
userGroup.Id = dto.Id;
|
||||
userGroup.CreateDate = dto.CreateDate;
|
||||
userGroup.UpdateDate = dto.UpdateDate;
|
||||
userGroup.StartContentId = dto.StartContentId;
|
||||
userGroup.StartMediaId = dto.StartMediaId;
|
||||
if (dto.UserGroup2AppDtos != null)
|
||||
{
|
||||
foreach (var app in dto.UserGroup2AppDtos)
|
||||
{
|
||||
userGroup.AddAllowedSection(app.AppAlias);
|
||||
}
|
||||
}
|
||||
|
||||
userGroup.ResetDirtyProperties(false);
|
||||
return userGroup;
|
||||
}
|
||||
finally
|
||||
{
|
||||
userGroup.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static UserGroupDto BuildDto(IUserGroup entity)
|
||||
{
|
||||
var dto = new UserGroupDto
|
||||
{
|
||||
Alias = entity.Alias,
|
||||
DefaultPermissions = entity.Permissions == null ? "" : string.Join("", entity.Permissions),
|
||||
Name = entity.Name,
|
||||
UserGroup2AppDtos = new List<UserGroup2AppDto>(),
|
||||
CreateDate = entity.CreateDate,
|
||||
UpdateDate = entity.UpdateDate,
|
||||
Icon = entity.Icon,
|
||||
StartMediaId = entity.StartMediaId,
|
||||
StartContentId = entity.StartContentId
|
||||
};
|
||||
|
||||
foreach (var app in entity.AllowedSections)
|
||||
{
|
||||
var appDto = new UserGroup2AppDto
|
||||
{
|
||||
AppAlias = app
|
||||
};
|
||||
if (entity.HasIdentity)
|
||||
{
|
||||
appDto.UserGroupId = entity.Id;
|
||||
}
|
||||
|
||||
dto.UserGroup2AppDtos.Add(appDto);
|
||||
}
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = short.Parse(entity.Id.ToString());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using static Umbraco.Core.Persistence.SqlExtensionsStatics;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
@@ -28,13 +29,21 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
private readonly Lazy<PropertyEditorCollection> _editors;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly Lazy<IDataTypeService> _dataTypeService;
|
||||
private readonly ILocalizedTextService _localizedTextService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
|
||||
// TODO: https://github.com/umbraco/Umbraco-CMS/issues/4237 - get rid of Lazy injection and fix circular dependencies
|
||||
public DataTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, Lazy<PropertyEditorCollection> editors, ILogger logger, IIOHelper ioHelper)
|
||||
public DataTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, Lazy<PropertyEditorCollection> editors, ILogger logger, IIOHelper ioHelper, Lazy<IDataTypeService> dataTypeService, ILocalizedTextService localizedTextService, ILocalizationService localizationService, IShortStringHelper shortStringHelper)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{
|
||||
_editors = editors;
|
||||
_ioHelper = ioHelper;
|
||||
_dataTypeService = dataTypeService;
|
||||
_localizedTextService = localizedTextService;
|
||||
_localizationService = localizationService;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
}
|
||||
|
||||
#region Overrides of RepositoryBase<int,DataTypeDefinition>
|
||||
@@ -58,7 +67,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
}
|
||||
|
||||
var dtos = Database.Fetch<DataTypeDto>(dataTypeSql);
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger,_ioHelper)).ToArray();
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger,_ioHelper, _dataTypeService.Value, _localizedTextService, _localizationService, _shortStringHelper)).ToArray();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IDataType> PerformGetByQuery(IQuery<IDataType> query)
|
||||
@@ -69,7 +78,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
var dtos = Database.Fetch<DataTypeDto>(sql);
|
||||
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger, _ioHelper)).ToArray();
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger, _ioHelper, _dataTypeService.Value, _localizedTextService, _localizationService, _shortStringHelper)).ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -194,7 +194,6 @@
|
||||
<Compile Include="Models\Identity\IdentityMapDefinition.cs" />
|
||||
<Compile Include="Models\Identity\IdentityUser.cs" />
|
||||
<Compile Include="Models\Identity\UserLoginInfoWrapper.cs" />
|
||||
<Compile Include="Models\Membership\UserGroupExtensions.cs" />
|
||||
<Compile Include="Models\PathValidationExtensions.cs" />
|
||||
<Compile Include="Models\UserExtensions.cs" />
|
||||
<Compile Include="Packaging\PackageDataInstallation.cs" />
|
||||
@@ -205,7 +204,6 @@
|
||||
<Compile Include="PropertyEditors\DataValueReferenceFactoryCollectionBuilder.cs" />
|
||||
<Compile Include="PropertyEditors\IDataValueReference.cs" />
|
||||
<Compile Include="PropertyEditors\IDataValueReferenceFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\MacroFactory.cs" />
|
||||
<Compile Include="Persistence\Repositories\Implement\ContentTypeCommonRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\IContentTypeCommonRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Implement\LanguageRepositoryExtensions.cs" />
|
||||
@@ -271,8 +269,6 @@
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\UpdatePickerIntegerValuesToUdi.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\UserForeignKeys.cs" />
|
||||
<Compile Include="Migrations\Upgrade\Common\CreateKeysAndIndexes.cs" />
|
||||
<Compile Include="Persistence\Factories\AuditEntryFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\ConsentFactory.cs" />
|
||||
<Compile Include="Persistence\Repositories\Implement\AuditEntryRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Implement\ConsentRepository.cs" />
|
||||
<Compile Include="RuntimeOptions.cs" />
|
||||
@@ -301,24 +297,6 @@
|
||||
<Compile Include="Persistence\DatabaseDebugHelper.cs" />
|
||||
<Compile Include="Persistence\DbCommandExtensions.cs" />
|
||||
<Compile Include="Persistence\EntityNotFoundException.cs" />
|
||||
<Compile Include="Persistence\Factories\ContentTypeFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\DataTypeFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\DictionaryItemFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\DictionaryTranslationFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\ExternalLoginFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\LanguageFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\ContentBaseFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\MemberGroupFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\PropertyFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\PropertyGroupFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\PublicAccessEntryFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\RelationFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\RelationTypeFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\ServerRegistrationFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\TagFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\TemplateFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\UserFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\UserGroupFactory.cs" />
|
||||
<Compile Include="Persistence\LocalDb.cs" />
|
||||
<Compile Include="Migrations\IMigrationContext.cs" />
|
||||
<Compile Include="Migrations\IMigrationExpression.cs" />
|
||||
@@ -564,8 +542,5 @@
|
||||
<Name>Umbraco.Infrastructure</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Persistence\Mappers" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user