Skip to content

Commit

Permalink
fixes #656 moved deletes to the end (#657)
Browse files Browse the repository at this point in the history
also corrected a typo
  • Loading branch information
henryjump authored Aug 7, 2024
1 parent e6eeb99 commit a4aadc1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
22 changes: 20 additions & 2 deletions uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +25,7 @@ namespace uSync.BackOffice.SyncHandlers.Handlers
/// </summary>
[SyncHandler(uSyncConstants.Handlers.TemplateHandler, "Templates", "Templates", uSyncConstants.Priorites.Templates,
Icon = "icon-layout", EntityType = UdiEntityType.Template, IsTwoPass = true)]
public class TemplateHandler : SyncHandlerLevelBase<ITemplate, IFileService>, ISyncHandler,
public class TemplateHandler : SyncHandlerLevelBase<ITemplate, IFileService>, ISyncHandler, ISyncPostImportHandler,
INotificationHandler<SavedNotification<ITemplate>>,
INotificationHandler<DeletedNotification<ITemplate>>,
INotificationHandler<MovedNotification<ITemplate>>,
Expand All @@ -51,6 +51,24 @@ public TemplateHandler(
this.fileService = fileService;
}

/// <inheritdoc/>
public IEnumerable<uSyncAction> ProcessPostImport(string folder, IEnumerable<uSyncAction> actions, HandlerSettings config)
{
if (actions == null || !actions.Any())
return Enumerable.Empty<uSyncAction>();

var results = new List<uSyncAction>();

// 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;
}

/// <inheritdoc/>
protected override string GetItemName(ITemplate item) => item.Name;

Expand Down
2 changes: 1 addition & 1 deletion uSync.Core/Serialization/Serializers/DataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public DataTypeSerializer(IEntityService entityService, ILogger<DataTypeSerializ
/// this only works because we are keeping the track of
/// all the deletes and renames when they happen
/// and we can only reliably do that for items
/// that have ContainerTree's because they are not
/// that have ContainerTrees because they are not
/// real trees - but flat (each alias is unique)
/// </remarks>
protected override SyncAttempt<IDataType> ProcessDelete(Guid key, string alias, SerializerFlags flags)
Expand Down
12 changes: 12 additions & 0 deletions uSync.Core/Serialization/Serializers/TemplateSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public TemplateSerializer(
_capabilityChecker = capabilityChecker;
}

protected override SyncAttempt<ITemplate> 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<ITemplate>.Succeed(alias, ChangeType.Hidden);
}

protected override SyncAttempt<ITemplate> DeserializeCore(XElement node, SyncSerializerOptions options)
{
var key = node.GetKey();
Expand Down

0 comments on commit a4aadc1

Please sign in to comment.