Skip to content

Commit

Permalink
Tidy content type serializer.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Dec 6, 2024
1 parent 230b847 commit 6a159b4
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions uSync.Core/Serialization/Serializers/ContentTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,20 @@ protected override void EnsureAliasCache()
protected override async Task<SyncAttempt<XElement>> SerializeCoreAsync(IContentType item, SyncSerializerOptions options)
{
var node = SerializeBase(item);
var info = SerializeInfo(item);

var history = SerializeCleanupHistory(item);
if (history != null) info.Add(history);
node.Add(await SerializeInfoAsync(item));
node.Add(await SerializeStructureAsync(item));
node.Add(await SerializePropertiesAsync(item));
node.Add(SerializeTabs(item));

return SyncAttempt<XElement>.Succeed(item.Name ?? item.Alias, node, typeof(IContentType), ChangeType.Export);
}

protected async Task<XElement> SerializeInfoAsync(IContentType item)
{
var info = SerializeInfo(item);

info.AddIfNotNull(SerializeCleanupHistory(item));

var parent = item.ContentTypeComposition.FirstOrDefault(x => x.Id == item.ParentId);
if (parent != null)
Expand All @@ -71,9 +81,7 @@ protected override async Task<SyncAttempt<XElement>> SerializeCoreAsync(IContent
}
else if (item.Level != 1)
{
var folderNode = await this.GetFolderNodeAsync(item);
if (folderNode != null)
info.Add(folderNode);
info.AddIfNotNull(await this.GetFolderNodeAsync(item));
}

// compositions ?
Expand All @@ -86,17 +94,9 @@ protected override async Task<SyncAttempt<XElement>> SerializeCoreAsync(IContent
: "";

info.Add(new XElement("DefaultTemplate", templateAlias));
info.AddIfNotNull(SerializeTemplates(item));

var templates = SerializeTemplates(item);
if (templates != null)
info.Add(templates);

node.Add(info);
node.Add(await SerializeStructureAsync(item));
node.Add(await SerializePropertiesAsync(item));
node.Add(SerializeTabs(item));

return SyncAttempt<XElement>.Succeed(item.Name ?? item.Alias, node, typeof(IContentType), ChangeType.Export);
return info;
}

protected override void SerializeExtraProperties(XElement node, IContentType item, IPropertyType property)
Expand Down Expand Up @@ -131,7 +131,6 @@ protected override async Task<SyncAttempt<IContentType>> DeserializeCoreAsync(XE

details.AddRange(await DeserializeBaseAsync(item, node));


// compositions
details.AddRange(await DeserializeCompositionsAsync(item, node));

Expand Down Expand Up @@ -185,7 +184,6 @@ public override async Task<SyncAttempt<IContentType>> DeserializeSecondPassAsync
var historyUpdated = historyChanges.Any(x => x.Change > ChangeDetailType.NoChange);
details.AddRange(historyChanges);


CleanTabAliases(item);

// clean tabs
Expand Down

0 comments on commit 6a159b4

Please sign in to comment.