diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs b/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs index 513414002..d1ea5c696 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Controllers/HomeController.cs @@ -109,7 +109,6 @@ namespace Orchard.Tags.Controllers { } catch (Exception exception) { - _notifier.Error(T("Retrieving tagged items failed: " + exception.Message)); return RedirectToAction("Index"); } } diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Handlers/TagsPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Tags/Handlers/TagsPartHandler.cs index 50ba44eee..206d2763d 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Handlers/TagsPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Handlers/TagsPartHandler.cs @@ -32,11 +32,19 @@ namespace Orchard.Tags.Handlers { tagsContentItemsRepository.Flush(); TagsPart tagsPart = context.ContentItem.As(); - foreach (var tag in tagsPart.CurrentTags) { - if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) { + + // delete orphan tags (for each tag, if there is no other contentItem than the one being deleted, it's an orphan) + foreach ( var tag in tagsPart.CurrentTags ) { + if ( tagsContentItemsRepository.Fetch(x => x.ContentItemId != context.ContentItem.Id).Count() == 0 ) { tagsRepository.Delete(tag); } } + + // delete tag links with this contentItem (tagsContentItems) + foreach ( var tagsContentItem in tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id) ) { + tagsContentItemsRepository.Delete(tagsContentItem); + } + }); } }