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

    }
   }
}
| improve this answer | |
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.

| improve this answer | |
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.
| improve this answer | |
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.

| improve this answer | |
1

This is (Very!) late, but just thought of sharing the solution that worked for me here as this article ranks top in search.

If you are looking for handling one item at a time during publish, you can just hook your handler to publish:itemProcessed event as described in Vlad's solution. If you will be needing to work on the entire list of published items all at once, you could leverage the ProcessedPublishingCandidates property. This is available in the Publish Context, which means it is accessible from the PublishItem pipeline (responsible for publishing individual item from publish queue) and Publish pipeline as well. You could just intercept the Publish pipeline after ProcessQueue step to get hold of the entire list of published items.

If you are looking for gathering more details specific to items and then handling them all at once, you could use 'CustomData' property which is part of Publish Context to store the custom data in PublishItem pipeline and process them at once from Publish pipeline.

class CustomPublishProcessor : PublishProcessor
{
    public override void Process(PublishContext context)
    {
        Assert.ArgumentNotNull(context, "context");
 
        if (context.Aborted)
            return;
     
        //Fetches List of Processed(Created/Updated/Deleted) Items
        var processedItems = context.ProcessedPublishingCandidates.Keys
            .Select(i => context.PublishOptions.TargetDatabase.GetItem(i.ItemId)).Where(j => j != null);

        //Fetches List of Deleted Items
        var deletedItems = context.DeleteCandidates;
    }
}

Here is the configuration to register the processor,

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <publish>
        <processor patch:after="*[@type='Sitecore.Publishing.Pipelines.Publish.ProcessQueue, Sitecore.Kernel']" type="Assembly.Pipelines.CustomPublishProcessor, Assembly"/>
      </publish>
    </pipelines>
  </sitecore>
</configuration>

For more information, see my blog article.

| 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.