diff --git a/src/Umbraco.Core/Strategies/RelateOnCopyHandler.cs b/src/Umbraco.Core/Strategies/RelateOnCopyHandler.cs new file mode 100644 index 0000000000..e8c1956f2d --- /dev/null +++ b/src/Umbraco.Core/Strategies/RelateOnCopyHandler.cs @@ -0,0 +1,42 @@ +using System; +using Umbraco.Core.Auditing; +using Umbraco.Core.Models; +using Umbraco.Core.Services; + +namespace Umbraco.Core.Strategies +{ + public sealed class RelateOnCopyHandler : ApplicationEventHandler + { + protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + ContentService.Copied += ContentServiceCopied; + } + + private void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs e) + { + if (e.RelateToOriginal) + { + var relationService = ApplicationContext.Current.Services.RelationService; + + var relationType = relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias); + + if (relationType == null) + { + relationType = new RelationType(new Guid(Constants.ObjectTypes.Document), + new Guid(Constants.ObjectTypes.Document), + Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias, + Constants.Conventions.RelationTypes.RelateDocumentOnCopyName) { IsBidirectional = true }; + + relationService.Save(relationType); + } + + var relation = new Relation(e.Original.Id, e.Copy.Id, relationType); + relationService.Save(relation); + + Audit.Add(AuditTypes.Copy, + string.Format("Copied content with Id: '{0}' related to original content with Id: '{1}'", + e.Copy.Id, e.Original.Id), e.Copy.WriterId, e.Copy.Id); + } + } + } +} diff --git a/src/Umbraco.Web/Strategies/RelateOnCopyHandler.cs b/src/Umbraco.Web/Strategies/RelateOnCopyHandler.cs index 98cad3e639..ae72000edc 100644 --- a/src/Umbraco.Web/Strategies/RelateOnCopyHandler.cs +++ b/src/Umbraco.Web/Strategies/RelateOnCopyHandler.cs @@ -7,38 +7,11 @@ using Umbraco.Core.Services; namespace Umbraco.Web.Strategies { + [Obsolete("This class is no longer used and will be removed from the codebase in future versions")] public sealed class RelateOnCopyHandler : ApplicationEventHandler { - protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) - { - ContentService.Copied += ContentServiceCopied; - } - - private void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs e) - { - if (e.RelateToOriginal) - { - var relationService = ApplicationContext.Current.Services.RelationService; - - var relationType = relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias); - - if (relationType == null) - { - relationType = new RelationType(new Guid(Constants.ObjectTypes.Document), - new Guid(Constants.ObjectTypes.Document), - Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias, - Constants.Conventions.RelationTypes.RelateDocumentOnCopyName) { IsBidirectional = true }; - - relationService.Save(relationType); - } - - var relation = new Relation(e.Original.Id, e.Copy.Id, relationType); - relationService.Save(relation); - - Audit.Add(AuditTypes.Copy, - string.Format("Copied content with Id: '{0}' related to original content with Id: '{1}'", - e.Copy.Id, e.Original.Id), e.Copy.WriterId, e.Copy.Id); - } + protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { } } }