7

I was writing some code to log User, Id and Webdav when an item is deleted from the CME. My issue is around Organizational Items. Within the DeleteEventArgs I can see that there are 'N' ItemsToDelete where 'N' correlates to the number of items within the folder.

The issue is that I received the following exception "The item tcm:261-7052-2 does not exist" when iterating. I understand why I am getting this exception as the EventPhase is Processed. In fact when I debug and put a watch on that itemArgs, I can see the item not found exceptions. I just wondered if anyone had done something similar that made it easy to log out the Id and WebDav for items that were deleted due to invoking a delete on an Organization Item.

if (configManager.IsEventEnabled("OnGenericDeletePost")) {
            EventSystem.Subscribe<RepositoryLocalObject, DeleteEventArgs>(OnGenericDeletePost, EventPhases.Processed);
}

private void OnGenericDeletePost(RepositoryLocalObject obj, DeleteEventArgs args, EventPhases phase)
    {
        DELETE_LOGGER.WarnFormat("OnGenericDeletePost - User: {0}, tcm:{1}, webdav:{2}",obj.Session.User.Id, obj.Id, obj.WebDavUrl);

        try {
            DeleteOrganizationalItemEventArgs itmArgs = (DeleteOrganizationalItemEventArgs)args;
            DELETE_LOGGER.WarnFormat("ItemsToDelete = {0}", itmArgs.ItemsToDelete.ToList().Count);

            foreach (RepositoryLocalObject repObj in itmArgs.ItemsToDelete) {
                DELETE_LOGGER.WarnFormat("Others {0}, {1} ", repObj.Id, repObj.WebDavUrl);
            }

        } catch (Exception e) {
            DELETE_LOGGER.WarnFormat("OnGenericDeletePost Exception: {0}", e.Message);
        }                    


       }
}
7

It seems like deleting and org item should trigger delete events for all contained items. As such you should not need to iterate through the child items as you can log on all the delete events individually. Have you tried that?

| improve this answer | |
  • 2
    When I first started working with the Event System I thought that also. That's not what I'm seeing though. The Event System is only fired on the initial (in this case) Delete execution and not fired for all the additional assets that are deleted. If it was then this code would be hit for each Component that resides in the Folder I'm deleting as I've tested that this method is executed when I delete a Component from the CMI. – Chris Curry May 10 '13 at 13:00
  • 1
    You're correct Chris: the delete event only fires for the item on which the delete is initially triggered. If you want to handle something for each individual item, I'd look into a resolver. Of course the problem there probably is that a resolver has no knowledge of the operation for which it is invoked. :-/ – Frank van Puffelen May 11 '13 at 12:53
4

I never tried, but I would suspect the following would work:

  1. Create an event handler for the initiated phase
    1. Collect all the data you need to log in this Initiated handler
    2. Store the data in subject.Session.ContextData using an ID unique to your event handlers
  2. Create an event handler for the processed phase (or committed, whatever makes sense for your logging)
    1. Read the data back from subject.Session.ContextData
    2. Log the data
| improve this answer | |
  • This is the route I ended up going with. Thanks. – Chris Curry May 15 '13 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.