diff --git a/setup/extensionsmap.class.inc.php b/setup/extensionsmap.class.inc.php index e5acebe1c4..7779bc6c09 100644 --- a/setup/extensionsmap.class.inc.php +++ b/setup/extensionsmap.class.inc.php @@ -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]); } } diff --git a/setup/modulediscovery.class.inc.php b/setup/modulediscovery.class.inc.php index 012b85863c..43bd7492cf 100755 --- a/setup/modulediscovery.class.inc.php +++ b/setup/modulediscovery.class.inc.php @@ -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) { diff --git a/tests/php-unit-tests/unitary-tests/setup/ExtensionsMapTest.php b/tests/php-unit-tests/unitary-tests/setup/ExtensionsMapTest.php index 8211cb9953..49e2872bdf 100644 --- a/tests/php-unit-tests/unitary-tests/setup/ExtensionsMapTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/ExtensionsMapTest.php @@ -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);