Skip to content

Add (un)publishing details to TreeChange notifications#17757

Merged
Zeegaan merged 1 commit intov13/devfrom
v13/feature/publishing-info-in-change-notifications
Dec 9, 2024
Merged

Add (un)publishing details to TreeChange notifications#17757
Zeegaan merged 1 commit intov13/devfrom
v13/feature/publishing-info-in-change-notifications

Conversation

@kjac
Copy link
Copy Markdown
Contributor

@kjac kjac commented Dec 9, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

Description

This PR adds additional (un)publishing info to TreeChange (specifically which cultures were affected by the operation), to be consumed by ContentTreeChangeNotification handlers.

This additional info is also added to the ContentCacheRefresherNotification, to make it available in a load balanced scenario.

For invariant content, the wildcard (*) is used to communicate the affected cultures.

Testing this PR

Add a notification handler to ContentTreeChangeNotification and ContentCacheRefresherNotification, and verify that the PublishedCultures and UnpublishedCultures properties match any (un)publishing operations performed in the backoffice.

Here's a notification handler 😄

using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services.Changes;

namespace Umbraco.Cms.Web.UI.Custom;

public class ContentCacheRefresherNotificationHandler :
    INotificationHandler<ContentCacheRefresherNotification>,
    INotificationHandler<ContentTreeChangeNotification>
{
    public void Handle(ContentCacheRefresherNotification notification)
    {
        if (notification.MessageObject is not ContentCacheRefresher.JsonPayload[] payloads)
        {
            return;
        }

        foreach (ContentCacheRefresher.JsonPayload payload in payloads)
        {
            Console.WriteLine(
                "## Content cache refresher - published = {0}, unpublished = {1}",
                string.Join(", ", payload.PublishedCultures ?? []),
                string.Join(", ", payload.UnpublishedCultures ?? []));
        }
    }

    public void Handle(ContentTreeChangeNotification notification)
    {
        foreach (TreeChange<IContent> change in notification.Changes)
        {
            Console.WriteLine(
                "## Content tree change - published = {0}, unpublished = {1}",
                string.Join(", ", change.PublishedCultures ?? []),
                string.Join(", ", change.UnpublishedCultures ?? []));
        }
    }
}

public class ContentCacheRefresherNotificationHandlerComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
        => builder.AddNotificationHandler<ContentCacheRefresherNotification, ContentCacheRefresherNotificationHandler>();
}

@Zeegaan
Copy link
Copy Markdown
Member

Zeegaan commented Dec 9, 2024

Looks good, tests good 🚀

@Zeegaan Zeegaan merged commit 404a62a into v13/dev Dec 9, 2024
@Zeegaan Zeegaan deleted the v13/feature/publishing-info-in-change-notifications branch December 9, 2024 10:36
Zeegaan pushed a commit that referenced this pull request Dec 9, 2024
@Zeegaan
Copy link
Copy Markdown
Member

Zeegaan commented Dec 9, 2024

Cherry picked for 13.6 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants