Problem The only event sent when a wiki is deleted is WikiDeletedEvent, and it is sent by DefaultWikiManager#delete once the wiki descriptor and the wiki database are already gone. A component which needs to read the wiki's data to clean up what it keeps about that wiki (indexes, caches, registered components, scheduled tasks…) cannot do it anymore at that point. Also, a listener receiving another event while the wiki is being deleted (for example the RightUpdatedEvent sent when the wiki descriptor document is deleted) has no way to know that this wiki is going away. This leads to errors in the logs, or to data of the deleted wiki being kept, for example:
XWIKI-25420: the asynchronous rendering cache evaluates again, on the RightUpdatedEvent sent when the descriptor is deleted, the right checks of users of the wiki being deleted, which logs Failed to load rights errors.
- XWIKI-9498: the Solr indexer keeps indexing the documents of the wiki being deleted. tmortagne: "we would probably need to introduce a WikiDeletingEvent since when receiving WikiDeletedEvent it's already too late".
XWIKI-9499: wiki components could not be unregistered by searching the wiki for them, because the search happens after the wiki is gone (a WikiDeletingEvent, possibly with a WikiDeleteFailedEvent, was proposed there).
- XWIKI-18484: a UI extension with a global scope from a deleted subwiki displays an error in the main wiki.
Proposal Frame the deletion of a wiki the same way its creation is framed by WikiCreatingEvent / WikiCreatedEvent / WikiCreateFailedEvent:
- introduce WikiDeletingEvent (BeginFoldEvent), sent by DefaultWikiManager#delete before the wiki is deleted;
- make WikiDeletedEvent an EndFoldEvent;
- introduce WikiDeleteFailedEvent (EndEvent), sent when the deletion fails.
A listener can then either clean up what it keeps about the wiki on WikiDeletingEvent, while the wiki can still be read, or check the ObservationContext to know that an event is received during the deletion of a wiki. Limitations
- Like WikiDeletedEvent, the events are only sent when the wiki is deleted through the WikiManager, not when the wiki descriptor page is deleted directly (see XWIKI-19846).
- The ObservationContext is only available in the thread performing the deletion (see XWIKI-19691 for the same problem with WikiCreatingEvent).
|