From 360c324511829bfdb03aaab0053a5e8b5e48bcc9 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 23 Apr 2014 16:11:12 +1000 Subject: [PATCH] updates examine events for media to update media if it is moved to recycle bin --- src/Umbraco.Web/Search/ExamineEvents.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/Search/ExamineEvents.cs b/src/Umbraco.Web/Search/ExamineEvents.cs index 5886f51e77..9b058008f2 100644 --- a/src/Umbraco.Web/Search/ExamineEvents.cs +++ b/src/Umbraco.Web/Search/ExamineEvents.cs @@ -155,19 +155,33 @@ namespace Umbraco.Web.Search switch (payload.Operation) { case MediaCacheRefresher.OperationType.Saved: - var media = ApplicationContext.Current.Services.MediaService.GetById(payload.Id); - if (media != null) + var media1 = ApplicationContext.Current.Services.MediaService.GetById(payload.Id); + if (media1 != null) { - ReIndexForMedia(media, media.Trashed == false); + ReIndexForMedia(media1, media1.Trashed == false); } break; case MediaCacheRefresher.OperationType.Trashed: + //keep if trashed for indexes supporting unpublished + //(delete the index from all indexes not supporting unpublished content) + DeleteIndexForEntity(payload.Id, true); + + //We then need to re-index this item for all indexes supporting unpublished content + var media2 = ApplicationContext.Current.Services.MediaService.GetById(payload.Id); + if (media2 != null) + { + ReIndexForMedia(media2, false); + } + break; case MediaCacheRefresher.OperationType.Deleted: + //permanently remove from all indexes + DeleteIndexForEntity(payload.Id, false); + break; default: throw new ArgumentOutOfRangeException();