SaaS CMS has officially launched! Learn more now.

CMS12 - How to hook up with unpublish content events?


Hi all good Opti people! 

I wonder if it's any way in Optimizely that you can hook up lik ContentEvent- Publishing but for un-publishing content? 

Why I'm asking? 

I have one Elasticsearch index that need to be updated when a editor have schedule to unpublish a page and when the unpublishing and when the time has come it should remove the content from the index. I will not that we should have an schedulejobb that reindex the whole site when something like this happends.

Have you a clue how i in a best way kan solve this issue?

Great regards


Edited, Aug 17, 2023 10:26

I think there is no event for unpublishing a content. You might want to use IPublishedStateAssessor or FilterContentForVisitor to check if a content should be gotten from the index.

Aug 17, 2023 12:55

One approach I've taken/seen is to use the Publish event, but with one more check for StopPublish date -- something like this, in the PublishedContent event:

if (content.StopPublish.HasValue && content.StopPublish <= DateTime.Now)

...then it's expired

Aug 17, 2023 20:09
Mikael Ekroth - Aug 18, 2023 5:56
But does this triggered when Optimizely expires unpublished the content?
Exampel: If you have an article that scheduled set to expires 12:00 and when the clock hits 12:00 it will marked as unpublished.
Quan Mai - Aug 18, 2023 6:17
no I don't think so. the expired content will be filtered by IPublishedStateAssessor / FilterContentForVisitor as I mentioned

believe (but you should test to verify) that when content is expired, it triggers the publish event.

Aug 18, 2023 15:00
Quan Mai - Aug 18, 2023 16:16
I believe it is not the case. there is no "ping" system, nor a scheduled job to check content for expiring.

Given something can become unpublished when the stop publish date goes from in the future to in the past, there will not be an event that happens immediately in the CMS editor code.  You're better off making sure your elastic search queries only include content where the Stop Publish Date is null or in the future and maybe add a Scheduled Job that removes recently expired content from your Elastic Search index.

Edited, Aug 21, 2023 7:50
Mikael Ekroth - Sep 01, 2023 7:04
When we receive the data from elasticsearch we do a sanity check to make sure that the page are published and it's work properly. I dont know if that is the best way to go but for now it's okey. Did not make any impact on the performance as well so.
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.