mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-04 00:24:14 +01:00
Compare commits
2 Commits
feature/91
...
feature/90
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae773ed912 | ||
|
|
f516053899 |
@@ -375,14 +375,14 @@ class iTopExtensionsMap
|
||||
* @return array<\iTopExtension>>
|
||||
*/
|
||||
|
||||
public function GetAllExtensionsToDisplayInSetup(bool $bKeepMissingDependencyExtensions = false): array
|
||||
public function GetAllExtensionsToDisplayInSetup(bool $bKeepMissingDependencyExtensions = false, bool $bRemoteExtensionsShouldBeMandatory = true): array
|
||||
{
|
||||
$aRes = [];
|
||||
foreach ($this->GetAllExtensionsWithPreviouslyInstalled() as $oExtension) {
|
||||
/** @var \iTopExtension $oExtension */
|
||||
if (($oExtension->sSource !== iTopExtension::SOURCE_WIZARD) && ($oExtension->bVisible)) {
|
||||
if ($bKeepMissingDependencyExtensions || (count($oExtension->aMissingDependencies) == 0)) {
|
||||
if (!$oExtension->bMandatory) {
|
||||
if ($oExtension->sSource !== iTopExtension::SOURCE_WIZARD && $oExtension->bVisible) {
|
||||
if ($bKeepMissingDependencyExtensions || count($oExtension->aMissingDependencies) == 0) {
|
||||
if (!$oExtension->bMandatory && $bRemoteExtensionsShouldBeMandatory) {
|
||||
$oExtension->bMandatory = ($oExtension->sSource === iTopExtension::SOURCE_REMOTE);
|
||||
}
|
||||
$aRes[$oExtension->sCode] = $oExtension;
|
||||
@@ -393,10 +393,10 @@ class iTopExtensionsMap
|
||||
return $aRes;
|
||||
}
|
||||
|
||||
public function GetAllExtensionsOptionInfo(): array
|
||||
public function GetAllExtensionsOptionInfo(bool $bRemoteExtensionsShouldBeMandatory = true): array
|
||||
{
|
||||
$aRes = [];
|
||||
foreach ($this->GetAllExtensionsToDisplayInSetup() as $sCode => $oExtension) {
|
||||
foreach ($this->GetAllExtensionsToDisplayInSetup(false, $bRemoteExtensionsShouldBeMandatory) as $sCode => $oExtension) {
|
||||
$aRes[] = [
|
||||
'extension_code' => $oExtension->sCode,
|
||||
'title' => $oExtension->sLabel,
|
||||
|
||||
@@ -83,33 +83,14 @@ class WizStepInstall extends AbstractWizStepInstall
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
if (!$this->CheckDependencies()) {
|
||||
$oPage->error($this->sDependencyIssue);
|
||||
$oPage->add_ready_script(<<<JS
|
||||
$("#wiz_form").data("installation_status", "error");
|
||||
document.getElementById("setup_msg").innerText = "Unmet dependencies";
|
||||
JS);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->oWizard->GetParameter('force-uninstall', false)) {
|
||||
SetupLog::Warning("User disabled uninstallation checks");
|
||||
}
|
||||
$aExtensionsRemoved = json_decode($this->oWizard->GetParameter('removed_extensions'), true) ?? [];
|
||||
$aExtensionsNotUninstallable = json_decode($this->oWizard->GetParameter('extensions_not_uninstallable'));
|
||||
$aExtensionsForceUninstalled = [];
|
||||
foreach ($aExtensionsRemoved as $sExtensionCode => $sLabel) {
|
||||
if (in_array($sExtensionCode, $aExtensionsNotUninstallable)) {
|
||||
$aExtensionsForceUninstalled[] = $sExtensionCode;
|
||||
}
|
||||
}
|
||||
if (count($aExtensionsForceUninstalled)) {
|
||||
SetupLog::Warning("Extensions uninstalled forcefully : ".implode(',', $aExtensionsForceUninstalled));
|
||||
}
|
||||
|
||||
$oPage->add_ready_script(<<<JS
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$("#wiz_form").data("installation_status", "not started");
|
||||
ExecuteStep("");
|
||||
JS);
|
||||
|
||||
JS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -626,7 +626,7 @@ EOF
|
||||
protected function GetStepInfo($idx = null)
|
||||
{
|
||||
$index = $idx ?? $this->GetStepIndex();
|
||||
|
||||
$bRemoteExtensionsShouldBeMandatory = !$this->oWizard->GetParameter('force-uninstall', false);
|
||||
if (is_null($this->aSteps)) {
|
||||
$this->oWizard->SetParameter('additional_extensions_modules', json_encode([])); // Default value, no additional extensions
|
||||
|
||||
@@ -637,7 +637,7 @@ EOF
|
||||
|
||||
if ($index + 1 >= count($this->aSteps)) {
|
||||
//make sure we also cache next step as well
|
||||
$aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo();
|
||||
$aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo($bRemoteExtensionsShouldBeMandatory);
|
||||
|
||||
// Display this step of the wizard only if there is something to display
|
||||
if (count($aOptions) > 0) {
|
||||
@@ -651,7 +651,7 @@ EOF
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo();
|
||||
$aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo($bRemoteExtensionsShouldBeMandatory);
|
||||
|
||||
// No wizard configuration provided, build a standard one with just one big list. All items are mandatory, only works when there are no conflicted modules.
|
||||
$this->aSteps = [
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Combodo\iTop\Test\UnitTest\Integration;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use iTopExtension;
|
||||
use iTopExtensionsMap;
|
||||
use iTopExtensionsMapFake;
|
||||
use ModuleDiscovery;
|
||||
@@ -376,6 +377,44 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
$this->assertEquals($aExpectedFlags, $aFlags);
|
||||
}
|
||||
|
||||
public function ProviderGetAllExtensionsToDisplayInSetupMandatoryFlag()
|
||||
{
|
||||
return [
|
||||
'A manually added extension should not be mandatory by default' => [
|
||||
'bExtensionSource' => 'extensions',//iTopExtension::SOURCE_MANUAL
|
||||
'bDisableUninstallChecks' => false,
|
||||
'bExpectedMandatory' => false,
|
||||
],
|
||||
'A remotely added extension should be mandatory by default' => [
|
||||
'bExtensionSource' => 'data',//iTopExtension::SOURCE_REMOTE
|
||||
'bDisableUninstallChecks' => false,
|
||||
'bExpectedMandatory' => true,
|
||||
],
|
||||
'A remotely added extension should not be mandatory by default if uninstall checks has been disabled' => [
|
||||
'bExtensionSource' => 'data',//iTopExtension::SOURCE_REMOTE
|
||||
'bDisableUninstallChecks' => true,
|
||||
'bExpectedMandatory' => false,
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ProviderGetAllExtensionsToDisplayInSetupMandatoryFlag
|
||||
*/
|
||||
public function testGetAllExtensionsToDisplayInSetupMandatoryFlag($bExtensionSource, $bDisableUninstallChecks, $bExpectedMandatory)
|
||||
{
|
||||
$aExtensionsOnDiskOrDb = [
|
||||
'itop-ext1' => [
|
||||
'installed' => true,
|
||||
'source' => $bExtensionSource,
|
||||
],
|
||||
];
|
||||
$oMap = iTopExtensionsMapFake::createFromArray($aExtensionsOnDiskOrDb);
|
||||
$aExtensions = $oMap->GetAllExtensionsToDisplayInSetup(false, !$bDisableUninstallChecks);
|
||||
$this->assertEquals($bExpectedMandatory, $aExtensions['itop-ext1']->bMandatory);
|
||||
}
|
||||
|
||||
public function ProviderGetAddedAndRemovedExtensions()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -21,6 +21,7 @@ class iTopExtensionsMapFake extends iTopExtensionsMap
|
||||
$oExtension->aModules = $aExtension['modules'] ?? [];
|
||||
$oExtension->bCanBeUninstalled = $aExtension['uninstallable'] ?? null;
|
||||
$oExtension->sVersion = $aExtension['version'] ?? '1.0.0';
|
||||
$oExtension->sSource = $aExtension['source'] ?? iTopExtension::SOURCE_MANUAL;
|
||||
$oExtension->aModuleInfo = $aExtension['module_info'] ?? [];
|
||||
$oMap->AddExtension($oExtension);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user