N°9949 - Cannot uninstall IPAM from setup wizard screen (#1015)

* N°9949 - Cannot uninstall IPAM from setup wizard screen

* N°9949 - add test coverage

* N°9949 - handle list in compilation
This commit is contained in:
odain-cbd
2026-08-20 10:03:25 +02:00
committed by GitHub
parent cdd7bbedcb
commit 95cb21cff7
3 changed files with 57 additions and 4 deletions

View File

@@ -239,7 +239,7 @@ class iTopExtensionsMap
\IssueLog::Debug(__METHOD__.": remove extension from map", null, [$oExtension->sCode => $oExtension->sSourceDir]);
unset($this->aExtensions[$oExtension->sCode.'/'.$oExtension->sVersion]);
unset($this->aExtensionsByCode[$sCode]);
unset($this->aExtensionsByCode[$oExtension->sCode]);
}
/**
@@ -260,14 +260,17 @@ class iTopExtensionsMap
public function DeclareExtensionAsRemoved(array $aExtensionCodes): void
{
$aRemovedExtension = [];
foreach ($aExtensionCodes as $sCode) {
foreach ($aExtensionCodes as $sCode => $sLabel) {
$sRealCode = is_int($sCode) ? $sLabel : $sCode;
/** @var \iTopExtension $oExtension */
$oExtension = $this->GetFromExtensionCode($sCode);
$oExtension = $this->GetFromExtensionCode($sRealCode);
if (!is_null($oExtension)) {
$aRemovedExtension [] = $oExtension;
\IssueLog::Debug(__METHOD__.": remove extension locally", null, ['extension_code' => $oExtension->sCode]);
} else {
\IssueLog::Warning(__METHOD__." cannot find extensions", null, ['code' => $sCode]);
\IssueLog::Warning(__METHOD__." cannot find extensions", null, ['code' => $sRealCode]);
}
}

View File

@@ -230,6 +230,7 @@ class ModuleDiscovery
}
/**
* @since 3.3
* @param array<\iTopExtension> $aRemovedExtension
* @return void
*/
@@ -241,6 +242,19 @@ class ModuleDiscovery
self::$m_aRemovedExtensions = $aRemovedExtension;
}
/**
* @since 3.3
* @return string[]
*/
public static function GetRemovedExtensionCodes(): array
{
$aRes = [];
foreach (self::$m_aRemovedExtensions as $oExtension) {
$aRes [] = $oExtension->sCode;
}
return $aRes;
}
private static function Init($aSearchDirs): void
{
if (self::$m_aSearchDirs != $aSearchDirs) {

View File

@@ -37,6 +37,40 @@ class ExtensionsMapTest extends ItopTestCase
$this->assertEquals($expected, array_keys($aExtensions));
}
public function testDeclareExtensionAsRemoved_WithDictPassed()
{
try {
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
//non existing extension
$aExtensionCodes = ['unexisting_extension_code' => 'label_unexisting_extension_code'];
//extension ok
$aExtensionCodes ['installed_ext1'] = $oExtensionsMap->GetFromExtensionCode('installed_ext1')->sLabel;
//search extension by label ko
$sLabel = $oExtensionsMap->GetFromExtensionCode('installed_ext_in_package')->sLabel;
$aExtensionCodes [$sLabel] = $sLabel;
$oExtensionsMap->DeclareExtensionAsRemoved($aExtensionCodes);
$this->assertEquals(["installed_ext1"], ModuleDiscovery::GetRemovedExtensionCodes());
} finally {
ModuleDiscovery::DeclareRemovedExtensions([]);
}
}
public function testDeclareExtensionAsRemoved_WithListPassed()
{
try {
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
$aExtensionCodes = ['unexisting_extension_code', 'installed_ext1'];
$aExtensionCodes [] = $oExtensionsMap->GetFromExtensionCode('installed_ext_in_package')->sLabel;
$oExtensionsMap->DeclareExtensionAsRemoved($aExtensionCodes);
$this->assertEquals(["installed_ext1"], ModuleDiscovery::GetRemovedExtensionCodes());
} finally {
ModuleDiscovery::DeclareRemovedExtensions([]);
}
}
public function testGetAllExtensionsToDisplayInSetup_WithExtensionsHavingDependencyIssues()
{
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
@@ -137,6 +171,7 @@ class ExtensionsMapTest extends ItopTestCase
{
$oExt = new iTopExtension();
$oExt->sCode = $sCode;
$oExt->sLabel = "LABEL_".$sCode;
$oExt->sVersion = $sVersion;
$oExt->bVisible = $bVisible;
$oExt->sSource = $sSource;
@@ -147,6 +182,7 @@ class ExtensionsMapTest extends ItopTestCase
private function AddExtension(iTopExtensionsMap $oExtensionsMap, iTopExtension $oExt, string $mapKeyInItopExtensionMap)
{
$this->InvokeNonPublicMethod(iTopExtensionsMap::class, 'AddExtension', $oExtensionsMap, [$oExt]);
$aMap = $this->GetNonPublicProperty($oExtensionsMap, $mapKeyInItopExtensionMap);
$aMap[$oExt->sCode.'/'.$oExt->sVersion] = $oExt;
$this->SetNonPublicProperty($oExtensionsMap, $mapKeyInItopExtensionMap, $aMap);