5

I did a small publish event listener using the following code:

[TcmExtension("TridionPPQEventSystem")]
public class PPQEventHandler : TcmExtension
{
    public PPQEventHandler()
    {
        Subscribe();
    }

    public void Subscribe()
    {
        EventSystem.Subscribe<Page, PublishEventArgs>(OnPagePublishPre, EventPhases.TransactionCommitted);
    }

    private void OnPagePublishPre(Page page, PublishEventArgs args, EventPhases phase)
    {
        //....some code here
    }
}

My question is, how to get the User who initiated the publishing? So far I have only found the user who last saved the page (Page.Revisor), but not the one who published it.

2 Answers 2

7

To get the user who published, you need to use

PublishTransaction.Creator

Here Creator returns the User Object.

private void OnPagePublishPre(Page page, PublishEventArgs mPublishEventArgs, EventPhases phase)
{
    List<PublishTransaction> mPublishTransactionList = mPublishEventArgs.PublishTransactions.ToList();

    foreach (PublishTransaction mPublishTransaction in mPublishTransactionList)
    {
        // Returns the User Title
        String publishedUser = mPublishTransaction.Creator.Title;
    }
}
0
7

Here just for your reference I pasted a code to get the user and also Groupname if you publish any component.

private void PublishingFinish(Component subject, PublishEventArgs e, EventPhases phase)
        {
            User user = subject.Session.User;           
            foreach (GroupMembership group in user.GroupMemberships)
            {
                group.Group.Title;
            }    
        }

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.