Try our conversational search powered by Generative AI!

Manoj Kumawat
Feb 28, 2022
  1129
(1 votes)

Delayed content scheduled job events

Hello everyone,

Today I was working on content events that adds the products under the category. As soon as you publish the category that will trigger the publish event and associates the products with the category that is being saved. This is working perfectly. 

The other scenarios where this was needed as where a category is scheduled to be published at a particular future time then those products should be auto assigned as soon as category is published. Now this required publish events to be triggered. I thought the job that keeps running is "Publish Delayed Content Versions" should handle those events by itself but unfortunately that wasn't supported. 

Per many blog posts it was suggested to write your own scheduled job that does it, This is what I'm sharing with you. Hopefully, It saves some time for you in future.

So I ended up writing my own scheduled job that looks for delayed contents and publishes them - 

  private void PublishOnBehalfOf(ContentReference contentLink, string user)
        {
            IPrincipal currentPrincipal = Thread.CurrentPrincipal;
            try
            {
                Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(user), null);

                var content = _contentLoader.Get<ContentData>(contentLink).CreateWritableClone();

                if (content != null)
                {
                    _contentRepository.Save((content as IContent), EPiServer.DataAccess.SaveAction.Publish | EPiServer.DataAccess.SaveAction.SkipValidation, AccessLevel.NoAccess);
                }
            }
            finally
            {
                Thread.CurrentPrincipal = currentPrincipal;
            }
        }

Let me know if full code is required. Thanks a lot for reading.

Feb 28, 2022

Comments

Please login to comment.
Latest blogs
Configured Commerce - Infrastructure Updates Ahoy!

I'm very happy to share an important milestone - we no longer have any customers in our legacy v1 environment!  This means that the Configured...

John McCarroll | May 10, 2024

A day in the life of an Optimizely Developer - Enabling Opti ID within your application

Hello and welcome to another instalment of A Day In The Life Of An Optimizely developer, in this blog post I will provide details on Optimizely's...

Graham Carr | May 9, 2024

How to add a custom property in Optimizely Graph

In the Optimizely CMS content can be synchronized to the Optimizely Graph service for it then to be exposed by the GraphQL API. In some cases, you...

Ynze | May 9, 2024 | Syndicated blog

New Security Improvement released for Optimizely CMS 11

A new security improvement has been released for Optimizely CMS 11. You should update now!

Tomas Hensrud Gulla | May 7, 2024 | Syndicated blog