Skip to content

Instantly share code, notes, and snippets.

@tomfulton
Last active March 18, 2019 16:02
Show Gist options
  • Save tomfulton/5624928 to your computer and use it in GitHub Desktop.
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
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