Try our conversational search powered by Generative AI!

Manoj Kumawat
Feb 28, 2022
  1131
(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
Do not upgrade to EPiServer.CMS.Core 12.21.4 without reading this!

Todays update of EPiServer.CMS.Core 12.21.4 alters default sort order in an unexpected way, when you are working with muligple languages and have...

Tomas Hensrud Gulla | May 14, 2024 | Syndicated blog

Upgrade Optimizely CMS From v11 to v12

Why Upgrade? There are many improvements implemented in version 12, but most importantly is that the whole framework is migrated from .Net Framewor...

MilosR | May 13, 2024

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