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);
}
}
}
}
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);
}
}
}
}
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);
}
}
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);
}
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;
}
}
}
}
}
Aggregations