Hi,
I’m using XWiki 13.10.5 and I have written an extension that listens for page/document deletions and renames. In the case of a rename my code appears to be getting a delete event which is part of the rename job (I.e. context.isIn(new DocumentRenamingEvent());
returns true
) but separately a second DocumentDeletedEvent
which isn’t part of the rename job (context.isIn(new DocumentRenamingEvent());
returns false
) as well as a DocumentRenamedEvent
.
As such, my code can’t reliably tell whether the document has been deleted or renamed.
Is there something I may be doing wrong or is there a way to determine whether a Delete event is an actual delete or part of a rename?
Thanks in advance,
Alex
Sounds very weird, could you get the stack trace of that one ?
Sorry for the delay. I’ve now realised what’s happening. I have an XWiki cluster and the extra Deleted Event is being seen on the other node. What I mean is…
- A Cluster with 2 instances of XWiki: A and B.
- Log in to XWiki, I end up on A.
- I rename a page.
- On A, I get:
- A
DocumentDeletedEvent
event which is in the context of a rename so, my code ignores it.
- A
DocumentRenamedEvent
which my code processes.
- On B, I get:
- A
DocumentDeletedEvent
event, which is not part of a context (the Event Deque the ObservationContext
gets from the ExecutionContext
is empty) so my code thinks it’s a page deletion and processes it as such.
Is there a way for my code to ignore remote events?
Cheers
My extension code basically follows the example provided here: https://extensions.xwiki.org/xwiki/bin/view/Extension/Observation%20Module%20Local such that it was intended to listen for “local” events rather than remote one.
I think I’ve found a solution but I would like some confirmation that I’m doing something acceptable. My solution is to:
Inject the Remote Observation Manager Context:
@Inject
private RemoteObservationManagerContext remoteContext;
An then in onEvent
, check remoteContext.isRemoteState();
and if that returns true
ignore the event.
WDYT?
Cheers
Yes, that’s it.
But this reminds me that we need to add support for DocumentRenaming/edEvent
events in the remote events distribution too since they are very important as your example shows. I created Loading....
Ok, great. Thank you @tmortagne, very much appreciated.