Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 33 additions & 39 deletions uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,55 +1004,49 @@ protected void CleanTabAliases(TObject item)

protected IEnumerable<uSyncChange> CleanTabs(TObject item, XElement node, SyncSerializerOptions options)
{
if (options.DeleteItems())
{
var tabNode = node?.Element("Tabs");
if (tabNode == null) return [];
if (options.DeleteItems() is false) return [];

var newTabs = tabNode.Elements("Tab")
.Select(x => GetTabAliasFromTabGroup(x))
.ToList();
var tabNode = node?.Element("Tabs");
if (tabNode == null) return [];

var inheritedTabs = item.CompositionPropertyGroups.Select(x => x.Alias).ToList();
var newTabs = tabNode.Elements("Tab")
.Select(x => GetTabAliasFromTabGroup(x))
.ToList();

List<PropertyGroup> removals = [];
foreach (var tab in item.PropertyGroups)
{
// don't remove the inherited tabs
if (inheritedTabs.Contains(tab.Alias)) continue;
var inheritedTabs =
item.ContentTypeComposition
.SelectMany(c => c.CompositionPropertyGroups.Select(x => x.Alias))
.Distinct()
.ToList();

if (!newTabs.InvariantContains(tab.Alias))
{
removals.Add(tab);
}
}
PropertyGroup[] removals = item.PropertyGroups
.Where(x => x is not null
&& inheritedTabs.InvariantContains(x.Alias) is false // don't touch inherited tabs
&& newTabs.InvariantContains(x.Alias) is false) // only include tabs we don't have in the xml
.ToArray();

if (removals.Count > 0)
{
var changes = new List<uSyncChange>();
if (removals.Length == 0) return [];

foreach (var tab in removals)
{
if (tab.PropertyTypes?.Count > 0)
{
logger.LogWarning("Not removing {tab} as it still has properties {properties}", tab.Alias,
String.Join(",", tab.PropertyTypes.Select(x => x.Name)));
}
else
{
if (logger.IsEnabled(LogLevel.Information))
logger.LogInformation("Removing tab : {alias}", tab.Alias);

changes.Add(uSyncChange.Delete($"Tabs/{tab.Alias}", tab.Alias, tab.Alias));
item.PropertyGroups.Remove(tab);
}
}
var changes = new List<uSyncChange>();
foreach (var tab in removals)
{
if (tab.PropertyTypes?.Count > 0)
{
logger.LogWarning("Not removing {tab} as it still has properties {properties}", tab.Alias,
String.Join(",", tab.PropertyTypes.Select(x => x.Name)));
changes.Add(uSyncChange.Warning($"Tabs/{tab.Alias}", $"Tab: {tab.Alias}", $"Tab '{tab.Alias}' not removed because it still has properties: {String.Join(",", tab.PropertyTypes.Select(x => x.Name))}"));
}
else
{
if (logger.IsEnabled(LogLevel.Information))
logger.LogInformation("Removing tab : {alias}", tab.Alias);

return changes;
changes.Add(uSyncChange.Delete($"Tabs/{tab.Alias}", $"Tab {tab.Alias}", tab.Alias));
item.PropertyGroups.Remove(tab);
}
}

return [];
return changes;
}

protected async Task CleanFolderAsync(TObject item, XElement node)
Expand Down
Loading