From a4aadc10c1b59b5fdc1a9d05dbb1fd22ecb849c7 Mon Sep 17 00:00:00 2001 From: Henry Jump <140804846+henryjump@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:01:59 +0100 Subject: [PATCH] fixes #656 moved deletes to the end (#657) also corrected a typo --- .../SyncHandlers/Handlers/TemplateHandler.cs | 22 +++++++++++++++++-- .../Serializers/DataTypeSerializer.cs | 2 +- .../Serializers/TemplateSerializer.cs | 12 ++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs b/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs index b76f7aab..def71e1d 100644 --- a/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs +++ b/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs @@ -15,7 +15,7 @@ using uSync.BackOffice.Configuration; using uSync.BackOffice.Services; using uSync.Core; - +using uSync.Core.Serialization; using static Umbraco.Cms.Core.Constants; namespace uSync.BackOffice.SyncHandlers.Handlers @@ -25,7 +25,7 @@ namespace uSync.BackOffice.SyncHandlers.Handlers /// [SyncHandler(uSyncConstants.Handlers.TemplateHandler, "Templates", "Templates", uSyncConstants.Priorites.Templates, Icon = "icon-layout", EntityType = UdiEntityType.Template, IsTwoPass = true)] - public class TemplateHandler : SyncHandlerLevelBase, ISyncHandler, + public class TemplateHandler : SyncHandlerLevelBase, ISyncHandler, ISyncPostImportHandler, INotificationHandler>, INotificationHandler>, INotificationHandler>, @@ -51,6 +51,24 @@ public TemplateHandler( this.fileService = fileService; } + /// + public IEnumerable ProcessPostImport(string folder, IEnumerable actions, HandlerSettings config) + { + if (actions == null || !actions.Any()) + return Enumerable.Empty(); + + var results = new List(); + + // we only do deletes here. + foreach (var action in actions.Where(x => x.Change == ChangeType.Hidden)) + { + results.AddRange( + Import(action.FileName, config, SerializerFlags.LastPass)); + } + + return results; + } + /// protected override string GetItemName(ITemplate item) => item.Name; diff --git a/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs b/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs index bd6f4b2d..5a86e8de 100644 --- a/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs +++ b/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs @@ -75,7 +75,7 @@ public DataTypeSerializer(IEntityService entityService, ILogger protected override SyncAttempt ProcessDelete(Guid key, string alias, SerializerFlags flags) diff --git a/uSync.Core/Serialization/Serializers/TemplateSerializer.cs b/uSync.Core/Serialization/Serializers/TemplateSerializer.cs index f337e496..c2437c0b 100644 --- a/uSync.Core/Serialization/Serializers/TemplateSerializer.cs +++ b/uSync.Core/Serialization/Serializers/TemplateSerializer.cs @@ -57,6 +57,18 @@ public TemplateSerializer( _capabilityChecker = capabilityChecker; } + protected override SyncAttempt ProcessDelete(Guid key, string alias, SerializerFlags flags) + { + if (flags.HasFlag(SerializerFlags.LastPass)) + { + logger.LogDebug("Processing deletes as part of the last pass"); + return base.ProcessDelete(key, alias, flags); + } + + logger.LogDebug("Delete not processing as this is not the final pass"); + return SyncAttempt.Succeed(alias, ChangeType.Hidden); + } + protected override SyncAttempt DeserializeCore(XElement node, SyncSerializerOptions options) { var key = node.GetKey();