Skip to content

Commit

Permalink
V12/data types renames deletes (#530) (#531) (#532)
Browse files Browse the repository at this point in the history
* WIP #511 - Experiments with moving datatype actions + improving tracking

* bigger comment - so we remember. #511

* Optimise the PostImport to only do the hidden "delete" actions #511
  • Loading branch information
KevinJump authored Aug 9, 2023
1 parent 81b6cf0 commit fdd34e7
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/////////

function showChange(change) {
return vm.showAll || (change !== 'NoChange' && change !== 'Removed');
return vm.showAll || (change !== 'NoChange' && change !== 'Removed' && change !== 'Hidden');
}

function hasFailedDetail(details) {
Expand Down Expand Up @@ -97,7 +97,7 @@
function countChanges(changes) {
var count = 0;
angular.forEach(changes, function (val, key) {
if (val.Change !== 'NoChange') {
if (val.Change !== 'NoChange' && val.Change !== 'Hidden') {
count++;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
function countChanges(changes) {
var count = 0;
angular.forEach(changes, function (val, key) {
if (val.Change !== 'NoChange') {
if (val.Change !== 'NoChange' && val.Change !== 'Hidden') {
count++;
}
});
Expand Down
2 changes: 1 addition & 1 deletion uSync8.BackOffice/Extensions/uSyncActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public static bool ContainsErrors(this IEnumerable<uSyncAction> actions)
/// count how many actions in this list are for changes
/// </summary>
public static int CountChanges(this IEnumerable<uSyncAction> actions)
=> actions.Count(x => x.Change > Core.ChangeType.NoChange);
=> actions.Count(x => x.Change > Core.ChangeType.NoChange && x.Change < Core.ChangeType.Hidden);
}
}
2 changes: 1 addition & 1 deletion uSync8.BackOffice/Services/uSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private IEnumerable<uSyncAction> PerformPostImport(string rootFolder, IEnumerabl
{
if (handlerPair.Handler is ISyncPostImportHandler postImportHandler)
{
var handlerActions = postImportActions.Where(x => x.ItemType == handlerPair.Handler.ItemType.Name);
var handlerActions = postImportActions.Where(x => x.HandlerAlias == handlerPair.Handler.Alias);

if (handlerActions.Any())
{
Expand Down
24 changes: 14 additions & 10 deletions uSync8.BackOffice/SyncHandlers/Handlers/DataTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace uSync8.BackOffice.SyncHandlers.Handlers
{
[SyncHandler("dataTypeHandler", "Datatypes", "DataTypes", uSyncBackOfficeConstants.Priorites.DataTypes,
Icon = "icon-autofill", EntityType = UdiEntityType.DataType)]
Icon = "icon-autofill", EntityType = UdiEntityType.DataType, IsTwoPass = true)]
public class DataTypeHandler : SyncHandlerContainerBase<IDataType, IDataTypeService>, ISyncExtendedHandler, ISyncPostImportHandler, ISyncItemHandler
{
private readonly IDataTypeService dataTypeService;
Expand Down Expand Up @@ -90,19 +90,23 @@ public override IEnumerable<uSyncAction> ProcessPostImport(string folder, IEnume
if (actions == null || !actions.Any())
return null;

var results = new List<uSyncAction>();

foreach (var action in actions)
{
var result = Import(action.FileName, config, SerializerFlags.None);
foreach (var attempt in result)
{
if (attempt.Success && attempt.Item is IDataType dataType)
{
ImportSecondPass(action.FileName, dataType, config, null);
}
}
results.AddRange(Import(action.FileName, config, SerializerFlags.LastPass));
//foreach (var attempt in result)
//{
// if (attempt.Success && attempt.Item is IDataType dataType)
// {
// ImportSecondPass(action.FileName, dataType, config, null);
// }
//}
}

return CleanFolders(folder, -1);
results.AddRange(CleanFolders(folder, -1));

return results;
}

protected override IDataType GetFromService(Guid key)
Expand Down
24 changes: 24 additions & 0 deletions uSync8.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;

using Umbraco.Core.Cache;
using Umbraco.Core.Events;
Expand All @@ -16,6 +17,8 @@
using uSync8.Core.Dependency;
using uSync8.Core.Serialization;
using uSync8.Core.Tracking;
using uSync8.Core.Extensions;
using Umbraco.Core;

namespace uSync8.BackOffice.SyncHandlers
{
Expand Down Expand Up @@ -160,5 +163,26 @@ protected void EventContainerSaved(IService service, SaveEventArgs<EntityContain
}
}
}

/// <summary>
/// Does this item match the one in a given xml file?
/// </summary>
/// <remarks>
/// container based tree's aren't really trees - as in things can't have the same
/// name inside a folder as something else that might be outside the folder.
///
/// this means when we are comparing files for clean up, we also want to check the
/// alias. so we check the key (in the base) and if doesn't match we check the alias.
///
/// under default setup none of this matters because the name of the item is the file
/// name so we find/overwrite it anyway,
///
/// but for guid / folder structured setups we need to do this compare.
/// </remarks>
protected override bool DoItemsMatch(XElement node, TObject item)
{
if (base.DoItemsMatch(node, item)) return true;
return node.GetAlias().InvariantEquals(GetItemAlias(item));
}
}
}
3 changes: 2 additions & 1 deletion uSync8.Core/ChangeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public enum ChangeType : int
Fail = 11,
ImportFail,
Mismatch,
ParentMissing
ParentMissing,
Hidden = 101
}

}
6 changes: 5 additions & 1 deletion uSync8.Core/Serialization/SerializerFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public enum SerializerFlags
OnePass = 2, // do this in one pass
DoNotSave = 4, // don't save
FailMissingParent = 8, // fail if the parent item is missing
CreateOnly = 16 // only create, if the item is already there we don't overwrite.
CreateOnly = 16, // only create, if the item is already there we don't overwrite.
FirstPast = 32, // this is the first pass, sometime we might not do stuff on first pass.
SecondPass = 64, // this is the second pass
LastPass = 128, // this is the last pass.

}
}
34 changes: 34 additions & 0 deletions uSync8.Core/Serialization/Serializers/DataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@ public DataTypeSerializer(IEntityService entityService, ILogger logger,
this.configurationSerializers = configurationSerializers;
}

/// <summary>
/// Process deletes
/// </summary>
/// <remarks>
/// datatypes are deleted late (in the last pass)
/// this means they are actually deleted at the very
/// end of the process.
///
/// In theory this should be fine,
///
/// any content types that may or may not use
/// datatypes we are about to delete will have
/// already been updated.
///
/// by moving the datatypes to the end we capture the
/// case where the datatype might have been replaced
/// in the content type, by not deleting first we
/// stop the triggering of any of Umbraco's delete
/// processes.
///
/// 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
/// real trees - but flat (each alias is unique)
/// </remarks>
protected override SyncAttempt<IDataType> ProcessDelete(Guid key, string alias, SerializerFlags flags)
{
if (flags.HasFlag(SerializerFlags.LastPass))
return base.ProcessDelete(key, alias, flags);

return SyncAttempt<IDataType>.Succeed(alias, ChangeType.Hidden);
}

protected override SyncAttempt<IDataType> DeserializeCore(XElement node, SyncSerializerOptions options)
{
var info = node.Element("Info");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/////////

function showChange(change) {
return vm.showAll || (change !== 'NoChange' && change !== 'Removed');
return vm.showAll || (change !== 'NoChange' && change !== 'Removed' && change !== 'Hidden');
}

function hasFailedDetail(details) {
Expand Down Expand Up @@ -97,7 +97,7 @@
function countChanges(changes) {
var count = 0;
angular.forEach(changes, function (val, key) {
if (val.Change !== 'NoChange') {
if (val.Change !== 'NoChange' && val.Change !== 'Hidden') {
count++;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
function countChanges(changes) {
var count = 0;
angular.forEach(changes, function (val, key) {
if (val.Change !== 'NoChange') {
if (val.Change !== 'NoChange' && val.Change !== 'Hidden') {
count++;
}
});
Expand Down
2 changes: 2 additions & 0 deletions uSync8.Website/uSync/v8/DataTypes/NewTypeA.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<Empty Key="53febe7f-f5bb-4541-a8a8-def98cd56dbb" Alias="NewTypeA" Change="Delete" Level="9999" />

0 comments on commit fdd34e7

Please sign in to comment.