Merge pull request #8257 from umbraco/v8/feature/8256_Raise_an_event_when_deleting_a_document_type_to_its_dependents

If content type is deleted and other document types have a reference to it, raise an event
This commit is contained in:
Warren Buckley
2020-06-16 13:13:11 +00:00
committed by GitHub

View File

@@ -511,6 +511,16 @@ namespace Umbraco.Core.Services.Implement
// delete content
DeleteItemsOfTypes(descendantsAndSelf.Select(x => x.Id));
// Next find all other document types that have a reference to this content type
var referenceToAllowedContentTypes = GetAll().Where(q => q.AllowedContentTypes.Any(p=>p.Id.Value==item.Id));
foreach (var reference in referenceToAllowedContentTypes)
{
reference.AllowedContentTypes = reference.AllowedContentTypes.Where(p => p.Id.Value != item.Id);
var changedRef = new List<ContentTypeChange<TItem>>() { new ContentTypeChange<TItem>(reference, ContentTypeChangeTypes.RefreshMain) };
// Fire change event
OnChanged(scope, changedRef.ToEventArgs());
}
// finally delete the content type
// - recursively deletes all descendants
@@ -518,7 +528,7 @@ namespace Umbraco.Core.Services.Implement
// (contents of any descendant type have been deleted but
// contents of any composed (impacted) type remain but
// need to have their property data cleared)
Repository.Delete(item);
Repository.Delete(item);
//...
var changes = descendantsAndSelf.Select(x => new ContentTypeChange<TItem>(x, ContentTypeChangeTypes.Remove))