From 317363977ead57e8b3dd8dcc12ed07802fd54e3c Mon Sep 17 00:00:00 2001 From: Mole Date: Wed, 31 Mar 2021 09:46:05 +0200 Subject: [PATCH] Migrate Deleting/ed relation --- .../Services/Implement/RelationService.cs | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Implement/RelationService.cs b/src/Umbraco.Infrastructure/Services/Implement/RelationService.cs index 19fb68ae8c..5b8b00975c 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/RelationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/RelationService.cs @@ -5,8 +5,10 @@ using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; +using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Services.Notifications; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Services.Implement @@ -501,10 +503,11 @@ namespace Umbraco.Cms.Core.Services.Implement /// public void Delete(IRelation relation) { - using (var scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { - var deleteEventArgs = new DeleteEventArgs(relation); - if (scope.Events.DispatchCancelable(DeletingRelation, this, deleteEventArgs)) + EventMessages eventMessages = EventMessagesFactory.Get(); + var deletingNotification = new RelationDeletingNotification(relation, eventMessages); + if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); return; @@ -512,8 +515,7 @@ namespace Umbraco.Cms.Core.Services.Implement _relationRepository.Delete(relation); scope.Complete(); - deleteEventArgs.CanCancel = false; - scope.Events.Dispatch(DeletedRelation, this, deleteEventArgs); + scope.Notifications.Publish(new RelationDeletedNotification(relation, eventMessages).WithStateFrom(deletingNotification)); } } @@ -540,19 +542,21 @@ namespace Umbraco.Cms.Core.Services.Implement public void DeleteRelationsOfType(IRelationType relationType) { var relations = new List(); - using (var scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { - var query = Query().Where(x => x.RelationTypeId == relationType.Id); + IQuery query = Query().Where(x => x.RelationTypeId == relationType.Id); relations.AddRange(_relationRepository.Get(query).ToList()); //TODO: N+1, we should be able to do this in a single call - foreach (var relation in relations) + foreach (IRelation relation in relations) + { _relationRepository.Delete(relation); + } scope.Complete(); - scope.Events.Dispatch(DeletedRelation, this, new DeleteEventArgs(relations, false)); + scope.Notifications.Publish(new RelationDeletedNotification(relations, EventMessagesFactory.Get())); } } @@ -589,15 +593,6 @@ namespace Umbraco.Cms.Core.Services.Implement #endregion #region Events Handlers - /// - /// Occurs before Deleting a Relation - /// - public static event TypedEventHandler> DeletingRelation; - - /// - /// Occurs after a Relation is Deleted - /// - public static event TypedEventHandler> DeletedRelation; /// /// Occurs before Saving a Relation