From ef164ed3ddadf4cbcc2f8eed84d5c5e64c7874b5 Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Mon, 9 Sep 2024 06:28:08 +0100 Subject: [PATCH] Merge v13.2.5 --- .../Services/SyncActionService.cs | 2 +- .../SyncHandlers/Handlers/MediaTypeHandler.cs | 2 +- .../Handlers/MemberTypeHandler.cs | 2 +- .../SyncHandlers/Handlers/TemplateHandler.cs | 23 ++++++++++++++++++- .../SyncHandlers/SyncHandlerBase.cs | 3 ++- .../SyncHandlers/SyncHandlerContainerBase.cs | 13 ++++++++++- .../SyncHandlers/SyncHandlerRoot.cs | 13 +++++++++-- .../uSyncBackOfficeBuilderExtensions.cs | 20 ++++++++-------- .../Serializers/DataTypeSerializer.cs | 2 +- .../Serializers/TemplateSerializer.cs | 12 ++++++++++ .../SyncContainerSerializerBase.cs | 14 +++++++++++ 11 files changed, 87 insertions(+), 19 deletions(-) diff --git a/uSync.BackOffice/Services/SyncActionService.cs b/uSync.BackOffice/Services/SyncActionService.cs index 2f5d1d72..f6c9a161 100644 --- a/uSync.BackOffice/Services/SyncActionService.cs +++ b/uSync.BackOffice/Services/SyncActionService.cs @@ -138,7 +138,7 @@ public SyncActionResult ImportPost(SyncActionOptions options, uSyncCallbacks? ca callbacks?.Update?.Invoke("Import Complete", 1, 1); - return new SyncActionResult(actions); + return new SyncActionResult(actions.Where(x => x.Change > Core.ChangeType.NoChange)); } public SyncActionResult ExportHandler(SyncActionOptions options, uSyncCallbacks? callbacks) diff --git a/uSync.BackOffice/SyncHandlers/Handlers/MediaTypeHandler.cs b/uSync.BackOffice/SyncHandlers/Handlers/MediaTypeHandler.cs index 3f15e16b..b6ed4177 100644 --- a/uSync.BackOffice/SyncHandlers/Handlers/MediaTypeHandler.cs +++ b/uSync.BackOffice/SyncHandlers/Handlers/MediaTypeHandler.cs @@ -24,7 +24,7 @@ namespace uSync.BackOffice.SyncHandlers.Handlers; /// [SyncHandler(uSyncConstants.Handlers.MediaTypeHandler, "Media Types", "MediaTypes", uSyncConstants.Priorites.MediaTypes, IsTwoPass = true, Icon = "icon-thumbnails", EntityType = UdiEntityType.MediaType)] -public class MediaTypeHandler : ContentTypeBaseHandler, ISyncHandler, ISyncGraphableHandler, +public class MediaTypeHandler : ContentTypeBaseHandler, ISyncHandler, ISyncPostImportHandler, ISyncGraphableHandler, INotificationHandler>, INotificationHandler>, INotificationHandler>, diff --git a/uSync.BackOffice/SyncHandlers/Handlers/MemberTypeHandler.cs b/uSync.BackOffice/SyncHandlers/Handlers/MemberTypeHandler.cs index fb96c823..1e0718b6 100644 --- a/uSync.BackOffice/SyncHandlers/Handlers/MemberTypeHandler.cs +++ b/uSync.BackOffice/SyncHandlers/Handlers/MemberTypeHandler.cs @@ -24,7 +24,7 @@ namespace uSync.BackOffice.SyncHandlers.Handlers; /// [SyncHandler(uSyncConstants.Handlers.MemberTypeHandler, "Member Types", "MemberTypes", uSyncConstants.Priorites.MemberTypes, IsTwoPass = true, Icon = "icon-users", EntityType = UdiEntityType.MemberType)] -public class MemberTypeHandler : ContentTypeBaseHandler, ISyncHandler, ISyncGraphableHandler, +public class MemberTypeHandler : ContentTypeBaseHandler, ISyncHandler, ISyncPostImportHandler, ISyncGraphableHandler, INotificationHandler>, INotificationHandler>, INotificationHandler>, diff --git a/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs b/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs index 85056daa..2e7a26b3 100644 --- a/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs +++ b/uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs @@ -15,6 +15,7 @@ using uSync.BackOffice.Configuration; using uSync.BackOffice.Services; using uSync.Core; +using uSync.Core.Serialization; using static Umbraco.Cms.Core.Constants; @@ -25,7 +26,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>, @@ -50,7 +51,27 @@ 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)) + { + if (action.FileName is null) continue; + + results.AddRange( + Import(action.FileName, config, SerializerFlags.LastPass)); + } + + return results; + } + /// protected override string GetItemName(ITemplate item) => item.Name ?? item.Alias; diff --git a/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs b/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs index 40f03a4e..95e9fc97 100644 --- a/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs +++ b/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs @@ -100,7 +100,8 @@ private int GetCleanParentId(string cleanFile) var node = syncFileService.LoadXElement(cleanFile); var id = node.Attribute("Id").ValueOrDefault(0); if (id != 0) return id; - return GetCleanParent(cleanFile)?.Id ?? 0; + return GetCleanParent(cleanFile)?.Id ?? + (node.GetKey() == Guid.Empty ? -1 : 0); } /// diff --git a/uSync.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs b/uSync.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs index fb8c789b..666935a9 100644 --- a/uSync.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs +++ b/uSync.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs @@ -121,7 +121,18 @@ public virtual IEnumerable ProcessPostImport(IEnumerable(); - return CleanFolders(-1); + var results = new List(); + + // we only do deletes here. + foreach (var action in actions.Where(x => x.Change == ChangeType.Hidden)) + { + if (action.FileName is null) continue; + results.AddRange(Import(action.FileName, config, SerializerFlags.LastPass)); + } + + results.AddRange(CleanFolders(-1)); + + return results; } /// diff --git a/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs b/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs index eb10a065..f4d662c9 100644 --- a/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs +++ b/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs @@ -1019,7 +1019,16 @@ public IEnumerable Export(Udi udi, string[] folders, HandlerSetting if (item != null) return Export(item, folders, settings); - return uSyncAction.Fail(nameof(udi), this.handlerType, this.ItemType, ChangeType.Fail, $"Item not found {udi}", + if (udi.IsRoot && settings.CreateClean) + { + // for roots we still can create a clean + var targetFolder = folders.Last(); + var filename = Path.Combine(targetFolder, $"{Guid.Empty}.{this.uSyncConfig.Settings.DefaultExtension}"); + CreateCleanFile(Guid.Empty, filename); + } + + + return uSyncAction.Fail(nameof(udi), this.handlerType, this.ItemType, ChangeType.Fail, $"Item not found {udi}", new KeyNotFoundException(nameof(udi))) .AsEnumerableOfOne(); } @@ -1170,7 +1179,7 @@ protected virtual bool HasChildren(TObject item) /// protected void CreateCleanFile(Guid key, string filename) { - if (string.IsNullOrWhiteSpace(filename) || key == Guid.Empty) + if (string.IsNullOrWhiteSpace(filename)) return; var folder = Path.GetDirectoryName(filename); diff --git a/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs b/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs index dff53518..d419ff41 100644 --- a/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs +++ b/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs @@ -163,11 +163,11 @@ internal static void AddHandlerNotifications(this IUmbracoBuilder builder) builder.AddNotificationHandler(); builder.AddNotificationHandler(); - // roots - pre-notifications for stopping things - builder - .AddNotificationHandler() - .AddNotificationHandler() - .AddNotificationHandler() + // roots - pre-notifications for stopping things + builder + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() @@ -196,11 +196,11 @@ internal static void AddHandlerNotifications(this IUmbracoBuilder builder) .AddNotificationHandler() - .AddNotificationHandler() - .AddNotificationHandler() - - .AddNotificationHandler() - .AddNotificationHandler(); + .AddNotificationHandler() + .AddNotificationHandler() + + .AddNotificationHandler() + .AddNotificationHandler(); // content ones diff --git a/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs b/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs index f14c3322..aa5cfaa4 100644 --- a/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs +++ b/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs @@ -64,7 +64,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 8c00a176..1939a2d5 100644 --- a/uSync.Core/Serialization/Serializers/TemplateSerializer.cs +++ b/uSync.Core/Serialization/Serializers/TemplateSerializer.cs @@ -44,6 +44,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(); diff --git a/uSync.Core/Serialization/SyncContainerSerializerBase.cs b/uSync.Core/Serialization/SyncContainerSerializerBase.cs index 6d78a456..93331b15 100644 --- a/uSync.Core/Serialization/SyncContainerSerializerBase.cs +++ b/uSync.Core/Serialization/SyncContainerSerializerBase.cs @@ -9,6 +9,8 @@ using Umbraco.Cms.Core.Services; using Umbraco.Extensions; +using uSync.Core.Models; + namespace uSync.Core.Serialization; public abstract class SyncContainerSerializerBase @@ -23,6 +25,18 @@ public SyncContainerSerializerBase(IEntityService entityService, ILogger 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 Attempt FindOrCreate(XElement node) {