Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Hi,
You can load a ContentVersion through the API and there you have DelayPublishUntil. Remember to pass the PageReference/ContentReference with the WorkID as well (it should already be included in contentEventArgs.ContentLink.
Thank you Johan. ContentVersion was the key. This was my solution. If there is a more efficient way to do this, let me know.
private DateTime? GetDelayPublishUntil(ContentEventArgs contentEventArgs) { DateTime? DelayPublishUntil = null; var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentVersionRepository>(); if (repository != null) { ContentVersion contentVersion = repository.Load(contentEventArgs.ContentLink); if (contentVersion != null) { DelayPublishUntil = contentVersion.DelayPublishUntil; contentVersion = null; } repository = null; } return DelayPublishUntil; }
When a site administrator edits a page and uses the "Schedule for Publish" option, I need to capture the "Publish changes on" date/time value. Where I'm capturing this is within the context of a Content Event Initializer. Here is part of the helper class I'm using for this:
[InitializableModule] [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class ContentEventInitializer : IInitializableModule { public void Initialize(InitializationEngine initializationEngine) { SetIsMonitorNotificationEnabled(); if (IsMonitorNotificationEnabled) { var events = ServiceLocator.Current.GetInstance();
events.CheckedInContent += ExtendEvent.checkedInContent;
}
}
And this is my checkedInContent event that executes when the "Schedule" button is selected.
private static class ExtendEvent { public static void checkedInContent(object sender, ContentEventArgs contentEventArgs) { // Get the scheduled date and time. } }
My initial solution was to write a method that retrieved the value from the database via the WorkID found in contentEventArgs, via:
And later I appended that WorkID to a SQL query, like so, to grab that DelayPublishUntil value from the database.
string query = string.Format("SELECT DelayPublishUntil FROM tblWorkContent WHERE pkId = {0}", WorkID); using (SqlConnection connection = new SqlConnection(connectString)) { using (SqlCommand command = new SqlCommand(query, connection)) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow)) { IsDataRetrieved = reader.HasRows; while (reader.Read()) { DelayPublishUntil = ReaderUtility.GetDateTimeNullable(reader, "DelayPublishUntil"); } } } }
For a variety of reasons, I really don't like using this approach to retrieve the date-time. Primarily I'm concerned about foreword compatibility. So how can I get that scheduled publish date and time in a more robust manner. Thanks!