mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Hooked up cascade delete for tags (not yet completed).
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045868
This commit is contained in:
@@ -26,11 +26,10 @@ namespace Orchard.Comments.Models {
|
|||||||
comments.PendingComments = commentsRepository.Fetch(x => x.CommentedOn == context.ContentItem.Id && x.Status == CommentStatus.Pending).ToList();
|
comments.PendingComments = commentsRepository.Fetch(x => x.CommentedOn == context.ContentItem.Id && x.Status == CommentStatus.Pending).ToList();
|
||||||
});
|
});
|
||||||
|
|
||||||
OnRemoved<HasComments>((context, c) => {
|
OnRemoved<HasComments>(
|
||||||
//TODO: (erikpo) Once comments are content items, replace the following repository delete call to a content manager remove call
|
(context, c) =>
|
||||||
var comments = commentService.GetCommentsForCommentedContent(context.ContentItem.Id).ToList();
|
commentService.GetCommentsForCommentedContent(context.ContentItem.Id).ToList().ForEach(
|
||||||
comments.ForEach(commentsRepository.Delete);
|
commentsRepository.Delete));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if false
|
#if false
|
||||||
|
|||||||
@@ -1,36 +1,37 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Data;
|
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Data;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
|
||||||
namespace Orchard.Tags.Models {
|
namespace Orchard.Tags.Models {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class HasTagsHandler : ContentHandler {
|
public class HasTagsHandler : ContentHandler {
|
||||||
private readonly IRepository<Tag> _tagsRepository;
|
|
||||||
private readonly IRepository<TagsContentItems> _tagsContentItemsRepository;
|
|
||||||
|
|
||||||
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) {
|
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) {
|
||||||
_tagsRepository = tagsRepository;
|
|
||||||
_tagsContentItemsRepository = tagsContentItemsRepository;
|
|
||||||
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
|
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
|
||||||
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
|
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
|
||||||
}
|
|
||||||
|
|
||||||
|
OnLoading<HasTags>((context, ht) => {
|
||||||
|
HasTags tags = context.ContentItem.As<HasTags>();
|
||||||
|
tags.AllTags = tagsRepository.Table.ToList();
|
||||||
|
IEnumerable<TagsContentItems> tagsContentItems = tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id);
|
||||||
|
foreach (var tagContentItem in tagsContentItems) {
|
||||||
|
Tag tag = tagsRepository.Get(tagContentItem.TagId);
|
||||||
|
tags.CurrentTags.Add(tag);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
protected override void Loading(LoadContentContext context) {
|
OnRemoved<HasTags>((context, ht) => {
|
||||||
if (context.ContentItem.Has<HasTags>() == false) {
|
tagsContentItemsRepository.Flush();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HasTags tags = context.ContentItem.Get<HasTags>();
|
HasTags tags = context.ContentItem.As<HasTags>();
|
||||||
tags.AllTags = _tagsRepository.Table.ToList();
|
foreach (var tag in tags.CurrentTags) {
|
||||||
IEnumerable<TagsContentItems> tagsContentItems = _tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id);
|
if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) {
|
||||||
foreach (var tagContentItem in tagsContentItems) {
|
tagsRepository.Delete(tag);
|
||||||
Tag tag = _tagsRepository.Get(tagContentItem.TagId);
|
}
|
||||||
tags.CurrentTags.Add(tag);
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,4 @@
|
|||||||
public virtual int Id { get; set; }
|
public virtual int Id { get; set; }
|
||||||
public virtual string TagName { get; set; }
|
public virtual string TagName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TagsContentItems {
|
|
||||||
public virtual int Id { get; set; }
|
|
||||||
public virtual int TagId { get; set; }
|
|
||||||
public virtual int ContentItemId { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Orchard.Tags.Models {
|
||||||
|
public class TagsContentItems {
|
||||||
|
public virtual int Id { get; set; }
|
||||||
|
public virtual int TagId { get; set; }
|
||||||
|
public virtual int ContentItemId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,6 +63,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AdminMenu.cs" />
|
<Compile Include="AdminMenu.cs" />
|
||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
|
<Compile Include="Models\TagsContentItems.cs" />
|
||||||
<Compile Include="ViewModels\EditTagsViewModel.cs" />
|
<Compile Include="ViewModels\EditTagsViewModel.cs" />
|
||||||
<Compile Include="Controllers\HomeController.cs" />
|
<Compile Include="Controllers\HomeController.cs" />
|
||||||
<Compile Include="Controllers\HasTagsDriver.cs" />
|
<Compile Include="Controllers\HasTagsDriver.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user