2

Tridion 2013 sp1

I am trying to create an event system that will let me monitor modifications to a folder or SG. (changing the default page template. etc) While I can get the pre-save and post-save state easy enough, trying to pass information from the initiate phase to the transaction committed phase of the event does not work. I see that Niolai wrote. "Note, you cannot pass ContextVariables between events handled by the CM service, e.g. Save events, and Publisher service, e.g. Publish events. – Nickoli Roussakov Oct 26 '13 at 13:58"

Does anyone know if this was for 2011 or 2013sp1 or both. And if so, how did you solve this issue of reporting the change of properties in a structure group?

UPDATE: here is a sample of the code. When this is loaded the event doesn't fire and create the last log to show the before and after, so that I can then compare.

    private void preOrganizationalItemSaveAction(OrganizationalItem subject, SaveEventArgs args, EventPhases phase)
    {

        if (!GetType().Name.Equals("StructureGroup"))
        {

            StructureGroup subjs = subject as StructureGroup;

            string logDate = DateTime.Now.ToString("T");

            string fileName = String.Format(@"{0}\{1}.{2}.{3}", tmplogFilePath, orgItemChangeLogName.ToLower().Replace(" ", "_"), DateTime.Now.ToString("yyyy-MM-dd"), "txt");

            args.ContextVariables.Add("Initiated" , subjs.DefaultPageTemplate.Id );

            TextWriter tw = new StreamWriter(fileName, true);

            tw.WriteLine(String.Format("Time: {0} |  what: {1}" , logDate, subjs.DefaultPageTemplate.Id ));

            tw.Close();
        }

    } 

    private void OrganizationalItemSaveAction(OrganizationalItem subject, SaveEventArgs args, EventPhases phase)
    {
        //check if structure group
        if (!GetType().Name.Equals("StructureGroup"))
        {
            StructureGroup subjs = subject as StructureGroup;

            // Log every modification to a Folder or Structure Group with date, time, action, item, and user

            string logDate = DateTime.Now.ToString("T");

            string fileName = String.Format(@"{0}\{1}.{2}.{3}", logFilePath, orgItemChangeLogName.ToLower().Replace(" ", "_"), DateTime.Now.ToString("yyyy-MM-dd"), "txt");

            TextWriter tw = new StreamWriter(fileName, true);

           tw.WriteLine(String.Format("{0} | changed from {1} to {2}", logDate, args.ContextVariables["Initiated"].ToString(), subjs.DefaultPageTemplate.Id ));

            tw.Close();
        }

}

here is the constructor

namespace Tridion2011EventSystem
{
  [TcmExtension("Tridion2011EventSystem")]
  public class Tridion2011EventSystem : EventBase
  {
    private const string logFilePath = @"D:\APPS\Tridion\log";
    private const string tmplogFilePath = @"D:\APPS\Tridion\log\tmp";

    // Call the subscribe method to fire all events
    public Tridion2011EventSystem()
    {
        Subscribe();
    }

    public void Subscribe()
    {

        EventSubscription preOrganizationalItem = EventSystem.SubscribeAsync<OrganizationalItem, SaveEventArgs>(preOrganizationalItemSaveAction, EventPhases.Initiated);
        EventSubscription saveOrganizationalItem = EventSystem.SubscribeAsync<OrganizationalItem, SaveEventArgs>(OrganizationalItemSaveAction, EventPhases.TransactionCommitted);


        this.Subscriptions.Add(preOrganizationalItem); 
        this.Subscriptions.Add(saveOrganizationalItem);

    }
1
  • If all you need to do is stay within the "saveargs" set of events, then the regular Context Variables should work. Please elaborate what you mean by "does not work" when you stated: "trying to pass information from the initiate phase to the transaction committed phase of the event does not work." A stacktrace and screenshots would be most useful. Jul 15, 2014 at 18:14

2 Answers 2

5

You cannot attach Context Variables with an Asynchronous event, as Tridion won't be able to control the flow of it.

If your initial event is synchronous, then this will work. See example of this here.

1
  • that seems to be working, i'll add in all conditional logic, thanks Jul 15, 2014 at 19:25
1

I would still expect this to be present in 2013 SP1 because the Content Manager Host service is still separate from the Publisher service.

The way that I worked around the issue was to append an encoded token string to the Page Title on the CM. Think of this as kind of like a querystring, but on the Page Title. The reason for using the Page Title is because it is the easiest text property to access on a Page via TOM.NET without having to dive into ItemFields. So then in the Publisher service's event I decoded and cleaned up the "querystring" off the Page Title. It felt like a total hack, but it did the job. Here is the actual use case: http://www.tridiondeveloper.com/translating-page-urls-without-localizing-pages

Another way you could get info across the two services is by creating a temp Component (let's call it your "event system variables component") for each transaction, and then clean it up on Transaction Committed. When you create this temp component, name it with the transaction ID and store them in some Folder neatly tucked away under System.

3
  • I am not sure that works for this. What I need to do is whenever anyone alters the workflow or default page template for a SG, then I want to log that information. publishing doesn't necessarily follow. is there anyway to compare the initial phase with the committed phase of a structure group. Jul 15, 2014 at 17:51
  • here is a sample of the code: Jul 15, 2014 at 18:19
  • and your constructor with subscriptions please? Jul 15, 2014 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.