Skip to content

Commit

Permalink
Indexed node updated on any parent movement in the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
bkapustik committed Oct 5, 2023
1 parent 3d4343f commit 024e13f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/AlgoliaSearchModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Configuration;

using System.Linq;
using Algolia.Search.Clients;

using CMS.Base;
Expand Down Expand Up @@ -60,6 +60,7 @@ protected override void OnInit()

DocumentEvents.Delete.Before += HandleDocumentEvent;
DocumentEvents.Update.Before += HandleDocumentEvent;
DocumentEvents.Update.Before += ForceMoveUpdate;
DocumentEvents.Insert.After += HandleDocumentEvent;
WorkflowEvents.Publish.After += HandleWorkflowEvent;
WorkflowEvents.Archive.After += HandleWorkflowEvent;
Expand Down Expand Up @@ -104,5 +105,19 @@ private void HandleDocumentEvent(object sender, DocumentEventArgs e)

algoliaTaskLogger.HandleEvent(e.Node, e.CurrentHandler.Name);
}

private void ForceMoveUpdate(object sender, DocumentEventArgs e)
{
var columns = e.Node.ChangedColumns();
if (columns.Any(col => col.Equals(nameof(TreeNode.NodeParentID), System.StringComparison.OrdinalIgnoreCase)))
{
algoliaTaskLogger.HandleEvent(e.Node, WorkflowEvents.Publish.Name);

foreach (var child in e.Node.AllChildren)
{
algoliaTaskLogger.HandleEvent(child, WorkflowEvents.Publish.Name);
}
}
}
}
}
3 changes: 1 addition & 2 deletions src/Services/Implementations/DefaultAlgoliaTaskLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ public void HandleEvent(TreeNode node, string eventName)
}
}


private AlgoliaTaskType GetTaskType(TreeNode node, string eventName)
{
if (eventName.Equals(DocumentEvents.Insert.Name, StringComparison.OrdinalIgnoreCase) ||
(eventName.Equals(WorkflowEvents.Publish.Name, StringComparison.OrdinalIgnoreCase) && node.WorkflowHistory.Count == 0))
(eventName.Equals(WorkflowEvents.Publish.Name, StringComparison.OrdinalIgnoreCase) && (node.WorkflowHistory == null || node.WorkflowHistory.Count == 0)))
{
return AlgoliaTaskType.CREATE;
}
Expand Down

0 comments on commit 024e13f

Please sign in to comment.