When installing an extension, if it register MandatoryDocumentInitializer roles, their updateDocument() method should be called in each context (wiki) that the extension is installed in.
Note, that due to an issue soon to be resolved (see
XWIKI-10352) in Utils#getComponentList() which cause the root CM to be used instead of the context CM, it will not be called on restart either.
The current workaround is the create a listener on ApplicationReadyEvent, WikiReadyEvent and ExtensionInstalledEvent to hook your own implementation of MandatoryDocumentInitializer#updateDocument(). Be careful to
- check that your listener is registered in the current context, since it will be called for any context
- use hashCode() to build the name of your listener, so its name is unique among all contexts (see XCOMMONS-213)
I attach a zip with 1 interface and 2 classes, showing a reimplementation of MandatoryDocumentInitializer based on such a listener to helps