Last active
August 29, 2015 13:57
-
-
Save willprice76/9496248 to your computer and use it in GitHub Desktop.
How to mirror live Tridion publish actions on staging using the Event System
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
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
using Tridion.ContentManager.CommunicationManagement; | |
using Tridion.ContentManager.ContentManagement; | |
using Tridion.ContentManager.Extensibility; | |
using Tridion.ContentManager.Extensibility.Events; | |
namespace Example.Events | |
{ | |
[TcmExtension("Publish Events Example")] | |
public class Events : TcmExtension | |
{ | |
public Events() | |
{ | |
EventSystem.Subscribe<RepositoryLocalObject, PublishOrUnPublishEventArgs>(MirrorOnStaging, EventPhases.Initiated); | |
} | |
private void MirrorOnStaging(RepositoryLocalObject item, PublishOrUnPublishEventArgs args, EventPhases phases) | |
{ | |
var stagingTargetTypeUri = "tcm:0-4-65538"; | |
var targets = args.Targets.ToList(); | |
if (targets.Where(t => t.Id.ToString() == stagingTargetTypeUri).FirstOrDefault() == null) | |
{ | |
targets.Add((TargetType)item.Session.GetObject(stagingTargetTypeUri)); | |
args.Targets = targets; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment