Prevent Channel Manager users from deleting pages with nested sub-pages

Prevent Channel Manager users from deleting pages with nested sub-pages

The documentation for the Channel Manager has the following note on this page

Note that when deleting a page which has nested sub-pages in the sitemap, the sub-pages will also be deleted. For example, assume you have an editable page at URL www.example.com/blogs and a nested sub-page at URL www.example.com/blogs/myblog. If you delete the former page, the latter page will be deleted, too.

I am trying to design a way to prevent this from happening, or at least provide a Channel Manager user with warning when their page delete action will also remove nested pages.

I have so far attempted to capture the ‘write-changes’ event emitted by the Channel Manager and respond to it. However, it seems like this event is triggered after the changes are already made, so there is no way to abort the delete action.

Some example code:

public class ChannelPageIndexer {

    @Subscribe
    public void handleEvent(HippoEvent event) {
        if (!(event.category().equals("channel-manager") && event.action().equals("write-changes")) || event.message().isEmpty()) {
            return;
        }

        String[] changedNodes = event.message().split(",");

        try {
            for (String changedNode : changedNodes) {
                Node node = this.getUserSession().getNode(changedNode);
                if (node.getPrimaryNodeType().getName().equals("hst:sitemapitem")) {
                    NodeIterator children = node.getNodes();   // the children are already deleted when the event is captured,
                    if (children.getSize() > 0) {              // so this check is always false. 
                        //no way to abort action, either
                    }
                }
            }
        } catch (RepositoryException e) {
            //handle exception
        }
    }
}

Is there an alternative approach that might work better, or is this type of validation not possible within the current Channel Manager? If it makes any difference, I am currently working with Hippo CMS version 11.2.8