Search in sources :

Example 1 with ExtensionHandler

use of org.xwiki.extension.handler.ExtensionHandler in project xwiki-platform by xwiki.

the class WikiEventListener method onWikiCreated.

private void onWikiCreated(WikiCreatedEvent event, XWikiContext context) {
    String namespace = "wiki:" + event.getWikiId();
    Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions(null);
    InstallRequest installRequest = new InstallRequest();
    DocumentReference userReference = context.getUserReference();
    if (userReference != null) {
        installRequest.setProperty(PROPERTY_USER_REFERENCE, userReference);
        // We set the string value because the extension repository doesn't know how to serialize/parse an extension
        // property whose value is a DocumentReference, and adding support for it requires considerable refactoring
        // because ExtensionPropertySerializers are not components (they are currently hard-coded).
        installRequest.setExtensionProperty(PROPERTY_USER_REFERENCE, userReference.toString());
    }
    installRequest.setVerbose(false);
    // TODO: make it interactive ? (require wiki creation to be job based)
    installRequest.setInteractive(false);
    ExtensionHandler xarHandler = this.xarHandlerProvider.get();
    for (InstalledExtension installedExtension : installedExtensions) {
        if (installedExtension.getType().equals(XarExtensionHandler.TYPE)) {
            installRequest.addExtension(installedExtension.getId());
            try {
                xarHandler.install(installedExtension, namespace, installRequest);
            } catch (InstallException e) {
                this.logger.error("Failed to import extension [{}] in wiki [{}]", installedExtension, event.getWikiId(), e);
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionHandler(org.xwiki.extension.handler.ExtensionHandler) InstallException(org.xwiki.extension.InstallException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

InstallException (org.xwiki.extension.InstallException)1 InstalledExtension (org.xwiki.extension.InstalledExtension)1 ExtensionHandler (org.xwiki.extension.handler.ExtensionHandler)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1