Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Keith Boynton 18 posts 59 karma points
    6 days ago
    Keith Boynton
    0

    I'm using Umbraco 8 and the scheduled publishing is working great. I'm also hooked into the ContentService.Published event which fires when the content has been published, again, all working great.

    What I'm looking for is an event that fires when the scheduling happens rather than the publishing.

    So if on Thursday I schedule a piece of content to be published on Saturday I'd like to handle an event on Thursday (during scheduling) rather than on Saturday (during publishing).

    I couldn't see any documentation on such an event, nor in intellisense, is anyone aware of such an event or another way to hook into that process and do "something" when a user schedules something for publish?

  • Markus Johansson 1672 posts 4750 karma points c-trib
    6 days ago
    Markus Johansson
    0

    Hi!

    Hmm, MediaService.Saved should work? If you look at the saved item and look for some scheduled publish date in the future?

    I guess that this event would fire every time the node is saved but technically it’s “rescheduled” on each save I guess.

  • Keith Boynton 18 posts 59 karma points
    5 days ago
    Keith Boynton
    0

    That's an interesting angle, thank you for that idea!

    I'm going to look into it right now...

  • Keith Boynton 18 posts 59 karma points
    5 days ago
    Keith Boynton
    0

    So... thank you very much Markus for your steer!

    Here is what I came up with for now, in the ContentService.Saving event I used this...

            var blogArticleEntitiesBeingSaved = e.SavedEntities.Where(x => x.ContentType.Alias.Equals("blogArticle")).ToList();
            foreach (var blogArticleEntity in blogArticleEntitiesBeingSaved)
            {
                // Get the release schedule
                var releaseSchedule = blogArticleEntity.ContentSchedule.GetSchedule(ContentScheduleAction.Release).FirstOrDefault();
    
                // Get the publish date (this will only be set if the article has previously had a release schedule)
                var publishDate = blogArticleEntity.GetValue<DateTime>("publishDate");
    
                // If there is a future release schedule date and the publish date hasn't previously been set
                if (releaseSchedule != null && releaseSchedule.Date > DateTime.Now && publishDate == DateTime.MinValue)
                {
                    // Do something you only want to do the first time it's been scheduled
    
                    // Save the publish date so we know it's already been scheduled
                    blogArticleEntity.SetValue("publishDate", releaseSchedule.Date);
                }
            }
    

    It seems to work well for my needs, the publishDate field feels like a bit of a workaround but all subsequent saves of the item after scheduling would trigger too so I needed a way to only do it once (on the first time it's been scheduled).

    There is a message in the UI "A schedule has been updated" that is shown when the content is first scheduled for publish and isn't shown on subsequent saves so presumably there is something schedule event related that could be hooked into but I couldn't find it.

  • Markus Johansson 1672 posts 4750 karma points c-trib
    5 days ago
    Markus Johansson
    0

    Hi!

    Thanks for sharing!

    Keep me posted if you find some other solution :)

Please Sign in or register to post replies

Write your reply to:

Draft