Search in sources :

Example 1 with InstalledExtension

use of org.xwiki.extension.InstalledExtension 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)

Example 2 with InstalledExtension

use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.

the class WikiEventListener method onWikiDeleted.

private void onWikiDeleted(WikiDeletedEvent event) {
    String namespace = "wiki:" + event.getWikiId();
    Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions(namespace);
    for (InstalledExtension installedExtension : installedExtensions) {
        if (!installedExtension.isInstalled(null)) {
            try {
                this.installedRepository.uninstallExtension(installedExtension, namespace);
            } catch (UninstallException e) {
                this.logger.error("Failed to uninstall extension [{}] from namespace [{}]", installedExtension, namespace, e);
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) UninstallException(org.xwiki.extension.UninstallException)

Example 3 with InstalledExtension

use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.

the class WikiEventListener method onWikiCopied.

private void onWikiCopied(WikiCopiedEvent event) {
    String sourceNamespace = "wiki:" + event.getSourceWikiId();
    String targetNamespace = "wiki:" + event.getTargetWikiId();
    Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions(sourceNamespace);
    for (InstalledExtension installedExtension : installedExtensions) {
        copyInstalledExtension(installedExtension, sourceNamespace, targetNamespace);
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension)

Example 4 with InstalledExtension

use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.

the class OutdatedExtensionsDistributionStep method executeNonInteractive.

@Override
public void executeNonInteractive() throws Exception {
    if (isMainWiki()) {
        Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions();
        // Upgrade outdated extensions only when there is invalid extensions
        for (InstalledExtension extension : installedExtensions) {
            Collection<String> installedNamespaces = extension.getNamespaces();
            if (installedNamespaces == null) {
                if (!extension.isValid(null)) {
                    // Upgrade/repair invalid extensions
                    repair(extension.getId(), null);
                }
            } else {
                for (String installedNamespace : installedNamespaces) {
                    if (!extension.isValid(installedNamespace)) {
                        // Upgrade/repair invalid extensions
                        repair(extension.getId(), installedNamespace);
                    }
                }
            }
        }
    } else {
        String currentNamespace = getNamespace().toString();
        Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions(currentNamespace);
        // Upgrade outdated extensions only when there is invalid extensions
        for (InstalledExtension extension : installedExtensions) {
            if (!extension.isValid(currentNamespace)) {
                // Upgrade/repair invalid extensions
                repair(extension.getId(), currentNamespace);
            }
        }
    }
    // Complete task
    setState(State.COMPLETED);
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension)

Example 5 with InstalledExtension

use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.

the class OutdatedExtensionsDistributionStep method prepare.

@Override
public void prepare() {
    if (getState() == null) {
        setState(State.COMPLETED);
        if (isMainWiki()) {
            Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions();
            // Upgrade outdated extensions only when there is invalid extensions
            for (InstalledExtension extension : installedExtensions) {
                Collection<String> installedNamespaces = extension.getNamespaces();
                if (installedNamespaces == null) {
                    if (!extension.isValid(null)) {
                        this.logger.debug("Enabling outdate extension step on main wiki " + "because extension [{}] is invalid on root namespace", extension.getId());
                        setState(null);
                        break;
                    }
                } else {
                    for (String installedNamespace : installedNamespaces) {
                        if (!extension.isValid(installedNamespace)) {
                            this.logger.debug("Enabling outdate extension step on main wiki " + "because extension [{}] is invalid on namespace [{}]", extension.getId(), installedNamespace);
                            setState(null);
                            break;
                        }
                    }
                }
            }
        } else {
            Namespace currentNamespace = getNamespace();
            Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions(currentNamespace.toString());
            // Upgrade outdated extensions only when there is invalid extensions
            for (InstalledExtension extension : installedExtensions) {
                if (!extension.isValid(currentNamespace.toString())) {
                    this.logger.debug("Enabling outdate extension step on wiki [{}]" + "because extension [{}] is invalid", getWiki(), extension.getId());
                    setState(null);
                    break;
                }
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) Namespace(org.xwiki.component.namespace.Namespace)

Aggregations

InstalledExtension (org.xwiki.extension.InstalledExtension)27 ExtensionId (org.xwiki.extension.ExtensionId)12 Test (org.junit.Test)8 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)5 Namespace (org.xwiki.component.namespace.Namespace)4 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)4 Collection (java.util.Collection)3 ExtensionDependency (org.xwiki.extension.ExtensionDependency)3 ExtensionInstalledEvent (org.xwiki.extension.event.ExtensionInstalledEvent)3 AbstractExtensionHandlerTest (org.xwiki.extension.test.AbstractExtensionHandlerTest)3 ExtendedURL (org.xwiki.url.ExtendedURL)3 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)3 JSONObject (net.sf.json.JSONObject)2 ExtensionEvent (org.xwiki.extension.event.ExtensionEvent)2 ExtensionUninstalledEvent (org.xwiki.extension.event.ExtensionUninstalledEvent)2 InstallRequest (org.xwiki.extension.job.InstallRequest)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 XWikiException (com.xpn.xwiki.XWikiException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1