Search in sources :

Example 1 with UninstallException

use of org.xwiki.extension.UninstallException 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 2 with UninstallException

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

the class XarExtensionHandler method uninstall.

@Override
public void uninstall(InstalledExtension installedExtension, String namespace, Request request) throws UninstallException {
    try {
        initializePagesIndex(request);
        initJobPackageConfiguration(request, false);
    } catch (Exception e) {
        throw new UninstallException("Failed to initialize extension plan index", e);
    }
    // probably not be in an expected state)
    if (!request.isRemote()) {
        Job currentJob;
        try {
            currentJob = this.componentManager.<JobContext>getInstance(JobContext.class).getCurrentJob();
        } catch (ComponentLookupException e) {
            currentJob = null;
        }
        if (currentJob == null) {
            String wiki;
            try {
                wiki = XarHandlerUtils.getWikiFromNamespace(namespace);
            } catch (UnsupportedNamespaceException e) {
                throw new UninstallException("Failed to extract wiki id from namespace", e);
            }
            PackageConfiguration configuration = createPackageConfiguration(null, request, wiki);
            try {
                XarInstalledExtension xarLocalExtension = (XarInstalledExtension) this.xarRepository.resolve(installedExtension.getId());
                Collection<XarEntry> pages = xarLocalExtension.getXarPackage().getEntries();
                this.packager.unimportPages(pages, configuration);
            } catch (Exception e) {
                // Not supposed to be possible
                throw new UninstallException("Failed to get xar extension [" + installedExtension.getId() + "] from xar repository", e);
            }
        } else {
        // The actual delete of pages is done in XarExtensionJobFinishedListener
        }
    }
}
Also used : XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) XarEntry(org.xwiki.xar.XarEntry) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) JobContext(org.xwiki.job.JobContext) Job(org.xwiki.job.Job) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob) PackageConfiguration(org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtensionException(org.xwiki.extension.ExtensionException) IOException(java.io.IOException) UninstallException(org.xwiki.extension.UninstallException) InstallException(org.xwiki.extension.InstallException) XarException(org.xwiki.xar.XarException) UninstallException(org.xwiki.extension.UninstallException)

Aggregations

UninstallException (org.xwiki.extension.UninstallException)2 IOException (java.io.IOException)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ExtensionException (org.xwiki.extension.ExtensionException)1 InstallException (org.xwiki.extension.InstallException)1 InstalledExtension (org.xwiki.extension.InstalledExtension)1 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)1 PackageConfiguration (org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration)1 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)1 Job (org.xwiki.job.Job)1 JobContext (org.xwiki.job.JobContext)1 XarEntry (org.xwiki.xar.XarEntry)1 XarException (org.xwiki.xar.XarException)1