public static IMedia BuildEntity(ContentVersionDto dto, IMediaType contentType) { var media = new Models.Media(dto.ContentDto.NodeDto.Text, dto.ContentDto.NodeDto.ParentId, contentType); try { media.DisableChangeTracking(); media.Id = dto.NodeId; media.Key = dto.ContentDto.NodeDto.UniqueId; media.Path = dto.ContentDto.NodeDto.Path; media.CreatorId = dto.ContentDto.NodeDto.UserId.Value; media.Level = dto.ContentDto.NodeDto.Level; media.ParentId = dto.ContentDto.NodeDto.ParentId; media.SortOrder = dto.ContentDto.NodeDto.SortOrder; media.Trashed = dto.ContentDto.NodeDto.Trashed; media.CreateDate = dto.ContentDto.NodeDto.CreateDate; media.UpdateDate = dto.VersionDate; media.Version = dto.VersionId; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 media.ResetDirtyProperties(false); return(media); } finally { media.EnableChangeTracking(); } }
public MediaDto BuildDto(IMedia entity) { var versionDto = new ContentVersionDto { NodeId = entity.Id, VersionDate = entity.UpdateDate, VersionId = entity.Version, ContentDto = BuildContentDto(entity) }; //Extract the media path for storage string mediaPath; TryMatch(entity.GetValue <string>("umbracoFile"), out mediaPath); var dto = new MediaDto() { NodeId = entity.Id, ContentVersionDto = versionDto, MediaPath = mediaPath, VersionId = entity.Version }; return(dto); }
public void Deal_With_Corrupt_Duplicate_Newest_Published_Flags_Slim_Model() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); ContentTypeRepository contentTypeRepository; IContent content1; using (var repository = CreateContentRepository(unitOfWork, out contentTypeRepository)) { var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage"); content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType); contentTypeRepository.AddOrUpdate(hasPropertiesContentType); repository.AddOrUpdate(content1); unitOfWork.Commit(); } //Now manually corrupt the data var versions = new[] { Guid.NewGuid(), Guid.NewGuid() }; for (var index = 0; index < versions.Length; index++) { var version = versions[index]; var versionDate = DateTime.Now.AddMinutes(index); var versionDto = new ContentVersionDto { NodeId = content1.Id, VersionDate = versionDate, VersionId = version }; this.DatabaseContext.Database.Insert(versionDto); this.DatabaseContext.Database.Insert(new DocumentDto { Newest = true, NodeId = content1.Id, Published = true, Text = content1.Name, VersionId = version, WriterUserId = 0, UpdateDate = versionDate, TemplateId = content1.Template == null || content1.Template.Id <= 0 ? null : (int?)content1.Template.Id }); } // Assert using (var repository = new EntityRepository(unitOfWork)) { var content = repository.GetByQuery(new Query <IUmbracoEntity>().Where(c => c.Id == content1.Id)).ToArray(); Assert.AreEqual(1, content.Length); var contentItem = repository.Get(content[0].Id); Assert.IsNotNull(contentItem); contentItem = repository.GetByKey(content[0].Key); Assert.IsNotNull(contentItem); } }
/// <summary> /// Builds an IContent item from a dto and content type. /// </summary> public static Content BuildEntity(DocumentDto dto, IContentType?contentType) { ContentDto contentDto = dto.ContentDto; NodeDto nodeDto = contentDto.NodeDto; DocumentVersionDto documentVersionDto = dto.DocumentVersionDto; ContentVersionDto contentVersionDto = documentVersionDto.ContentVersionDto; DocumentVersionDto?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(); } }
public ContentVersionDto BuildDto(IMedia entity) { var dto = new ContentVersionDto { NodeId = entity.Id, VersionDate = entity.UpdateDate, VersionId = entity.Version, ContentDto = BuildContentDto(entity) }; return(dto); }
private ContentVersionDto BuildDto(Member entity) { var dto = new ContentVersionDto { NodeId = entity.Id, VersionDate = entity.UpdateDate, VersionId = entity.Version, ContentDto = BuildContentDto(entity) }; return(dto); }
/// <summary> /// Private method to create a media object from a ContentDto /// </summary> /// <param name="d"></param> /// <param name="contentType"></param> /// <param name="propCollection"></param> /// <returns></returns> private IMedia CreateMediaFromDto(ContentVersionDto dto, IMediaType contentType, PropertyCollection propCollection) { var factory = new MediaFactory(contentType, NodeObjectTypeId, dto.NodeId); var media = factory.BuildEntity(dto); media.Properties = propCollection; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((Entity)media).ResetDirtyProperties(false); return(media); }
private ContentVersionDto BuildContentVersionDto(IContent entity) { //TODO: Change this once the Language property is public on IContent var content = entity as Content; var lang = content == null ? string.Empty : content.Language; var contentVersionDto = new ContentVersionDto { NodeId = entity.Id, VersionDate = entity.UpdateDate, VersionId = entity.Version, ContentDto = BuildContentDto(entity) }; return(contentVersionDto); }
// 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); }
/// <summary> /// Private method to create a media object from a ContentDto /// </summary> /// <param name="dto"></param> /// <param name="docSql"></param> /// <returns></returns> private IMedia CreateMediaFromDto(ContentVersionDto dto, Sql docSql) { var contentType = _mediaTypeRepository.Get(dto.ContentDto.ContentTypeId); var media = MediaFactory.BuildEntity(dto, contentType); var docDef = new DocumentDefinition(dto, contentType); var properties = GetPropertyCollection(new PagingSqlQuery(docSql), new[] { docDef }); media.Properties = properties[dto.VersionId]; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((Entity)media).ResetDirtyProperties(false); return(media); }
/// <summary> /// Builds an IMedia item from a dto and content type. /// </summary> public static Member BuildEntity(MemberDto dto, IMemberType?contentType) { NodeDto nodeDto = dto.ContentDto.NodeDto; ContentVersionDto contentVersionDto = dto.ContentVersionDto; var content = new Member(nodeDto.Text, dto.Email, dto.LoginName, dto.Password, contentType); try { content.DisableChangeTracking(); content.Id = dto.NodeId; content.SecurityStamp = dto.SecurityStampToken; content.EmailConfirmedDate = dto.EmailConfirmedDate; content.PasswordConfiguration = dto.PasswordConfig; 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; content.FailedPasswordAttempts = dto.FailedPasswordAttempts ?? default; content.IsLockedOut = dto.IsLockedOut; content.IsApproved = dto.IsApproved; content.LastLoginDate = dto.LastLoginDate; content.LastLockoutDate = dto.LastLockoutDate; content.LastPasswordChangeDate = dto.LastPasswordChangeDate; // reset dirty initial properties (U4-1946) content.ResetDirtyProperties(false); return(content); } finally { content.EnableChangeTracking(); } }
/// <summary> /// Private method to create a media object from a ContentDto /// </summary> /// <param name="d"></param> /// <param name="versionId"></param> /// <param name="docSql"></param> /// <returns></returns> private IMedia CreateMediaFromDto(ContentVersionDto dto, Guid versionId, Sql docSql) { var contentType = _mediaTypeRepository.Get(dto.ContentDto.ContentTypeId); var factory = new MediaFactory(contentType, NodeObjectTypeId, dto.NodeId); var media = factory.BuildEntity(dto); var docDef = new DocumentDefinition(dto.NodeId, versionId, media.UpdateDate, media.CreateDate, contentType); var properties = GetPropertyCollection(docSql, new[] { docDef }); media.Properties = properties[dto.NodeId]; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 ((Entity)media).ResetDirtyProperties(false); return(media); }
public IMedia BuildEntity(ContentVersionDto dto) { var media = new Models.Media(dto.ContentDto.NodeDto.Text, dto.ContentDto.NodeDto.ParentId, _contentType) { Id = _id, Key = dto.ContentDto.NodeDto.UniqueId, Path = dto.ContentDto.NodeDto.Path, CreatorId = dto.ContentDto.NodeDto.UserId.Value, Level = dto.ContentDto.NodeDto.Level, ParentId = dto.ContentDto.NodeDto.ParentId, SortOrder = dto.ContentDto.NodeDto.SortOrder, Trashed = dto.ContentDto.NodeDto.Trashed, CreateDate = dto.ContentDto.NodeDto.CreateDate, UpdateDate = dto.VersionDate, Version = dto.VersionId }; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 media.ResetDirtyProperties(false); return(media); }
/// <summary> /// Builds an IMedia item from a dto and content type. /// </summary> public static Core.Models.Media BuildEntity(ContentDto dto, IMediaType?contentType) { NodeDto nodeDto = dto.NodeDto; ContentVersionDto contentVersionDto = dto.ContentVersionDto; var content = new Core.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(); } }
protected override void PersistNewItem(IMember entity) { entity.AddingEntity(); // ensure security stamp if missing if (entity.SecurityStamp.IsNullOrWhiteSpace()) { entity.SecurityStamp = Guid.NewGuid().ToString(); } // ensure that strings don't contain characters that are invalid in xml // TODO: do we really want to keep doing this here? entity.SanitizeEntityPropertiesForXmlStorage(); // create the dto MemberDto memberDto = ContentBaseFactory.BuildDto(entity); // check if we have a user config else use the default memberDto.PasswordConfig = entity.PasswordConfiguration ?? DefaultPasswordConfigJson; // derive path and level from parent NodeDto parent = GetParentNodeDto(entity.ParentId); var level = parent.Level + 1; // get sort order var sortOrder = GetNewChildSortOrder(entity.ParentId, 0); // persist the node dto NodeDto nodeDto = memberDto.ContentDto.NodeDto; nodeDto.Path = parent.Path; nodeDto.Level = Convert.ToInt16(level); nodeDto.SortOrder = sortOrder; // see if there's a reserved identifier for this unique id // and then either update or insert the node dto var id = GetReservedId(nodeDto.UniqueId); if (id > 0) { nodeDto.NodeId = id; nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId); nodeDto.ValidatePathWithException(); Database.Update(nodeDto); } else { Database.Insert(nodeDto); // update path, now that we have an id nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId); nodeDto.ValidatePathWithException(); Database.Update(nodeDto); } // update entity entity.Id = nodeDto.NodeId; entity.Path = nodeDto.Path; entity.SortOrder = sortOrder; entity.Level = level; // persist the content dto ContentDto contentDto = memberDto.ContentDto; contentDto.NodeId = nodeDto.NodeId; Database.Insert(contentDto); // persist the content version dto // assumes a new version id and version date (modified date) has been set ContentVersionDto contentVersionDto = memberDto.ContentVersionDto; contentVersionDto.NodeId = nodeDto.NodeId; contentVersionDto.Current = true; Database.Insert(contentVersionDto); entity.VersionId = contentVersionDto.Id; // persist the member dto memberDto.NodeId = nodeDto.NodeId; // if the password is empty, generate one with the special prefix // this will hash the guid with a salt so should be nicely random if (entity.RawPasswordValue.IsNullOrWhiteSpace()) { memberDto.Password = Constants.Security.EmptyPasswordPrefix + _passwordHasher.HashPassword(Guid.NewGuid().ToString("N")); entity.RawPasswordValue = memberDto.Password; } Database.Insert(memberDto); // persist the property data InsertPropertyValues(entity, 0, out _, out _); SetEntityTags(entity, _tagRepository, _jsonSerializer); PersistRelations(entity); OnUowRefreshedEntity(new MemberRefreshNotification(entity, new EventMessages())); entity.ResetDirtyProperties(); }
public DocumentDefinition(ContentVersionDto dto, IContentTypeComposition composition) { ContentVersionDto = dto; Composition = composition; }
protected override void PersistNewItem(IMedia entity) { entity.AddingEntity(); // ensure unique name on the same level entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name) !; // ensure that strings don't contain characters that are invalid in xml // TODO: do we really want to keep doing this here? entity.SanitizeEntityPropertiesForXmlStorage(); // create the dto MediaDto dto = ContentBaseFactory.BuildDto(_mediaUrlGenerators, entity); // derive path and level from parent NodeDto parent = GetParentNodeDto(entity.ParentId); var level = parent.Level + 1; // get sort order var sortOrder = GetNewChildSortOrder(entity.ParentId, 0); // persist the node dto NodeDto nodeDto = dto.ContentDto.NodeDto; nodeDto.Path = parent.Path; nodeDto.Level = Convert.ToInt16(level); nodeDto.SortOrder = sortOrder; // see if there's a reserved identifier for this unique id // and then either update or insert the node dto var id = GetReservedId(nodeDto.UniqueId); if (id > 0) { nodeDto.NodeId = id; } else { Database.Insert(nodeDto); } nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId); nodeDto.ValidatePathWithException(); Database.Update(nodeDto); // update entity entity.Id = nodeDto.NodeId; entity.Path = nodeDto.Path; entity.SortOrder = sortOrder; entity.Level = level; // persist the content dto ContentDto contentDto = dto.ContentDto; contentDto.NodeId = nodeDto.NodeId; Database.Insert(contentDto); // persist the content version dto // assumes a new version id and version date (modified date) has been set ContentVersionDto contentVersionDto = dto.MediaVersionDto.ContentVersionDto; contentVersionDto.NodeId = nodeDto.NodeId; contentVersionDto.Current = true; Database.Insert(contentVersionDto); entity.VersionId = contentVersionDto.Id; // persist the media version dto MediaVersionDto mediaVersionDto = dto.MediaVersionDto; mediaVersionDto.Id = entity.VersionId; Database.Insert(mediaVersionDto); // persist the property data InsertPropertyValues(entity, 0, out _, out _); // set tags SetEntityTags(entity, _tagRepository, _serializer); PersistRelations(entity); OnUowRefreshedEntity(new MediaRefreshNotification(entity, new EventMessages())); entity.ResetDirtyProperties(); }
protected override void PersistUpdatedItem(IMedia entity) { // update entity.UpdatingEntity(); // Check if this entity is being moved as a descendant as part of a bulk moving operations. // In this case we can bypass a lot of the below operations which will make this whole operation go much faster. // When moving we don't need to create new versions, etc... because we cannot roll this operation back anyways. var isMoving = entity.IsMoving(); if (!isMoving) { // ensure unique name on the same level entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name, entity.Id) !; // ensure that strings don't contain characters that are invalid in xml // TODO: do we really want to keep doing this here? entity.SanitizeEntityPropertiesForXmlStorage(); // if parent has changed, get path, level and sort order if (entity.IsPropertyDirty(nameof(entity.ParentId))) { NodeDto parent = GetParentNodeDto(entity.ParentId); entity.Path = string.Concat(parent.Path, ",", entity.Id); entity.Level = parent.Level + 1; entity.SortOrder = GetNewChildSortOrder(entity.ParentId, 0); } } // create the dto MediaDto dto = ContentBaseFactory.BuildDto(_mediaUrlGenerators, entity); // update the node dto NodeDto nodeDto = dto.ContentDto.NodeDto; nodeDto.ValidatePathWithException(); Database.Update(nodeDto); if (!isMoving) { // update the content dto Database.Update(dto.ContentDto); // update the content & media version dtos ContentVersionDto contentVersionDto = dto.MediaVersionDto.ContentVersionDto; MediaVersionDto mediaVersionDto = dto.MediaVersionDto; contentVersionDto.Current = true; Database.Update(contentVersionDto); Database.Update(mediaVersionDto); // replace the property data ReplacePropertyValues(entity, entity.VersionId, 0, out _, out _); SetEntityTags(entity, _tagRepository, _serializer); PersistRelations(entity); } OnUowRefreshedEntity(new MediaRefreshNotification(entity, new EventMessages())); entity.ResetDirtyProperties(); }
public IMedia BuildEntity(ContentVersionDto dto) { return(BuildEntity(dto, _contentType)); }