Skip to content

Commit

Permalink
Recheck all child items when a folder is saved (renamed) #26
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Jun 10, 2019
1 parent 752564a commit 3de8fe7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ protected override void InitializeEvents(HandlerSettings settings)
ContentTypeService.Saved += EventSavedItem;
ContentTypeService.Deleted += EventDeletedItem;
ContentTypeService.Moved += EventMovedItem;
}

ContentTypeService.SavedContainer += EventContainerSaved;
}

protected override string GetItemFileName(IUmbracoEntity item, bool useGuid)
{
Expand Down
4 changes: 3 additions & 1 deletion uSync8.BackOffice/SyncHandlers/Handlers/DataTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ protected override void InitializeEvents(HandlerSettings settings)
{
DataTypeService.Saved += EventSavedItem;
DataTypeService.Deleted += EventDeletedItem;
DataTypeService.Moved += EventMovedItem; ;
DataTypeService.Moved += EventMovedItem;

DataTypeService.SavedContainer += EventContainerSaved;
}

protected override string GetItemFileName(IUmbracoEntity item, bool useGuid)
Expand Down
2 changes: 2 additions & 0 deletions uSync8.BackOffice/SyncHandlers/Handlers/MediaTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected override void InitializeEvents(HandlerSettings settings)
MediaTypeService.Saved += EventSavedItem;
MediaTypeService.Deleted += EventDeletedItem;
MediaTypeService.Moved += EventMovedItem;

MediaTypeService.SavingContainer += EventContainerSaved;
}

protected override string GetItemFileName(IUmbracoEntity item, bool useGuid)
Expand Down
2 changes: 2 additions & 0 deletions uSync8.BackOffice/SyncHandlers/Handlers/MemberTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ protected override void InitializeEvents(HandlerSettings settings)
MemberTypeService.Saved += EventSavedItem;
MemberTypeService.Deleted += EventDeletedItem;
MemberTypeService.Moved += EventMovedItem;

MemberTypeService.SavedContainer += EventContainerSaved;
}

protected override void DeleteFolder(int id)
Expand Down
48 changes: 47 additions & 1 deletion uSync8.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
Expand Down Expand Up @@ -41,7 +43,6 @@ protected SyncHandlerContainerBase(IEntityService entityService, IProfilingLogge
protected IEnumerable<uSyncAction> CleanFolders(string folder, int parent)
{
var actions = new List<uSyncAction>();

var folders = entityService.GetChildren(parent, this.itemContainerType);
foreach (var fdlr in folders)
{
Expand All @@ -67,5 +68,50 @@ public virtual IEnumerable<uSyncAction> ProcessPostImport(string folder, IEnumer
return CleanFolders(folder, -1);
}

/// <summary>
/// will resave everything in a folder (and beneath)
/// we need to this when it's renamed
/// </summary>
/// <param name="folderId"></param>
/// <param name="folder"></param>
/// <param name="config"></param>
/// <returns></returns>
protected IEnumerable<uSyncAction> UpdateFolder(int folderId, string folder, HandlerSettings config)
{
var actions = new List<uSyncAction>();
var folders = entityService.GetChildren(folderId, this.itemContainerType);
foreach (var fdlr in folders)
{
actions.AddRange(UpdateFolder(fdlr.Id, folder, config));
}

var items = entityService.GetChildren(folderId, this.itemObjectType);
foreach(var item in items)
{
var obj = GetFromService(item.Id);
if (obj != null)
{
var attempt = Export(obj, folder, config);
if (attempt.Success)
{
CleanUp(obj, attempt.FileName, folder);
}
actions.Add(attempt);
}
}

return actions;

}

protected void EventContainerSaved(IService service, SaveEventArgs<EntityContainer> e)
{
if (uSync8BackOffice.eventsPaused) return;

foreach(var folder in e.SavedEntities)
{
UpdateFolder(folder.Id, Path.Combine(rootFolder, this.DefaultFolder), DefaultConfig);
}
}
}
}
2 changes: 1 addition & 1 deletion uSync8.BackOffice/uSyncBackofficeComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Initialize()
{
ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;

if (runtimeState.Level <= RuntimeLevel.Run)
if (runtimeState.Level < RuntimeLevel.Run)
{
logger.Info<uSyncBackofficeComponent>("Umbraco is not in Run Mode {0} so uSync is not going to run", runtimeState.Level);
return;
Expand Down

0 comments on commit 3de8fe7

Please sign in to comment.