mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
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:
@@ -109,7 +109,6 @@ namespace Orchard.Tags.Controllers {
|
||||
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Retrieving tagged items failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user