Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moves RelateOnCopyHandler to Core and changes from ApplicationStartin…
…g to ApplicationStarted
- Loading branch information
Showing
2 changed files
with
45 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IContent> 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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters