diff --git a/src/Umbraco.Core/Models/PropertyGroupCollection.cs b/src/Umbraco.Core/Models/PropertyGroupCollection.cs index 6e1847856b..3162634ceb 100644 --- a/src/Umbraco.Core/Models/PropertyGroupCollection.cs +++ b/src/Umbraco.Core/Models/PropertyGroupCollection.cs @@ -71,16 +71,30 @@ namespace Umbraco.Core.Models { using (new WriteLock(_addLocker)) { - var key = GetKeyForItem(item); - if (key != null) + //Note this is done to ensure existig groups can be renamed + if (item.HasIdentity && item.Id > 0) { - var exists = this.Contains(key); + var exists = this.Contains(item.Id); if (exists) { - SetItem(IndexOfKey(key), item); + SetItem(IndexOfKey(item.Id), item); return; } } + else + { + var key = GetKeyForItem(item); + if (key != null) + { + var exists = this.Contains(key); + if (exists) + { + SetItem(IndexOfKey(key), item); + return; + } + } + } + base.Add(item); OnAdd.IfNotNull(x => x.Invoke());//Could this not be replaced by a Mandate/Contract for ensuring item is not null @@ -99,6 +113,11 @@ namespace Umbraco.Core.Models return this.Any(x => x.Name == groupName); } + public bool Contains(int id) + { + return this.Any(x => x.Id == id); + } + public void RemoveItem(string propertyGroupName) { var key = IndexOfKey(propertyGroupName); @@ -119,6 +138,18 @@ namespace Umbraco.Core.Models return -1; } + public int IndexOfKey(int id) + { + for (var i = 0; i < this.Count; i++) + { + if (this[i].Id == id) + { + return i; + } + } + return -1; + } + protected override string GetKeyForItem(PropertyGroup item) { return item.Name; diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs index 2533fe62e8..81a7321cbe 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs @@ -298,8 +298,15 @@ AND umbracoNode.id <> @id", var dbPropertyGroups = Database.Fetch("WHERE contenttypeNodeId = @Id", new {Id = entity.Id}) .Select(x => new Tuple(x.Id, x.Text)); - var entityPropertyGroups = entity.PropertyGroups.Select(x => new Tuple(x.Id, x.Name)); + var entityPropertyGroups = entity.PropertyGroups.Select(x => new Tuple(x.Id, x.Name)).ToList(); var tabs = dbPropertyGroups.Except(entityPropertyGroups); + //Update Tab name downstream to ensure renaming is done properly + foreach (var propertyGroup in entityPropertyGroups) + { + Database.Update("SET Text = @TabName WHERE parentGroupId = @TabId", + new { TabId = propertyGroup.Item1, TabName = propertyGroup.Item2 }); + } + //Do Tab updates foreach (var tab in tabs) { Database.Update("SET propertyTypeGroupId = NULL WHERE propertyTypeGroupId = @PropertyGroupId",