Prevent Scheduled Unpublish of Home node?
# help-with-umbraco
s
Hey all - Has anyone any insight into how to intercept and successfully cancel the Schedule Unpublish action on a content node? I have a ContentUnpublishingNotificationHandler that prevents the regular Unpublish of a home node (without the schedule feature). This code is working on Unpublish, however, I am having difficulties with the Scheduled Unpublish feature. When using the schedule unpublish, the ContentUnpublishingNotificationHandler runs, and "cancels" the event, but the node is still unpublished. Because the above is failing to prevent the unpublish even though it's returning the "CancleNotification", I've also created a ContentSavingNotificationHandler and a ContentSavedNotificationHandler, both of which use the ContentService to retreive the ContentSchedule. However, when they are run after applying the "Schedule Unpublish" feature on a home node, they do not contain the Expire Schedule. I've also tried subscribing to the ContentSchedule.CollectionChange event on the home node (created a ApplicationStarted) - however, this was never hit. I've read online that this event is often lost as the content is Saved and new versions are created. Note: I have explicitly set the ServerRole to ScheduledPublisher because otherwise the notifications weren't being sent. Note: I've also tried looking into just removing the permission to Schedule Unpublish on the home node - but, the permissions are then inherited by all child nodes - which isn't what we need. We just need to prevent unpublish on the root node.
While I'm still curious regarding why returning CancelNotification didn't work on the Content Unpublishing Notification Handler, I have resolved this issue. I was able to use the SendingContentNotification type notification to remove the ActionUnpublish.ActionLetter from the notification.Content.AllowedActions on the Home node (unless a condition is met to allow it).
11 Views