We have a multi-lingual site, where English is the "parent" and all others are copies of and related to the English parent. When we delete or unpublish a node in the English section, we'd like all the related nodes to also be affected.
Documentation for these (particularly unpublish) has been very difficult to find, so I'm turning to the forums.
I've tried the following, but nothing is happening when I do the actions.
For delete I have:
ContentService.Trashed += ContentService_Trashed;
void ContentService_Trashed(IContentService sender, MoveEventArgs<IContent> e)
{
var rs = ApplicationContext.Current.Services.RelationService;
var cs = ApplicationContext.Current.Services.ContentService;
// get the parent
foreach (var parentRelation in rs.GetByParentId(e.ParentId))
{
cs.MoveToRecycleBin(cs.GetById(parentRelation.ChildId));
}
}
For the unpublish, I have (this is actually unpublishing the related node's parent and I'm not sure why):
ContentService.UnPublished += ContentService_UnPublished;
void ContentService_UnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
var rs = ApplicationContext.Current.Services.RelationService;
var cs = ApplicationContext.Current.Services.ContentService;
// go through each document unpublished
foreach (var c in e.PublishedEntities)
{
// get the parent
foreach (var parentRelation in rs.GetByParentId(c.ParentId).Where(x => x.RelationType.Alias == RelationTypes.RelateDocumentOnCopy))
{
// copy the item if not already a relation
cs.UnPublish(cs.GetById(parentRelation.ChildId));
}
}
}
Did you ever get this figured out? I am trying to do something similar by automatically adding pages when a page is added in my English section. It is working, but I am getting multiple copies of pages added in some languages. I was wondering if you ever figured this out?
Deleting and Unpublishing related content nodes
We have a multi-lingual site, where English is the "parent" and all others are copies of and related to the English parent. When we delete or unpublish a node in the English section, we'd like all the related nodes to also be affected.
Documentation for these (particularly unpublish) has been very difficult to find, so I'm turning to the forums.
I've tried the following, but nothing is happening when I do the actions.
For delete I have:
For the unpublish, I have (this is actually unpublishing the related node's parent and I'm not sure why):
Did you ever get this figured out? I am trying to do something similar by automatically adding pages when a page is added in my English section. It is working, but I am getting multiple copies of pages added in some languages. I was wondering if you ever figured this out?
If you change your delete method to this it will work for you:
is working on a reply...