3

I need to get list of items that were published but I don't know where to get it...

I created publish:end handler

public void OnPubEnd(object sender, EventArgs args)
        {
            var sitecoreEventArgs = ((SitecoreEventArgs) args);
            var item = Event.ExtractParameter(args, 0);
}

but it is no data about it in SitecoreEventArgs

8

The publish:end event will be triggered once at the end when all items have been published and therefore does not contain the list of all the items. If you are interested in collect information about the item you published you need to implement a handler in the publish:itemProcessed

 <event name="publish:itemProcessed">
   <handler 
   type="My.Assembly.Namespace.ItemProcessedProcessor, My.Assembly"
method="ItemProcessed">
   </handler>
  </event>

This is your code for the processor:

using System;
using Sitecore.Data;
using Sitecore.Publishing.Pipelines.PublishItem;

namespace My.Assembly.Namespace
{
  public class ItemProcessedProcessor
    {


    public void ItemProcessed(object sender, EventArgs args)
    {
        ItemProcessedEventArgs itemProcessedEventArgs = args as ItemProcessedEventArgs;
        PublishItemContext context = itemProcessedEventArgs != null ? itemProcessedEventArgs.Context : null;

        // your logic here

    }
   }
}
1

As an example for quick solution you can use publish:itemProcessed but you can operate only with one item per time. In this case you need to develop your custom storage and accumulate published items and clean it up by some criteria.

1

You can patch up your logic in 'Publish' Pipeline to get the items published. Also get 'lastpublished date' & compare it with published items to fetch the new items that are published.

Please take care of

  1. Your sitecore version as publishing feature in 8.2 started using publishing service, if 8.2 i think you might change your approach on this.
  2. I would recommend to make publish light weight & think about someother alternates to achieve this if possible. As you might be aware 'publish' is the long time process & we have to think before extending it.
1

Sitecore publishing log is way more complete and durable, but if you don't have a processor logging this for you -- in a pinch -- I've made use of this SQL query to the EventQueue to get a handle on what's been recently published:

SELECT Created as [Publish Timestamp]
            , Username as [Initiator]
            , CAST(SUBSTRING(HASHBYTES('SHA1', UserName),1,3) as bigint)  as [Hashed Initiator]
            , IIF(CHARINDEX('"TargetDatabaseName":"web"', InstanceData)>0,'1','0') AS [To web]
            , IIF(CHARINDEX('"TargetDatabaseName":"ProdRegion1web"', InstanceData)>0,'1','0') AS [To Region1]
            , IIF(CHARINDEX('"TargetDatabaseName":"ProdRegion2web"', InstanceData)>0,'1','0') AS [To Region2]
            , IIF(CHARINDEX('"TargetDatabaseName":"ProdRegion3web"', InstanceData)>0,'1','0') AS [To Region3]
            , (LEN(InstanceData) - LEN(REPLACE(InstanceData, '"LanguageName"', ''))) / LEN('"LanguageName"') as [# of Langs] --this is an ugly proxy for how heavy a publish is
            , InstanceData AS [Raw Data]
        FROM EventQueue
        WHERE EventType LIKE 'Sitecore.Publishing.StartPublishingRemoteEvent%'
        ORDER BY Created DESC

Depending on your EventQueue data retention rules, this may or may not be useful.

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.