Details
-
Bug
-
Resolution: Fixed
-
Major
-
9.11.3, 10.5
-
Unknown
-
N/A
-
N/A
-
Description
When a document is deleted, an DocumentDeletingEvent is triggered. It extends AbstractCancelableEvent so it should be cancel-able.
However, when a java listener call the "cancel()" method, it has no effect.
Some code to reproduce:
/** * @version $Id: $ */ @Component @Named("SomeName") @Singleton public class ProtectedPages implements EventListener { private static final List<Event> EVENTS = Arrays.<Event>asList(new DocumentDeletingEvent()); private static final List<DocumentReference> PROTECTED_PAGES = Arrays.asList( new DocumentReference("xwiki", "XWiki", "SomePage1"), new DocumentReference("xwiki", "XWiki", "SomePage2") ); @Inject private Logger logger; @Override public String getName() { return "Some Name"; } @Override public List<Event> getEvents() { return EVENTS; } @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; DocumentReference documentReference = document.getDocumentReference(); if (PROTECTED_PAGES.contains(documentReference)) { if (event instanceof CancelableEvent) { CancelableEvent cancelableEvent = (CancelableEvent) event; cancelableEvent.cancel("This document must be present in the wiki."); } else { logger.error("Failed to cancel the event [{}] for the document [{}].", event, documentReference); } } } }
A possible workaround is to save the original document in a DocumentDeletedEvent listener.
Attachments
Issue Links
- is related to
-
XWIKI-9054 Make document Events Cancelable + Implement ability to cancel when saving a document
- Closed
- relates to
-
XWIKI-19216 Display Document*ingEvent cancel reason in the UI
- Open