Copied to clipboard

Flag this post as spam?

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


  • Tobias Nylin 24 posts 117 karma points
    May 23, 2017 @ 06:49
    Tobias Nylin
    0

    ApplicationEventHandler ContentService.Publishing keeps executing over and over

    Hi! I'm making an event that will automatically sort pages of the type "CalendarEventPage". For doing this I get all the pages and sort them on a custom property called "StartDate". Finally, I call the method "ContentService.Sort" that will sort the pages. However, as soon as that line is executed the method starts all over again.

    At first I thought it triggered a publish event for the other pages but it is the same page the event is fired for.

    Does anyone have any idea why this is happening, am I missing something?

    Thanks!

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        ContentService.Publishing += ContentService_Publishing;
    }
    
    private void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
    {            
        var currentPage = e.PublishedEntities.FirstOrDefault();
    
        Debug.WriteLine("CurrentPage: " + currentPage.Name);
    
        if (currentPage != null && currentPage.ContentType.Alias == "CalendarEventPage")
        {
            var parent = currentPage.Parent();
    
            if (parent.ContentType.Alias == "CalendarEventListingPage")
            {
                var children = parent.Children();
    
                if (children != null && children.Any())
                {
                    var calendarEvents = children.Where(x => x.ContentType.Alias == "CalendarEventPage");
                    var sortedCalendarEvents =
                        calendarEvents.OrderByDescending(x => x.GetValue<DateTime>("StartDate"));
    
                    // This line fails!
                    var results = ApplicationContext.Current.Services.ContentService.Sort(sortedCalendarEvents);                        
                }
    
            }
        }
    }
    
  • Tobias Nylin 24 posts 117 karma points
    May 24, 2017 @ 12:52
    Tobias Nylin
    0

    Anyone? :)

Please Sign in or register to post replies

Write your reply to:

Draft