Last active
March 18, 2019 16:02
-
-
Save tomfulton/5624928 to your computer and use it in GitHub Desktop.
Fix for deleted nodes remaining in the Examine index
TODO: Add same for Media
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Examine; | |
using Examine.Providers; | |
using Umbraco.Core; | |
using Umbraco.Web; | |
using umbraco.BusinessLogic; | |
using umbraco.businesslogic; | |
using umbraco.cms.businesslogic.media; | |
namespace YourSite | |
{ | |
/// <summary> | |
/// Workaround for Deleted Documents (move to trash) nodes not getting removed from Examine Index | |
/// </summary> | |
public class FixDeletedNodes : IApplicationEventHandler | |
{ | |
public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) | |
{ | |
Document.AfterMoveToTrash += Document_AfterMoveToTrash; | |
} | |
public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext) | |
{ | |
} | |
public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext) | |
{ | |
} | |
void Document_AfterMoveToTrash(Document sender, umbraco.cms.businesslogic.MoveToTrashEventArgs e) | |
{ | |
foreach (BaseIndexProvider indexer in ExamineManager.Instance.IndexProviderCollection) | |
{ | |
indexer.DeleteFromIndex(sender.Id.ToString()); | |
var children = sender.Children; | |
foreach (var Page in children) | |
{ | |
indexer.DeleteFromIndex(Page.Id.ToString()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment