0

Is there any way to tell when a particular revision of an item, or version, got published? I can see standard fields for created and edited date-time, but publishing copies these fields to the web DB.

Is there any standard field or property that timestamps when an item was actually moved from master to web?

We use publish-on-demand and no workflows, so it's easily possible an item was edited a long time before someone got around to publishing it. I'd like to use PowerShell Extensions to find the point at which a particular item changed for a site visitor.

0

1 Answer 1

1

There is no functionality / field like that OOTB. You need to implement it.

You can create two fields "__Published" (Published Date) and "__Published By" (Published By).

Create your own custom class:

 public class UpdatePublishingStatistics : PublishItemProcessor
 {
    private const string PublishedFieldName = "__Published";
    private const string PublishedByFieldName = "__Published By";

    public override void Process(PublishItemContext context)
    {
        SetPublishingStatisticsFields(context);
    }

    private void SetPublishingStatisticsFields(PublishItemContext context)
    {
        Assert.ArgumentNotNull(context, "context");
        Assert.ArgumentNotNull(context.PublishOptions, "context.PublishOptions");
        Assert.ArgumentNotNull(context.PublishOptions.SourceDatabase, "context.PublishOptions.SourceDatabase");
        Assert.ArgumentNotNull(context.PublishOptions.TargetDatabase, "context.PublishOptions.TargetDatabase");
        Assert.ArgumentCondition(!ID.IsNullOrEmpty(context.ItemId), "context.ItemId", "context.ItemId must be set!");
        Assert.ArgumentNotNull(context.User, "context.User");

        SetPublishingStatisticsFields(context.PublishOptions.SourceDatabase, context.ItemId, context.User.Name);
        SetPublishingStatisticsFields(context.PublishOptions.TargetDatabase, context.ItemId, context.User.Name);
    }

    private void SetPublishingStatisticsFields(Database database, ID itemId, string userName)
    {
        Assert.ArgumentNotNull(database, "database");
        Item item = TryGetItem(database, itemId);

        if (HasPublishingStatisticsFields(item))
        {
            SetPublishingStatisticsFields(item, DateUtil.IsoNow, userName);
        }
    }

    private void SetPublishingStatisticsFields(Item item, string isoDateTime, string userName)
    {
        Assert.ArgumentNotNull(item, "item");
        Assert.ArgumentNotNullOrEmpty(isoDateTime, "isoDateTime");
        Assert.ArgumentNotNullOrEmpty(userName, "userName");

        using (new SecurityDisabler())
        {
            item.Editing.BeginEdit();
            item.Fields[PublishedFieldName].Value = DateUtil.IsoNow;
            item.Fields[PublishedByFieldName].Value = userName;
            item.Editing.EndEdit();
        }
    }

    private Item TryGetItem(Database database, ID itemId)
    {
        try
        {
            return database.Items[itemId];
        }
        catch (Exception ex)
        {
            Log.Error(this.ToString(), ex, this);
        }

        return null;
    }

    private static bool HasPublishingStatisticsFields(Item item)
    {
        Assert.ArgumentNotNull(item, "item");
        return item.Fields[PublishedFieldName] != null
                && item.Fields[PublishedByFieldName] != null;
    }
}

Add your custom pipeline :

 <?xml version="1.0" encoding="utf-8"?>
 <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
   <sitecore>
     <pipelines>
      <publishItem>
       <processor type="Sitecore.Sandbox.Pipelines.Publishing.UpdatePublishingStatistics, Sitecore.Sandbox"                     patch:after="processor[@type='Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics, Sitecore.Kernel']" />
      </publishItem>
     </pipelines>
   </sitecore>
 </configuration>

You can then access fields "__Published" or "__Published By" from PSE.

Code above was taken from below blog post where you can also get more information -> https://sitecorejunkie.com/2013/01/26/who-just-published-that-log-publishing-statistics-in-the-sitecore-client/

More information and previous discussion can be found here -> How to get a 'last publish date' for an item

0

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