7

I have set up an Auto Publish Workflow OnSave event. But some events like Rename and Copy doesn't Auto Publish. Basically I don't save these changes explicitly, they autosave.

How do i handle this and make sure all my changes (for all the events) are Auto Published?

0
6

You should make use of the other Sitecore item events. For your case, you will need to add a handler on the below events:

  1. item:copied

  2. item:renamed

Note that you can check web.config if you are still on Sitecore v6.x to v7.2 and Sitecore.config for Sitecore v8.x to see the different events that are available.

The same code you applied on the item save event can be applied on the above event. All you need to do is to use the same handler as the one you used for the save event.

UPDATE

You can also directly publish the item when the user updates / creates or rename an item. Please see below code.

public class PublishingOnSaved
{
    public void OnSavedItem(object sender, EventArgs args)
    {
        var currentItem = Event.ExtractParameter(args, 0) as Item;

        if (currentItem == null)
        {
            return;
        }

        var targetDatabase = Factory.GetDatabase("your target database name");

        // The publishOptions determine the source and target database,
        // the publish mode and language, and the publish date
        Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions
        (
            currentItem.Database,
            targetDatabase,
            Sitecore.Publishing.PublishMode.SingleItem,
            currentItem.Language,
            System.DateTime.Now
        );

        // Create a publisher with the publishoptions
        Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

        // Choose where to publish from
        publisher.Options.RootItem = currentItem;

        // Publish children as well?
        publisher.Options.Deep = true;

        // Do the publish!
        publisher.Publish();
    }
}

Then you need to bind this piece of code to the event.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="item:saved">
        <handler type="YourNamespaceWithClass, YourAssembly" method="OnSavedItem">
      </event>
    </events>
  </sitecore>
</configuration>
1
  • Hi Hishaam, I see following handlers <handler type="Sitecore.Links.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved"/> <handler type="Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved"/> <!--6.1 Upgrade--> <handler type="Sitecore.Rules.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" /> <handler type="Sitecore.Caching.Placeholders.PlaceholderCacheEventHandler, Sitecore.Kernel" method="UpdateCaches" resolve="true" />
    – Prakash
    Jun 22 '17 at 9:19

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.