4

We are writing a Storage Extension. In the Storage extension is it possible to fetch the identity of the user who published the item?

I need the user name because I am creating an application which will be scheduling the publishing of an item by impersonation. There are some items for which records will be inserted by storage extension in MySQL database. In that record I need a column which can tell me the username of each publishing transaction.

If yes can you please share some sample code?

Issue is resolved:- Solution refer

  • Why you would you need a user in a Storage Extension, what is your plan with it? (please update the question with more information, so answers can be given in that direction) – Bart Koopman Jul 30 '13 at 11:03
  • I have updated the question. – AlokBhatt Jul 31 '13 at 5:25
3

Your description is still a little bit too abstract to determine whether a storage extension is the best place to handle this- could you be a little bit more specific about why it is you want to do this.

There is user information available on the content delivery side, however this is not necessarily the user who published the item. If you look in the ITEMS table in the broker database, you will see a TRUSTEE column which contains the username (not ID) of the user who last edited the item. If you look at a transport package you can also find this information in the xml file for the item(s) published. For example for a component, in components.xml:

<Components>
  <Component Id="tcm:9-99" isMultimedia="false">
    <Mandatory>
      <Title>My Component</Title>
      <VersionInfo>
        <Version>1</Version>
        <Revision>0</Revision>
        <CreationDate>2013-07-30T10:47:40</CreationDate>
        <RevisionDate>2013-07-30T10:47:40</RevisionDate>
        <Author>TRAIN1\Administrator</Author>
      </VersionInfo>
      <Schema Id="tcm:9-95-8" />
      <OwningPublication Id="tcm:0-4-1" />
    </Mandatory>
  </Component>
</Components>

So I guess you can access this information from within a storage/deployer extension.

If you really need the user who published the transaction, Version 2013+ contains an update whereby you can, from templates access the user who published via Engine.PublishContext.RenderContext.PublishTransaction.Creator. Note that this is not applicable for 2011 and earlier versions, where its a bit harder to get the Publish Transaction

So one thing you could do is add a binary on the fly into the publish transaction which is an xml file containing user id and whatever other details you want to store. Give it a suitably unique file extension (like .ptinfo or something) and then create a Item mapping for this file extension in your storage conf and a storage extension to put it in your MySQL database. The following gives some (untested) TBB code to do this...

public class AddTransactionInfo : ITemplate
{
    public void Transform(Engine engine, Package package)
    {
        var renderContext = engine.PublishingContext.RenderContext;
        //Context variables have scope of the whole transaction, so we can use them
        //to ensure we only generate the binary once per transaction.
        if (renderContext != null && !renderContext.ContextVariables.Contains("PublishTransactionInfo"))
        {
            var pubTransaction = renderContext.PublishTransaction;
            //Create an XML binary stream with the user id
            XDocument infoXml = XDocument.Parse("<transaction/>");
            MemoryStream binaryStream = new MemoryStream();
            infoXml.Root.SetAttributeValue("userid", pubTransaction.Creator.Id.ItemId);
            infoXml.Save(binaryStream);
            //Add the binary with unique filename and special file extension
            engine.PublishingContext.RenderedItem.AddBinary(binaryStream, pubTransaction.Id.ItemId + ".ptinfo", "ptinfo", "text/xml");
            //Set the context variable to prevent repeating this process
            renderContext.ContextVariables.Add("PublishTransactionInfo", infoXml);
        }
    }
}
| improve this answer | |
  • Your suggestion of publishing an xml file on the fly seems a good option for me. Can you please provide some link or information so that I can try this. – AlokBhatt Aug 8 '13 at 10:04
  • I added some example TBB code to generate the XML once per transaction... – Will Price Aug 8 '13 at 12:20
  • 1
    This is in the right general direction, but maybe it would be better to use RenderedItem.AddMetadata() – Dominic Cronin Aug 8 '13 at 13:07
  • Dominic - does that metadata persist over all items in the publish transaction? So if I publish a SG, will it be there for all pages? – Will Price Aug 8 '13 at 13:53
  • If you add RenderedItem.AddMetadata() in a page TBB it should make metadata available for each page in the transaction, but it doesnt store that added metadata in the broker afaik. – Raimond Aug 8 '13 at 14:13
2

The Storage Extension is executed on the Content Delivery side, so there is no concept of a user there available anymore (users are only on the Content Manager side, further down all actions are being handled by service and/or admin user accounts).

I believe that you don't even have access to the Publish Transaction ID inside the Storage Extension anymore, since that also isn't considered relevant on that level anymore. But technically the user who did the actual rendering and transporting of the package, is the SDL Tridion System Administrator, the user you are probably looking for is only the one who queued the Publish Transaction.

So in short, the user is not available.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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