Try our conversational search powered by Generative AI!

Manoj Kumawat
Feb 28, 2022
  1117
(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
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024