Skip to content

Commit

Permalink
Move tab deletion to the end of the process #160
Browse files Browse the repository at this point in the history
Some change means the remving the tab also removes the properties - so
no we don't remove the tabs until we have gotten to the end of the
process.
  • Loading branch information
KevinJump committed Nov 16, 2017
1 parent db76350 commit 3497e01
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
22 changes: 20 additions & 2 deletions Jumoo.uSync.Core/Serializers/ContentTypeBaseSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,18 @@ internal string DeserializeProperties(IContentTypeBase item, XElement node)
var propKey = propertyNode.Element("Key").ValueOrDefault(Guid.Empty);
if (propKey != Guid.Empty)
{
LogHelper.Debug<ContentTypeSerializer>("Looking up Property Key: {0}", () => propKey);
property = item.PropertyTypes.SingleOrDefault(x => x.Key == propKey);



}

var alias = propertyNode.Element("Alias").ValueOrDefault(string.Empty);

if (property == null)
{
LogHelper.Debug<ContentTypeSerializer>("Looking up Property Alias: {0}", () => alias);
// look up via alias?
property = item.PropertyTypes.SingleOrDefault(x => x.Alias == alias);
}
Expand Down Expand Up @@ -416,22 +421,35 @@ internal void DeserializeTabSortOrder(IContentTypeBase item, XElement node)
}
}

}

internal void CleanUpTabs(IContentTypeBase item, XElement node)
{
LogHelper.Debug<Events>("Cleaning up Tabs");
var tabNode = node.Element("Tabs");

if (tabNode == null || !tabNode.HasElements)
return;

// remove tabs
List<string> tabsToRemove = new List<string>();
foreach(var tab in item.PropertyGroups)
foreach (var tab in item.PropertyGroups)
{
if (tabNode.Elements("Tab").FirstOrDefault(x => x.Element("Caption").Value == tab.Name) == null)
{
// no tab of this name in the import... remove it.
LogHelper.Debug<ContentTypeSerializer>("Removing Tab {0}", () => tab.Name);
tabsToRemove.Add(tab.Name);
}
}

foreach (var name in tabsToRemove)
{
item.PropertyGroups.Remove(name);
}
}

}

#endregion

#region ContentTypeBase Serialize Helpers
Expand Down
2 changes: 2 additions & 0 deletions Jumoo.uSync.Core/Serializers/ContentTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ internal override SyncAttempt<IContentType> DeserializeCore(XElement node)
item.SetDefaultTemplate(template);
}

CleanUpTabs((IContentTypeBase)item, node);

DeserializeTemplates(item, info);

_contentTypeService.Save(item);
Expand Down
2 changes: 2 additions & 0 deletions Jumoo.uSync.Core/Serializers/MediaTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ internal override SyncAttempt<IMediaType> DeserializeCore(XElement node)

var msg = DeserializeProperties(item, node);

CleanUpTabs(item, node);

// this really needs to happen in a seperate step.
// DeserializeStructure(item, node);

Expand Down
4 changes: 3 additions & 1 deletion Jumoo.uSync.Core/Serializers/MemberTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ internal override SyncAttempt<IMemberType> DeserializeCore(XElement node)

DeserializeBase(item, info);

DeserializeTabSortOrder(item, node);

var msg = DeserializeProperties(item, node);

DeserializeTabSortOrder(item, node);
CleanUpTabs(item, node);

_memberTypeService.Save(item);

Expand Down

0 comments on commit 3497e01

Please sign in to comment.