Console icon indicating copy to clipboard operation
Console copied to clipboard

Event handler for Publish:Complete and Publish:Complete:Remote needs update to Args casting.

Open GreyGhostStudio opened this issue 3 years ago • 1 comments

Expected Behavior

Event handler should cast the Sitecore Event arguments to the correct type based on the type of publish event before extracting the Item to pass along for rules evaluation.

<handler type="Spe.Integrations.Tasks.ScriptedItemEventHandler, Spe" method="OnEvent" />

For Publish:Complete might do something like... (Event.ExtractParameter(eventArgs, 0) as IEnumerable<DistributedPublishOptions>)?.First().RootItemId

For Publish:Complete:Remote might do something like... (eventArgs as PublishCompletedRemoteEventArgs).PublishOptions?.First().RootItemId

Then peel off the RootItemId to get the Item to pass in.

Actual Behavior

The event handler treats each event args as the same. In certain situations this will result in null being passed in for the item variable to the rules evaluation.

if (args is SitecoreEventArgs)
        item = ((SitecoreEventArgs) args).Parameters[0] as Item;

Steps to Reproduce the Problem

SPE 6.1.1.0 Sitecore 9.3

  • [x] Tested issue with clean install of Sitecore and the latest available version of SPE. Downloaded 6.2 and the event handler code has not changed.

  • [ ] Asked questions on the Sitecore Slack Chat channel.

  • [ ] Reviewed questions and answers on the Sitecore Stack Exchange.

GreyGhostStudio avatar Mar 16 '21 19:03 GreyGhostStudio

If there are multiple items should the event handler run for each item?

michaellwest avatar Mar 16 '21 20:03 michaellwest