Ejemplo n.º 1
0
        private static MediaVersionDto BuildMediaVersionDto(PropertyEditorCollection propertyEditors, IMedia entity, ContentDto contentDto)
        {
            // try to get a path from the string being stored for media
            // TODO: only considering umbracoFile

            string path = null;

            if (entity.Properties.TryGetValue(Constants.Conventions.Media.File, out var property) &&
                propertyEditors.TryGet(property.PropertyType.PropertyEditorAlias, out var editor) &&
                editor is IDataEditorWithMediaPath dataEditor)
            {
                var value = property.GetValue();
                path = dataEditor.GetMediaPath(value);
            }

            var dto = new MediaVersionDto
            {
                Id   = entity.VersionId,
                Path = path,

                ContentVersionDto = BuildContentVersionDto(entity, contentDto)
            };

            return(dto);
        }
Ejemplo n.º 2
0
        private static MediaVersionDto BuildMediaVersionDto(IMedia entity, ContentDto contentDto)
        {
            // try to get a path from the string being stored for media
            // fixme - 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);
        }
Ejemplo n.º 3
0
        private static MediaVersionDto BuildMediaVersionDto(MediaUrlGeneratorCollection mediaUrlGenerators, IMedia entity, ContentDto contentDto)
        {
            // try to get a path from the string being stored for media
            // TODO: only considering umbracoFile

            string path = null;

            if (entity.Properties.TryGetValue(Cms.Core.Constants.Conventions.Media.File, out var property) &&
                mediaUrlGenerators.TryGetMediaPath(property.PropertyType.PropertyEditorAlias, property.GetValue(), out var mediaPath))
            {
                path = mediaPath;
            }

            var dto = new MediaVersionDto
            {
                Id   = entity.VersionId,
                Path = path,

                ContentVersionDto = BuildContentVersionDto(entity, contentDto)
            };

            return(dto);
        }
Ejemplo n.º 4
0
    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();
    }
Ejemplo n.º 5
0
    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();
    }