Skip to content

Commit

Permalink
Merge v13.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Sep 9, 2024
1 parent baa7a35 commit ef164ed
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 19 deletions.
2 changes: 1 addition & 1 deletion uSync.BackOffice/Services/SyncActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion uSync.BackOffice/SyncHandlers/Handlers/MediaTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace uSync.BackOffice.SyncHandlers.Handlers;
/// </summary>
[SyncHandler(uSyncConstants.Handlers.MediaTypeHandler, "Media Types", "MediaTypes", uSyncConstants.Priorites.MediaTypes,
IsTwoPass = true, Icon = "icon-thumbnails", EntityType = UdiEntityType.MediaType)]
public class MediaTypeHandler : ContentTypeBaseHandler<IMediaType, IMediaTypeService>, ISyncHandler, ISyncGraphableHandler,
public class MediaTypeHandler : ContentTypeBaseHandler<IMediaType, IMediaTypeService>, ISyncHandler, ISyncPostImportHandler, ISyncGraphableHandler,
INotificationHandler<SavedNotification<IMediaType>>,
INotificationHandler<DeletedNotification<IMediaType>>,
INotificationHandler<MovedNotification<IMediaType>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace uSync.BackOffice.SyncHandlers.Handlers;
/// </summary>
[SyncHandler(uSyncConstants.Handlers.MemberTypeHandler, "Member Types", "MemberTypes", uSyncConstants.Priorites.MemberTypes,
IsTwoPass = true, Icon = "icon-users", EntityType = UdiEntityType.MemberType)]
public class MemberTypeHandler : ContentTypeBaseHandler<IMemberType, IMemberTypeService>, ISyncHandler, ISyncGraphableHandler,
public class MemberTypeHandler : ContentTypeBaseHandler<IMemberType, IMemberTypeService>, ISyncHandler, ISyncPostImportHandler, ISyncGraphableHandler,
INotificationHandler<SavedNotification<IMemberType>>,
INotificationHandler<MovedNotification<IMemberType>>,
INotificationHandler<DeletedNotification<IMemberType>>,
Expand Down
23 changes: 22 additions & 1 deletion uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +26,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 @@ -50,7 +51,27 @@ 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))
{
if (action.FileName is null) continue;

results.AddRange(
Import(action.FileName, config, SerializerFlags.LastPass));
}

return results;
}

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

Expand Down
3 changes: 2 additions & 1 deletion uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
13 changes: 12 additions & 1 deletion uSync.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,18 @@ public virtual IEnumerable<uSyncAction> ProcessPostImport(IEnumerable<uSyncActio
if (actions == null || !actions.Any())
return Enumerable.Empty<uSyncAction>();

return CleanFolders(-1);
var results = new List<uSyncAction>();

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

/// <summary>
Expand Down
13 changes: 11 additions & 2 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,16 @@ public IEnumerable<uSyncAction> 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();
}
Expand Down Expand Up @@ -1170,7 +1179,7 @@ protected virtual bool HasChildren(TObject item)
/// </summary>
protected void CreateCleanFile(Guid key, string filename)
{
if (string.IsNullOrWhiteSpace(filename) || key == Guid.Empty)
if (string.IsNullOrWhiteSpace(filename))
return;

var folder = Path.GetDirectoryName(filename);
Expand Down
20 changes: 10 additions & 10 deletions uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ internal static void AddHandlerNotifications(this IUmbracoBuilder builder)
builder.AddNotificationHandler<WebhookSavedNotification, WebhookHandler>();
builder.AddNotificationHandler<WebhookDeletedNotification, WebhookHandler>();

// roots - pre-notifications for stopping things
builder
.AddNotificationHandler<ContentTypeSavingNotification, ContentTypeHandler>()
.AddNotificationHandler<ContentTypeDeletingNotification, ContentTypeHandler>()
.AddNotificationHandler<ContentTypeMovingNotification, ContentTypeHandler>()
// roots - pre-notifications for stopping things
builder
.AddNotificationHandler<ContentTypeSavingNotification, ContentTypeHandler>()
.AddNotificationHandler<ContentTypeDeletingNotification, ContentTypeHandler>()
.AddNotificationHandler<ContentTypeMovingNotification, ContentTypeHandler>()

.AddNotificationHandler<MediaTypeSavingNotification, MediaTypeHandler>()
.AddNotificationHandler<MediaTypeDeletingNotification, MediaTypeHandler>()
Expand Down Expand Up @@ -196,11 +196,11 @@ internal static void AddHandlerNotifications(this IUmbracoBuilder builder)
.AddNotificationHandler<RelationTypeDeletingNotification, RelationTypeHandler>()


.AddNotificationHandler<TemplateSavingNotification, TemplateHandler>()
.AddNotificationHandler<TemplateDeletingNotification, TemplateHandler>()
.AddNotificationHandler<WebhookSavingNotification, WebhookHandler>()
.AddNotificationHandler<WebhookDeletingNotification, WebhookHandler>();
.AddNotificationHandler<TemplateSavingNotification, TemplateHandler>()
.AddNotificationHandler<TemplateDeletingNotification, TemplateHandler>()

.AddNotificationHandler<WebhookSavingNotification, WebhookHandler>()
.AddNotificationHandler<WebhookDeletingNotification, WebhookHandler>();


// content ones
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 @@ -64,7 +64,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 @@ -44,6 +44,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
14 changes: 14 additions & 0 deletions uSync.Core/Serialization/SyncContainerSerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;

using uSync.Core.Models;

namespace uSync.Core.Serialization;

public abstract class SyncContainerSerializerBase<TObject>
Expand All @@ -23,6 +25,18 @@ public SyncContainerSerializerBase(IEntityService entityService, ILogger<SyncCon
this.containerType = containerType;
}

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

protected override Attempt<TObject?> FindOrCreate(XElement node)
{

Expand Down

0 comments on commit ef164ed

Please sign in to comment.