I'm hoping this is me just missing something but it seems to me that it's impossible to do a scheduled publish with descendants and there appears to be no workaround.
I can't publish the descendants first as the parent needs to be published, if I schedule the parent then the descendants aren't published and there is no option I can see on the scheduling screen to include descendants.
Is the only way with some custom code hooked into the publish event or am I being daft and missing something?
// Subscribe to the content service publishing and published events
ContentService.Publishing += ContentService_Publishing;
ContentService.Published += ContentService_Published;
It's the published one that matters here, using the publishing one won't work on the first attempt as the parent won't be published yet.
And then in the event handler I just do this:
private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
{
// Handle any podcast episodes that have been published
var podcastEpisodeEntitiesPublished = e.PublishedEntities.Where(x => x.ContentType.Alias.Equals("podcastEpisode")).ToList();
HandlePublishedPodcastEpisodes(podcastEpisodeEntitiesPublished, e);
}
private void HandlePublishedPodcastEpisodes(List<IContent> publishedPodcastEpisodeEntities, ContentPublishedEventArgs e)
{
foreach (var podcastEpisodeEntity in publishedPodcastEpisodeEntities)
{
// Publish all the track nodes of the episode
var trackCount = _contentService.CountChildren(podcastEpisodeEntity.Id, "podcastTrack");
if (trackCount > 0)
{
var trackNodes = _contentService.GetPagedChildren(podcastEpisodeEntity.Id, 0, trackCount, out var total);
foreach (var trackNode in trackNodes)
{
var result = _contentService.SaveAndPublish(trackNode, raiseEvents: false);
_logger.Debug<CustomPublishingComponent>("published podcast track {Result}", result);
}
}
}
}
Scheduled publish with descendants in v8
Hey folks..
I'm hoping this is me just missing something but it seems to me that it's impossible to do a scheduled publish with descendants and there appears to be no workaround.
I can't publish the descendants first as the parent needs to be published, if I schedule the parent then the descendants aren't published and there is no option I can see on the scheduling screen to include descendants.
Is the only way with some custom code hooked into the publish event or am I being daft and missing something?
Hi Keith,
If this is not available out of the box what I would do is...
Schedule the publish of the parent
Then create a PublishedEvent to track this parent. https://our.umbraco.com/documentation/reference/events/
Then trigger saving and publishing all its children from within your PublishedEvent
This should work very well. I have done a similar thing many times.
Regards
David
Hi David,
Just returned to this after working on something else. Thank you very much for the response, I'm going to take a look at this in the morning.
Hi again David,
Thank you so much for the steer here, made total sense.
Here's how I implemented it for anyone looking for the same information:
In my custom publishing component where I suscribe to events:
I make sure I've got an IContentService I can use:
I then subscribe to the published event:
It's the published one that matters here, using the publishing one won't work on the first attempt as the parent won't be published yet.
And then in the event handler I just do this:
Thank you again David :)
No problems at all. Glad I could help.
This is a bit old topic, but hopefully you guys are still active here...
Still not figured out (now already in Umbraco 12) how to make this work.
When I schedule a Save and publish it seems the publishing and published events both arent hit, so how did you manage to get this working then?
is working on a reply...