Corrected Tags deletion

- When a content item is deleted, correctly delete tags if there are no other content items attached to it
- When searching for a non existing tag, don't display an error message and a null reference exception anymore

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-07-28 13:39:56 -07:00
parent dcda153286
commit 0ee57bdf6e
2 changed files with 10 additions and 3 deletions

View File

@@ -109,7 +109,6 @@ namespace Orchard.Tags.Controllers {
}
catch (Exception exception) {
_notifier.Error(T("Retrieving tagged items failed: " + exception.Message));
return RedirectToAction("Index");
}
}

View File

@@ -32,11 +32,19 @@ namespace Orchard.Tags.Handlers {
tagsContentItemsRepository.Flush();
TagsPart tagsPart = context.ContentItem.As<TagsPart>();
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);
}
});
}
}