diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixZeroOne/UpdatePropertyTypesAndGroups.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixZeroOne/UpdatePropertyTypesAndGroups.cs index 6cc1013fb6..9984776cb3 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixZeroOne/UpdatePropertyTypesAndGroups.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixZeroOne/UpdatePropertyTypesAndGroups.cs @@ -22,30 +22,53 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSixZeroOne { if (database != null) { + //Fetch all PropertyTypes that belongs to a PropertyTypeGroup var propertyTypes = database.Fetch("WHERE propertyTypeGroupId > 0"); var propertyGroups = database.Fetch("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; - var propertyGroup = new PropertyTypeGroupDto - { - ContentTypeNodeId = propertyType.ContentTypeId, - ParentGroupId = parentPropertyTypeGroup.Id, - Text = parentPropertyTypeGroup.Text, - SortOrder = parentPropertyTypeGroup.SortOrder - }; + //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); - int id = Convert.ToInt16(database.Insert(propertyGroup)); - propertyGroup.Id = id; - propertyGroups.Add(propertyGroup); + //This should ensure that we don't create duplicate groups for a single ContentType + if (existingPropertyTypeGroup == null) + { - propertyType.PropertyTypeGroupId = id; - database.Update(propertyType); + //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); + } } } } diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs index 825898008e..c6281a44ff 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs @@ -80,7 +80,8 @@ namespace Umbraco.Core.Persistence.Repositories var translator = new SqlTranslator(sqlClause, query); var sql = translator.Translate() .Where(x => x.Newest) - .OrderByDescending(x => x.VersionDate); + .OrderByDescending(x => x.VersionDate) + .OrderBy(x => x.SortOrder); //NOTE: This doesn't allow properties to be part of the query var dtos = Database.Fetch(sql); diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs index 03bb6ceca3..e28e38efa1 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs @@ -93,7 +93,8 @@ namespace Umbraco.Core.Persistence.Repositories { var sqlClause = GetBaseQuery(false); var translator = new SqlTranslator(sqlClause, query); - var sql = translator.Translate(); + var sql = translator.Translate() + .OrderBy(x => x.Text); var dtos = Database.Fetch(sql); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadNodeTypes.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadNodeTypes.cs index 1dca0daa7d..1d39f1c847 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadNodeTypes.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadNodeTypes.cs @@ -58,7 +58,7 @@ function openNodeType(id) { public override void Render(ref XmlTree tree) { - var docTypes = Service.GetContentTypeChildren(base.m_id).OrderBy(x => x.Name); + var docTypes = Service.GetContentTypeChildren(base.m_id); foreach (var docType in docTypes) {