-
Notifications
You must be signed in to change notification settings - Fork 283
N°8762 - Allow extension uninstallation at setup #772
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
830a741
N°8762 - Allow uninstall at setup
Timmy38 350deb0
N°8762 - Allow uninstall at setup
Timmy38 233befd
N°8762 - Add warning for non-uninstallable extension
Timmy38 8a23a32
N°8762 - Remove trace
Timmy38 7ab5883
N°8762 - Remove temporary test
Timmy38 ada63ab
N°8762 - Force uninstallation flag (WIP)
Timmy38 76731f7
N°8762 - Force uninstallation flag
Timmy38 95c8139
N°8762 - Code cleanup
Timmy38 36a5284
N°8762 - Small refactor
Timmy38 a850ea8
N°8762 - Remove unused flag, add @since to new methods
Timmy38 c4ca0bc
N°8762 Apply suggestion from @Hipska
Timmy38 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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -110,6 +110,17 @@ public function __construct() | |||||||
| $this->bVisible = true; | ||||||||
| $this->aMissingDependencies = array(); | ||||||||
| } | ||||||||
|
|
||||||||
| public function IsUninstallable() | ||||||||
| { | ||||||||
| foreach ($this->aModuleInfo as $sModuleCode => $aModuleInfo) { | ||||||||
| $bUninstallable = $aModuleInfo['uninstallable'] === 'yes'; | ||||||||
| if (!$bUninstallable) { | ||||||||
|
Comment on lines
+121
to
+122
Contributor
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.
Suggested change
|
||||||||
| return false; | ||||||||
| } | ||||||||
| } | ||||||||
| return true; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
|
|
@@ -253,6 +264,16 @@ protected function AddExtension(iTopExtension $oNewExtension) | |||||||
| $this->aExtensions[$oNewExtension->sCode.'/'.$oNewExtension->sVersion] = $oNewExtension; | ||||||||
| } | ||||||||
|
|
||||||||
| public function Get($sExtensionCode):?iTopExtension | ||||||||
| { | ||||||||
Timmy38 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| foreach($this->aExtensions as $oExtension) { | ||||||||
| if ($oExtension->sCode == $sExtensionCode) { | ||||||||
| return $oExtension; | ||||||||
| } | ||||||||
| } | ||||||||
| return null; | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Read (recursively) a directory to find if it contains extensions (or modules) | ||||||||
| * | ||||||||
|
|
@@ -277,8 +298,7 @@ protected function ReadDir($sSearchDir, $sSource, $sParentExtensionId = null) | |||||||
| $aSubDirectories = array(); | ||||||||
|
|
||||||||
| // First check if there is an extension.xml file in this directory | ||||||||
| if (is_readable($sSearchDir.'/extension.xml')) | ||||||||
| { | ||||||||
| if (is_readable($sSearchDir.'/extension.xml')) { | ||||||||
| $oXml = new XMLParameters($sSearchDir.'/extension.xml'); | ||||||||
| $oExtension = new iTopExtension(); | ||||||||
| $oExtension->sCode = $oXml->Get('extension_code'); | ||||||||
|
|
@@ -317,20 +337,19 @@ protected function ReadDir($sSearchDir, $sSource, $sParentExtensionId = null) | |||||||
| // to this extension | ||||||||
| $sModuleId = $aModuleInfo[1]; | ||||||||
| list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId); | ||||||||
| if ($sModuleVersion == '') | ||||||||
| { | ||||||||
| if ($sModuleVersion == '') { | ||||||||
| // Provide a default module version since version is mandatory when recording ExtensionInstallation | ||||||||
| $sModuleVersion = '0.0.1'; | ||||||||
| } | ||||||||
| $aModuleInfo[2]['uninstallable'] ??= 'yes'; | ||||||||
Timmy38 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
|
|
||||||||
| if (($sParentExtensionId !== null) && (array_key_exists($sParentExtensionId, $this->aExtensions)) && ($this->aExtensions[$sParentExtensionId] instanceof iTopExtension)) { | ||||||||
| // Already inside an extension, let's add this module the list of modules belonging to this extension | ||||||||
| $this->aExtensions[$sParentExtensionId]->aModules[] = $sModuleName; | ||||||||
| $this->aExtensions[$sParentExtensionId]->aModuleVersion[$sModuleName] = $sModuleVersion; | ||||||||
| $this->aExtensions[$sParentExtensionId]->aModuleInfo[$sModuleName] = $aModuleInfo[2]; | ||||||||
| } | ||||||||
| else | ||||||||
| { | ||||||||
| else { | ||||||||
| // Not already inside an folder containing an 'extension.xml' file | ||||||||
|
|
||||||||
| // Ignore non-visible modules and auto-select ones, since these are never prompted | ||||||||
|
|
@@ -452,6 +471,17 @@ public function MarkAsChosen($sExtensionCode, $bMark = true) | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| public function MarkAsUninstallable($sExtensionCode, $bMark = true) | ||||||||
Timmy38 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| { | ||||||||
| foreach($this->aExtensions as $oExtension) { | ||||||||
| if ($oExtension->sCode == $sExtensionCode) { | ||||||||
| $oExtension->bUninstallable = $bMark; | ||||||||
| break; | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Tells if a given extension(code) is marked as chosen | ||||||||
| * @param string $sExtensionCode | ||||||||
|
|
@@ -530,6 +560,8 @@ public function LoadChoicesFromDatabase(Config $oConfig) | |||||||
| foreach($aInstalledExtensions as $aDBInfo) | ||||||||
| { | ||||||||
| $this->MarkAsChosen($aDBInfo['code']); | ||||||||
| $sUninstallable = $aDBInfo['uninstallable'] ?? 'yes'; | ||||||||
| $this->MarkAsUninstallable($sUninstallable); | ||||||||
Timmy38 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| $this->SetInstalledVersion($aDBInfo['code'], $aDBInfo['version']); | ||||||||
| } | ||||||||
| return true; | ||||||||
|
|
@@ -572,46 +604,39 @@ public function IsExtensionObsoletedByAnother(iTopExtension $oExtension) | |||||||
| public function NormalizeOldExtensions($sInSourceOnly = iTopExtension::SOURCE_MANUAL) | ||||||||
| { | ||||||||
| $aSignatures = $this->GetOldExtensionsSignatures(); | ||||||||
| foreach($aSignatures as $sExtensionCode => $aExtensionSignatures) | ||||||||
| { | ||||||||
| foreach($aSignatures as $sExtensionCode => $aExtensionSignatures) { | ||||||||
| $bFound = false; | ||||||||
| foreach($aExtensionSignatures['versions'] as $sVersion => $aModules) | ||||||||
| { | ||||||||
| foreach($aExtensionSignatures['versions'] as $sVersion => $aModules) { | ||||||||
| $bInstalled = true; | ||||||||
| foreach($aModules as $sModuleId) | ||||||||
| { | ||||||||
| if(!$this->ModuleIsPresent($sModuleId, $sInSourceOnly)) | ||||||||
| { | ||||||||
| foreach($aModules as $sModuleId) { | ||||||||
| if(!$this->ModuleIsPresent($sModuleId, $sInSourceOnly)) { | ||||||||
| $bFound = false; | ||||||||
| break; // One missing module is enough to determine that the extension/version is not present | ||||||||
| } | ||||||||
| else | ||||||||
| { | ||||||||
| $bInstalled = $bInstalled && (!$this->ModuleIsInstalled($sModuleId, $sInSourceOnly)); | ||||||||
| else { | ||||||||
| $bInstalled = $bInstalled && $this->ModuleIsInstalled($sModuleId, $sInSourceOnly); | ||||||||
| $bFound = true; | ||||||||
| } | ||||||||
| } | ||||||||
| if ($bFound) break; // The current version matches the signature | ||||||||
| } | ||||||||
|
|
||||||||
| if ($bFound) | ||||||||
| { | ||||||||
| if ($bFound) { | ||||||||
| $oExtension = new iTopExtension(); | ||||||||
| $oExtension->sCode = $sExtensionCode; | ||||||||
| $oExtension->sLabel = $aExtensionSignatures['label']; | ||||||||
| $oExtension->sSource = $sInSourceOnly; | ||||||||
| $oExtension->sDescription = $aExtensionSignatures['description']; | ||||||||
| $oExtension->sVersion = $sVersion; | ||||||||
| $oExtension->aModules = array(); | ||||||||
| if ($bInstalled) | ||||||||
| { | ||||||||
| if ($bInstalled) { | ||||||||
| $oExtension->sInstalledVersion = $sVersion; | ||||||||
| $oExtension->bMarkedAsChosen = true; | ||||||||
| } | ||||||||
| foreach($aModules as $sModuleId) | ||||||||
| { | ||||||||
| foreach($aModules as $sModuleId) { | ||||||||
| list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId); | ||||||||
| $oExtension->aModules[] = $sModuleName; | ||||||||
| $oExtension->aModuleInfo[$sModuleName] = $this->aExtensions[$sModuleId]->aModuleInfo[$sModuleName]; | ||||||||
| } | ||||||||
| $this->ReplaceModulesByNormalizedExtension($aExtensionSignatures['versions'][$sVersion], $oExtension); | ||||||||
| } | ||||||||
|
|
||||||||
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
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.