use of org.xwiki.extension.job.InstallRequest 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.job.InstallRequest in project xwiki-platform by xwiki.
the class AbstractExtensionDistributionStep method install.
protected void install(ExtensionId extensionId, String namespace, boolean jarOnRoot) throws JobException, InterruptedException {
// Install the default UI
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, extensionId.getId(), namespace));
installRequest.addExtension(extensionId);
installRequest.addNamespace(namespace);
// Indicate it's allowed to do modification on root namespace
installRequest.setRootModificationsAllowed(true);
// Make sure the job is no interactive
installRequest.setInteractive(false);
if (jarOnRoot) {
// Make sure jars are installed on root
// TODO: use a less script oriented class
ScriptExtensionRewriter rewriter = new ScriptExtensionRewriter();
rewriter.installExtensionTypeOnRootNamespace("jar");
rewriter.installExtensionTypeOnRootNamespace("webjar");
installRequest.setRewriter(rewriter);
}
// Set the author to use
installRequest.setProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, new DocumentReference("xwiki", "XWiki", XWikiRightService.SUPERADMIN_USER));
installRequest.setExtensionProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, XWikiRightService.SUPERADMIN_USER_FULLNAME);
this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest).join();
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createUpgradePlanRequest.
/**
* Create a request used when asking for the upgrade plan on the whole farm.
*
* @return the request to pass t the job
*/
private InstallRequest createUpgradePlanRequest() {
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, null, null));
contextualize(installRequest);
return installRequest;
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createUpgradePlanRequest.
/**
* Create a request used when asking for the upgrade plan of an extension on a namespace.
*
* @param extensionId the id of the extension
* @param namespace the namespace to upgrade
* @return the request to pass t the job
* @since 9.5
*/
public InstallRequest createUpgradePlanRequest(ExtensionId extensionId, String namespace) {
InstallRequest installRequest = new InstallRequest();
installRequest.addNamespace(namespace);
List<String> jobId;
if (extensionId != null) {
installRequest.addExtension(extensionId);
jobId = ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), namespace);
} else {
jobId = ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, null, namespace);
}
installRequest.setId(jobId);
contextualize(installRequest);
return installRequest;
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createInstallPlanRequest.
/**
* Create an {@link InstallRequest} instance based on given parameters, to be used to create the install plan.
*
* @param id the identifier of the extension to install
* @param version the version to install
* @param namespace the (optional) namespace where to install the extension; if {@code null} or empty, the extension
* will be installed in root namespace (globally)
* @return the {@link InstallRequest}
*/
public InstallRequest createInstallPlanRequest(String id, String version, String namespace) {
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, id, namespace));
installRequest.setInteractive(true);
installRequest.addExtension(new ExtensionId(id, version));
if (StringUtils.isNotBlank(namespace)) {
installRequest.addNamespace(namespace);
}
XWikiContext xcontext = this.xcontextProvider.get();
// Indicate if it's allowed to do modification on root namespace
installRequest.setRootModificationsAllowed(namespace == null || xcontext.isMainWiki(toWikiId(namespace)));
// Allow overwritting a few things in extensions descriptors
installRequest.setRewriter(new ScriptExtensionRewriter());
contextualize(installRequest);
setRightsProperties(installRequest);
return installRequest;
}
Aggregations