Skip to content

Commit ea12da9

Browse files
committed
moves RelateOnCopyHandler to Core and changes from ApplicationStarting to ApplicationStarted
1 parent 97a0500 commit ea12da9

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using Umbraco.Core.Auditing;
3+
using Umbraco.Core.Models;
4+
using Umbraco.Core.Services;
5+
6+
namespace Umbraco.Core.Strategies
7+
{
8+
public sealed class RelateOnCopyHandler : ApplicationEventHandler
9+
{
10+
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
11+
{
12+
ContentService.Copied += ContentServiceCopied;
13+
}
14+
15+
private void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs<IContent> e)
16+
{
17+
if (e.RelateToOriginal)
18+
{
19+
var relationService = ApplicationContext.Current.Services.RelationService;
20+
21+
var relationType = relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias);
22+
23+
if (relationType == null)
24+
{
25+
relationType = new RelationType(new Guid(Constants.ObjectTypes.Document),
26+
new Guid(Constants.ObjectTypes.Document),
27+
Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias,
28+
Constants.Conventions.RelationTypes.RelateDocumentOnCopyName) { IsBidirectional = true };
29+
30+
relationService.Save(relationType);
31+
}
32+
33+
var relation = new Relation(e.Original.Id, e.Copy.Id, relationType);
34+
relationService.Save(relation);
35+
36+
Audit.Add(AuditTypes.Copy,
37+
string.Format("Copied content with Id: '{0}' related to original content with Id: '{1}'",
38+
e.Copy.Id, e.Original.Id), e.Copy.WriterId, e.Copy.Id);
39+
}
40+
}
41+
}
42+
}

src/Umbraco.Web/Strategies/RelateOnCopyHandler.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,11 @@
77

88
namespace Umbraco.Web.Strategies
99
{
10+
[Obsolete("This class is no longer used and will be removed from the codebase in future versions")]
1011
public sealed class RelateOnCopyHandler : ApplicationEventHandler
1112
{
12-
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
13-
{
14-
ContentService.Copied += ContentServiceCopied;
15-
}
16-
17-
private void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs<IContent> e)
18-
{
19-
if (e.RelateToOriginal)
20-
{
21-
var relationService = ApplicationContext.Current.Services.RelationService;
22-
23-
var relationType = relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias);
24-
25-
if (relationType == null)
26-
{
27-
relationType = new RelationType(new Guid(Constants.ObjectTypes.Document),
28-
new Guid(Constants.ObjectTypes.Document),
29-
Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias,
30-
Constants.Conventions.RelationTypes.RelateDocumentOnCopyName) { IsBidirectional = true };
31-
32-
relationService.Save(relationType);
33-
}
34-
35-
var relation = new Relation(e.Original.Id, e.Copy.Id, relationType);
36-
relationService.Save(relation);
37-
38-
Audit.Add(AuditTypes.Copy,
39-
string.Format("Copied content with Id: '{0}' related to original content with Id: '{1}'",
40-
e.Copy.Id, e.Original.Id), e.Copy.WriterId, e.Copy.Id);
41-
}
13+
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
14+
{
4215
}
4316
}
4417
}

0 commit comments

Comments
 (0)