public static string UpdatePropertyTypesAndGroupsDo(Database database)
        {
            if (database != null)
            {
                //Fetch all PropertyTypes that belongs to a PropertyTypeGroup
                var propertyTypes  = database.Fetch <PropertyTypeDto>("WHERE propertyTypeGroupId > 0");
                var propertyGroups = database.Fetch <PropertyTypeGroupDto>("WHERE id > 0");

                foreach (var propertyType in propertyTypes)
                {
                    //Get the PropertyTypeGroup that the current PropertyType references
                    var parentPropertyTypeGroup = propertyGroups.FirstOrDefault(x => x.Id == propertyType.PropertyTypeGroupId);
                    if (parentPropertyTypeGroup != null)
                    {
                        //If the ContentType is the same on the PropertyType and the PropertyTypeGroup the group is valid and we skip to the next
                        if (parentPropertyTypeGroup.ContentTypeNodeId == propertyType.ContentTypeId)
                        {
                            continue;
                        }

                        //Check if the 'new' PropertyTypeGroup has already been created
                        var existingPropertyTypeGroup =
                            propertyGroups.FirstOrDefault(
                                x =>
                                x.ParentGroupId == parentPropertyTypeGroup.Id && x.Text == parentPropertyTypeGroup.Text &&
                                x.ContentTypeNodeId == propertyType.ContentTypeId);

                        //This should ensure that we don't create duplicate groups for a single ContentType
                        if (existingPropertyTypeGroup == null)
                        {
                            //Create a new PropertyTypeGroup that references the parent group that the PropertyType was referencing pre-6.0.1
                            var propertyGroup = new PropertyTypeGroupDto
                            {
                                ContentTypeNodeId = propertyType.ContentTypeId,
                                ParentGroupId     = parentPropertyTypeGroup.Id,
                                Text      = parentPropertyTypeGroup.Text,
                                SortOrder = parentPropertyTypeGroup.SortOrder
                            };

                            //Save the PropertyTypeGroup in the database and update the list of groups with this new group
                            int id = Convert.ToInt16(database.Insert(propertyGroup));
                            propertyGroup.Id = id;
                            propertyGroups.Add(propertyGroup);
                            //Update the reference to the new PropertyTypeGroup on the current PropertyType
                            propertyType.PropertyTypeGroupId = id;
                            database.Update(propertyType);
                        }
                        else
                        {
                            //Update the reference to the existing PropertyTypeGroup on the current PropertyType
                            propertyType.PropertyTypeGroupId = existingPropertyTypeGroup.Id;
                            database.Update(propertyType);
                        }
                    }
                }
            }

            return(string.Empty);
        }
 private PropertyGroup MapPropertyGroup(PropertyTypeGroupDto dto, bool isPublishing)
 {
     return(new PropertyGroup(new PropertyTypeCollection(isPublishing))
     {
         Id = dto.Id,
         Name = dto.Text,
         SortOrder = dto.SortOrder,
         Key = dto.UniqueId
     });
 }
 private PropertyGroup MapPropertyGroup(PropertyTypeGroupDto dto, bool isPublishing) =>
 new PropertyGroup(new PropertyTypeCollection(isPublishing))
 {
     Id        = dto.Id,
     Key       = dto.UniqueId,
     Type      = (PropertyGroupType)dto.Type,
     Name      = dto.Text,
     Alias     = dto.Alias,
     SortOrder = dto.SortOrder
 };
        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 PropertyTypeGroupDto Map(PropertyTypeGroupDto a, PropertyTypeDto p, DataTypeDto d)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (a == null)
            {
                return(current);
            }

            //Set the PropertyTypeDto's DataTypeDto object
            if (p.DataTypeId == d.DataTypeId)
            {
                p.DataTypeDto = d;
            }

            // Is this the same Group as the current one we're processing
            if (current != null && current.Id == a.Id)
            {
                // Yes, just add this PropertyType to the current Group's collection of PropertyTypes
                current.PropertyTypeDtos.Add(p);

                // Return null to indicate we're not done with this Group yet
                return(null);
            }

            // This is a different Group to the current one, or this is the
            // first time through and we don't have a Tab yet

            // Save the current Group
            var prev = current;

            // Setup the new current Group
            current = a;
            current.PropertyTypeDtos = new List <PropertyTypeDto>();
            current.PropertyTypeDtos.Add(p);

            // Return the now populated previous Tab (or null if first time through)
            return(prev);
        }
Beispiel #6
0
        internal PropertyTypeGroupDto BuildGroupDto(PropertyGroup propertyGroup)
        {
            var dto = new PropertyTypeGroupDto
            {
                ContentTypeNodeId = _id,
                SortOrder         = propertyGroup.SortOrder,
                Text = propertyGroup.Name
            };

            if (propertyGroup.ParentId.HasValue)
            {
                dto.ParentGroupId = propertyGroup.ParentId.Value;
            }

            if (propertyGroup.HasIdentity)
            {
                dto.Id = propertyGroup.Id;
            }

            dto.PropertyTypeDtos = propertyGroup.PropertyTypes.Select(propertyType => BuildPropertyTypeDto(propertyGroup.Id, propertyType)).ToList();

            return(dto);
        }
Beispiel #7
0
    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 (PropertyTypeGroupDto 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.Key       = groupDto.UniqueId;
                group.Type      = (PropertyGroupType)groupDto.Type;
                group.Name      = groupDto.Text;
                group.Alias     = groupDto.Alias;
                group.SortOrder = groupDto.SortOrder;

                group.PropertyTypes = new PropertyTypeCollection(isPublishing);

                // Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded
                IEnumerable <PropertyTypeDto> typeDtos = groupDto.PropertyTypeDtos?.Where(x => x.Id > 0) ??
                                                         Enumerable.Empty <PropertyTypeDto>();
                foreach (PropertyTypeDto typeDto in typeDtos)
                {
                    PropertyTypeGroupDto tempGroupDto = groupDto;
                    PropertyType         propertyType = propertyTypeCtor(
                        typeDto.DataTypeDto.EditorAlias,
                        typeDto.DataTypeDto.DbType.EnumParse <ValueStorageType>(true),
                        typeDto.Alias);

                    try
                    {
                        propertyType.DisableChangeTracking();

                        propertyType.Alias                   = typeDto.Alias ?? string.Empty;
                        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 ?? string.Empty;
                        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);
    }
Beispiel #8
0
 private PropertyGroup MapPropertyGroup(PropertyTypeGroupDto dto, bool isPublishing) =>
        public static string UpdatePropertyTypesAndGroupsDo(Database database)
        {
            if (database != null)
            {
                //Fetch all PropertyTypes that belongs to a PropertyTypeGroup
                //NOTE: We are writing the full query because we've added a column to the PropertyTypeDto in later versions so one of the columns
                // won't exist yet
                //NOTE: We're using dynamic to avoid having this migration fail due to the UniqueId column added in 7.3 (this column is not added
                // in the table yet and will make the mapping of done by Fetch fail when the actual type is used here).
                var propertyTypes = database.Fetch <dynamic>("SELECT * FROM cmsPropertyType WHERE propertyTypeGroupId > 0");

                var propertyGroups = database.Fetch <PropertyTypeGroupDto>("WHERE id > 0");

                foreach (var propertyType in propertyTypes)
                {
                    //Get the PropertyTypeGroup that the current PropertyType references
                    var parentPropertyTypeGroup = propertyGroups.FirstOrDefault(x => x.Id == propertyType.propertyTypeGroupId);
                    if (parentPropertyTypeGroup != null)
                    {
                        //If the ContentType is the same on the PropertyType and the PropertyTypeGroup the group is valid and we skip to the next
                        if (parentPropertyTypeGroup.ContentTypeNodeId == propertyType.contentTypeId)
                        {
                            continue;
                        }

                        //Check if the 'new' PropertyTypeGroup has already been created
                        var existingPropertyTypeGroup =
                            propertyGroups.FirstOrDefault(
                                x =>
                                x.ParentGroupId == parentPropertyTypeGroup.Id && x.Text == parentPropertyTypeGroup.Text &&
                                x.ContentTypeNodeId == propertyType.contentTypeId);

                        //This should ensure that we don't create duplicate groups for a single ContentType
                        if (existingPropertyTypeGroup == null)
                        {
                            //Create a new PropertyTypeGroup that references the parent group that the PropertyType was referencing pre-6.0.1
                            var propertyGroup = new PropertyTypeGroupDto
                            {
                                ContentTypeNodeId = propertyType.contentTypeId,
                                ParentGroupId     = parentPropertyTypeGroup.Id,
                                Text      = parentPropertyTypeGroup.Text,
                                SortOrder = parentPropertyTypeGroup.SortOrder
                            };

                            //Save the PropertyTypeGroup in the database and update the list of groups with this new group
                            int id = Convert.ToInt16(database.Insert(propertyGroup));
                            propertyGroup.Id = id;
                            propertyGroups.Add(propertyGroup);
                            //Update the reference to the new PropertyTypeGroup on the current PropertyType
                            propertyType.propertyTypeGroupId = id;
                            database.Update("cmsPropertyType", "id", propertyType);
                        }
                        else
                        {
                            //Update the reference to the existing PropertyTypeGroup on the current PropertyType
                            propertyType.propertyTypeGroupId = existingPropertyTypeGroup.Id;
                            database.Update("cmsPropertyType", "id", propertyType);
                        }
                    }
                }
            }
            return(string.Empty);
        }