-
-
Notifications
You must be signed in to change notification settings - Fork 624
XWIKI-10330: Allow reinstalling an extension from an extension reposi… #5383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vmassol
wants to merge
1
commit into
master
Choose a base branch
from
XWIKI-10330
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,6 +236,8 @@ ${escapetool.xml($name)}## | |
| #getInstalledExtension($extension $extensionNamespace $installedExtension) | ||
| ## If the installed extension might be invalid and need repairing | ||
| #extensionRepairButtons($installedExtension) | ||
| ## This extension can be reinstalled (re-download and re-install) | ||
| #extensionReinstallButtons($installedExtension) | ||
| ## This extension can be uninstalled | ||
| #extensionUninstallButtons($installedExtension) | ||
| ## XAR specific buttons | ||
|
|
@@ -308,6 +310,17 @@ ${escapetool.xml($name)}## | |
| #end | ||
| #end | ||
|
|
||
| #macro(extensionReinstallButtons $installedExtension) | ||
| #if ($installedExtension.isInstalled($NULL)) | ||
| ## It's installed on root namespace, propose reinstall on root | ||
| #extensionActionGlobalButton('reinstall' true) | ||
| #end | ||
| #if (!$installedExtension.isInstalled($NULL) && $installedExtension.isInstalled($extensionNamespace)) | ||
| ## It's installed on provided namespace, propose reinstall on that namespace | ||
| #extensionActionButton('reinstall' true) | ||
| #end | ||
| #end | ||
|
|
||
| #macro(extensionUninstallButtons $installedExtension) | ||
| #if (!$installedExtension.isInstalled($NULL) && $installedExtension.isInstalled($extensionNamespace)) | ||
| ## It's installed on provided namespace | ||
|
|
@@ -1161,6 +1174,10 @@ $namespace## | |
| #computeInstallPlan($request.extensionId $request.extensionVersion $NULL) | ||
| #elseif ($request.extensionAction == 'upgradeGlobally' || $request.extensionAction == 'downgradeGlobally') | ||
| #computeUpgradePlan($request.extensionId $request.extensionVersion) | ||
| #elseif ($request.extensionAction == 'reinstall') | ||
| #computeReinstallPlan($request.extensionId $request.extensionVersion $extensionNamespace) | ||
| #elseif ($request.extensionAction == 'reinstallGlobally') | ||
| #computeReinstallPlan($request.extensionId $request.extensionVersion $NULL) | ||
| #elseif ($request.extensionAction == 'uninstall') | ||
| #computeUninstallPlan($request.extensionId $request.extensionVersion $extensionNamespace) | ||
| #elseif ($request.extensionAction == 'uninstallGlobally') | ||
|
|
@@ -1221,6 +1238,31 @@ $namespace## | |
| #handleExtensionJobStartFailure('extensions.install.error.prepareFailure') | ||
| #end | ||
|
|
||
| #macro (computeReinstallPlan $extensionId $extensionVersion $extensionNamespace) | ||
| ## Remove from local cache to force a fresh download (useful for snapshot versions) | ||
| #set ($discard = $services.extension.local.removeExtension($extensionId, $extensionVersion)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After this line the installed extension is essentially broken. So if you don't validate the proposed plan, you are left in a pretty bad state. Creating an installation plan should be a readonly thing. Also, any change like this should be part of a job IMO. |
||
| ## Create install plan ignoring the fact that the extension is already installed | ||
| #set ($installPlanRequest = $extensionManager.createInstallPlanRequest($extensionId, $extensionVersion, $extensionNamespace)) | ||
| #set ($discard = $installPlanRequest.setInstalledIgnored(true)) | ||
| ## Force overwrite: bypass the 3-way merge so the freshly-downloaded content is written as-is. | ||
| ## Without this, the merge sees previous==next (both from the re-downloaded XAR) and silently keeps | ||
| ## the current wiki content unchanged. | ||
| #set ($discard = $installPlanRequest.setProperty('extension.xar.packager.forceOverwrite', true)) | ||
| #if ($extensionConfig.skipCheckRight) | ||
| #set ($discard = $installPlanRequest.removeProperty('checkrights')) | ||
| #end | ||
| #if ($extensionConfig.skipCurrentUser) | ||
| #set ($discard = $installPlanRequest.removeProperty('user.reference')) | ||
| #end | ||
| #if ($extensionConfig.installJAROnRoot) | ||
| #set ($discard = $installPlanRequest.rewriter.installExtensionTypeOnRootNamespace('jar')) | ||
| #set ($discard = $installPlanRequest.rewriter.installExtensionTypeOnRootNamespace('webjar')) | ||
| #set ($discard = $installPlanRequest.rewriter.installExtensionTypeOnRootNamespace('webjar-node')) | ||
| #end | ||
| #set ($discard = $extensionManager.createInstallPlan($installPlanRequest)) | ||
| #handleExtensionJobStartFailure('extensions.install.error.prepareFailure') | ||
| #end | ||
|
|
||
| #macro (computeUpgradePlan $extensionId $extensionVersion) | ||
| ## Upgrade all the namespaces were the specified extension is installed. | ||
| #set ($namespaces = []) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's IMO not a good idea to provide such a dangerous helper (if the passed extension is still installed, it will create quite a mess since the extension will still be found in the installed extension index in memory but not in the storage). If you really need that hack (but I don't think it's the right direction here), you can always use the already existing getRepository() script API.