mirror of
https://github.com/Combodo/iTop.git
synced 2026-10-20 23:38:57 +02:00
Compare commits
1 Commits
develop
...
support/3.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2ab9f2902 |
@@ -62,20 +62,22 @@ class iTopExtensionsMap
|
|||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function __construct(string $sFromEnvironment = ITOP_DEFAULT_ENV, array $aExtraDirs = [], ?string $sAppRootForTests = null)
|
private function __construct(string $sFromEnvironment = ITOP_DEFAULT_ENV, array $aExtraDirs = [], ?string $sAppRootForTests = null, bool $bNoScan = false)
|
||||||
{
|
{
|
||||||
$this->aExtensions = [];
|
$this->aExtensions = [];
|
||||||
$this->aExtensionsByCode = [];
|
$this->aExtensionsByCode = [];
|
||||||
$this->aScannedDirs = [];
|
$this->aScannedDirs = [];
|
||||||
|
|
||||||
$sAppRoot = $sAppRootForTests ?? APPROOT;
|
if (! $bNoScan) {
|
||||||
$this->ScanDisk($sFromEnvironment, $sAppRoot);
|
$sAppRoot = $sAppRootForTests ?? APPROOT;
|
||||||
|
$this->ScanDisk($sFromEnvironment, $sAppRoot);
|
||||||
|
|
||||||
foreach ($aExtraDirs as $sDir) {
|
foreach ($aExtraDirs as $sDir) {
|
||||||
$this->ReadDir($sDir, iTopExtension::SOURCE_REMOTE, bIsRootDir: true);
|
$this->ReadDir($sDir, iTopExtension::SOURCE_REMOTE, bIsRootDir: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->CheckDependencies($sAppRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->CheckDependencies($sAppRoot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -261,7 +263,7 @@ class iTopExtensionsMap
|
|||||||
foreach ($aExtensionCodes as $sCode => $sLabel) {
|
foreach ($aExtensionCodes as $sCode => $sLabel) {
|
||||||
$sRealCode = is_int($sCode) ? $sLabel : $sCode;
|
$sRealCode = is_int($sCode) ? $sLabel : $sCode;
|
||||||
|
|
||||||
/** @var \iTopExtension $oExtension */
|
/** @var ?\iTopExtension $oExtension */
|
||||||
$oExtension = $this->GetFromExtensionCode($sRealCode);
|
$oExtension = $this->GetFromExtensionCode($sRealCode);
|
||||||
if (!is_null($oExtension)) {
|
if (!is_null($oExtension)) {
|
||||||
$aRemovedExtension [] = $oExtension;
|
$aRemovedExtension [] = $oExtension;
|
||||||
@@ -298,7 +300,7 @@ class iTopExtensionsMap
|
|||||||
$aSubDirectories = [];
|
$aSubDirectories = [];
|
||||||
|
|
||||||
// First check if there is an extension.xml file in this directory
|
// First check if there is an extension.xml file in this directory
|
||||||
if (is_readable($sSearchDir.'/extension.xml')) {
|
if ($sParentExtensionId === null && is_readable($sSearchDir.'/extension.xml')) {
|
||||||
$oXml = new XMLParameters($sSearchDir.'/extension.xml');
|
$oXml = new XMLParameters($sSearchDir.'/extension.xml');
|
||||||
$oExtension = new iTopExtension();
|
$oExtension = new iTopExtension();
|
||||||
$oExtension->sCode = $oXml->Get('extension_code');
|
$oExtension->sCode = $oXml->Get('extension_code');
|
||||||
@@ -357,7 +359,7 @@ class iTopExtensionsMap
|
|||||||
$oExtension->sVersion = $sModuleVersion;
|
$oExtension->sVersion = $sModuleVersion;
|
||||||
$oExtension->sSource = $sSource;
|
$oExtension->sSource = $sSource;
|
||||||
$oExtension->bMandatory = $aModuleInfo[ModuleFileReader::MODULE_INFO_CONFIG]['mandatory'];
|
$oExtension->bMandatory = $aModuleInfo[ModuleFileReader::MODULE_INFO_CONFIG]['mandatory'];
|
||||||
$oExtension->sMoreInfoUrl = $aModuleInfo[ModuleFileReader::MODULE_INFO_CONFIG]['doc.more_information'];
|
$oExtension->sMoreInfoUrl = $aModuleInfo[ModuleFileReader::MODULE_INFO_CONFIG]['doc.more_information'] ?? '';
|
||||||
$oExtension->aModules = [$sModuleName];
|
$oExtension->aModules = [$sModuleName];
|
||||||
$oExtension->aModuleVersion[$sModuleName] = $sModuleVersion;
|
$oExtension->aModuleVersion[$sModuleName] = $sModuleVersion;
|
||||||
$oExtension->aModuleInfo[$sModuleName] = $aModuleInfo[ModuleFileReader::MODULE_INFO_CONFIG];
|
$oExtension->aModuleInfo[$sModuleName] = $aModuleInfo[ModuleFileReader::MODULE_INFO_CONFIG];
|
||||||
@@ -403,27 +405,15 @@ class iTopExtensionsMap
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$aExtensions = [];
|
$oiTopExtensionsMap = new iTopExtensionsMap(bNoScan: true);
|
||||||
$hDir = opendir($sSearchDir);
|
$oiTopExtensionsMap->ReadDir($sSearchDir, iTopExtension::SOURCE_REMOTE, bIsRootDir: true);
|
||||||
if ($hDir !== false) {
|
|
||||||
|
|
||||||
// Then scan the other files and subdirectories
|
$aRes = [];
|
||||||
while (($sDir = readdir($hDir)) !== false) {
|
foreach ($oiTopExtensionsMap->aExtensionsByCode as $sCode => $oExtension) {
|
||||||
if (($sDir === '.') || ($sDir === '..') || !is_dir($sSearchDir.$sDir)) {
|
/** @var iTopExtension $oExtension */
|
||||||
continue;
|
$aRes[$sCode] = $oExtension->sLabel;
|
||||||
}
|
|
||||||
|
|
||||||
// First check if there is an extension.xml file in this directory
|
|
||||||
if (is_readable($sSearchDir.$sDir.'/extension.xml')) {
|
|
||||||
$oXml = new XMLParameters($sSearchDir.$sDir.'/extension.xml');
|
|
||||||
$aExtensions[$oXml->Get('extension_code')] = $oXml->Get('label');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir($hDir);
|
|
||||||
}
|
}
|
||||||
|
return $aRes;
|
||||||
return $aExtensions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice
|
|||||||
|
|
||||||
public function __construct(WizardController $oWizard, $sCurrentState)
|
public function __construct(WizardController $oWizard, $sCurrentState)
|
||||||
{
|
{
|
||||||
$this->oRuntimeEnv = new RunTimeEnvironment($oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV));
|
$this->oRuntimeEnv = new RunTimeEnvironment($oWizard->GetParameter('target_env', ITOP_DEFAULT_ENV), false);
|
||||||
$sBuildConfigFile = APPCONF.$this->oRuntimeEnv->GetBuildEnv().'/'.ITOP_CONFIG_FILE;
|
$sBuildConfigFile = APPCONF.$this->oRuntimeEnv->GetFinalEnv().'/'.ITOP_CONFIG_FILE;
|
||||||
$this->oConfig = new Config($sBuildConfigFile);
|
$this->oConfig = new Config($sBuildConfigFile);
|
||||||
|
|
||||||
$oWizard->SetParameter('previous_version_dir', APPROOT);
|
$oWizard->SetParameter('previous_version_dir', APPROOT);
|
||||||
@@ -36,6 +36,8 @@ class WizStepLandingBeforeAudit extends WizStepModulesChoice
|
|||||||
|
|
||||||
// should be done at the end
|
// should be done at the end
|
||||||
parent::__construct($oWizard, $sCurrentState, false);
|
parent::__construct($oWizard, $sCurrentState, false);
|
||||||
|
|
||||||
|
$this->oExtensionsMap = iTopExtensionsMap::GetExtensionsMap($this->oRuntimeEnv->GetBuildEnv());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ parameters:
|
|||||||
bootstrapFiles:
|
bootstrapFiles:
|
||||||
- ../../../approot.inc.php
|
- ../../../approot.inc.php
|
||||||
- ../../../bootstrap.inc.php
|
- ../../../bootstrap.inc.php
|
||||||
|
- ../../../tests/php-unit-tests/vendor/autoload.php
|
||||||
|
|
||||||
scanFiles:
|
scanFiles:
|
||||||
# Files necessary as they contain some declarations (constants, classes, functions, ...)
|
# Files necessary as they contain some declarations (constants, classes, functions, ...)
|
||||||
@@ -36,6 +37,5 @@ parameters:
|
|||||||
- ../../../env-php-unit-tests (?) # Irrelevant as it will either already be in `env-production` or might be desynchronized from `env-production`
|
- ../../../env-php-unit-tests (?) # Irrelevant as it will either already be in `env-production` or might be desynchronized from `env-production`
|
||||||
- ../../../env-toolkit (?) # Irrelevent as it will either already be in `env-production` or might be desynchronized from `env-production` (for local run only, not useful in the CI)
|
- ../../../env-toolkit (?) # Irrelevent as it will either already be in `env-production` or might be desynchronized from `env-production` (for local run only, not useful in the CI)
|
||||||
|
|
||||||
#- ../../../tests (?) # Exclude tests for now
|
- ../../../tests (?) # Exclude tests for now
|
||||||
- ../../../toolkit (?) # Exclude toolkit for now
|
- ../../../toolkit (?) # Exlclude toolkit for now
|
||||||
- ../../../setup/compat # Exclude fake DOMDocument & DOMElement declarations
|
|
||||||
|
|||||||
@@ -420,4 +420,130 @@ XML;
|
|||||||
|
|
||||||
return $aRes;
|
return $aRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetExtensionsFromDir_MonoModuleExtensionWithXmlDefinition()
|
||||||
|
{
|
||||||
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
||||||
|
$sTestDir = $this->PrepareTestDir();
|
||||||
|
|
||||||
|
$this->CreateExtensionFolder($sTestDir, "ext1", "ext_code1", "1.5.9");
|
||||||
|
$this->CreateModule($sTestDir, "module1", "module_code1", "9.5.1");
|
||||||
|
self::assertEquals(['ext_code1' => 'ext1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetExtensionsFromDir_MultiModuleExtension()
|
||||||
|
{
|
||||||
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
||||||
|
$sTestDir = $this->PrepareTestDir();
|
||||||
|
|
||||||
|
$this->CreateExtensionFolder($sTestDir, "ext1", "ext_code1", "1.5.9");
|
||||||
|
|
||||||
|
foreach ([1, 2, 3] as $i) {
|
||||||
|
$this->CreateModule($sTestDir, "module{$i}", "module_code{$i}", "9.5.{$i}");
|
||||||
|
}
|
||||||
|
self::assertEquals(['ext_code1' => 'ext1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetExtensionsFromDir_MultiModuleExtensionWithOneXMLDefPerModule()
|
||||||
|
{
|
||||||
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
||||||
|
$sTestDir = $this->PrepareTestDir();
|
||||||
|
|
||||||
|
$this->CreateExtensionFolder($sTestDir, "ext1", "ext_code1", "1.5.9");
|
||||||
|
|
||||||
|
foreach ([1, 2, 3] as $i) {
|
||||||
|
if (! is_dir("$sTestDir/module_code{$i}")) {
|
||||||
|
mkdir("$sTestDir/module_code{$i}");
|
||||||
|
}
|
||||||
|
$this->CreateExtensionFolder("$sTestDir/module_code{$i}", "ext{$i}", "ext_code{$i}", "9.5.{$i}");
|
||||||
|
$this->CreateModule($sTestDir, "module{$i}", "module_code{$i}", "9.5.{$i}");
|
||||||
|
}
|
||||||
|
self::assertEquals(['ext_code1' => 'ext1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetExtensionsFromDir_FurtherMonoModuleExtensionsWithoutXmlDefinition()
|
||||||
|
{
|
||||||
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
||||||
|
$sTestDir = $this->PrepareTestDir();
|
||||||
|
|
||||||
|
foreach ([1, 2, 3] as $i) {
|
||||||
|
$this->CreateModule($sTestDir, "module{$i}", "module_code{$i}", "9.5.{$i}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$expected = [
|
||||||
|
'module_code1' => 'module1',
|
||||||
|
'module_code2' => 'module2',
|
||||||
|
'module_code3' => 'module3',
|
||||||
|
];
|
||||||
|
self::assertEquals($expected, $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetExtensionsFromDir_MonoModuleExtensionWithoutXmlDefinition()
|
||||||
|
{
|
||||||
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
||||||
|
$sTestDir = $this->PrepareTestDir();
|
||||||
|
|
||||||
|
$this->CreateModule($sTestDir, "module1", "module_code1", "9.5.1");
|
||||||
|
self::assertEquals(['module_code1' => 'module1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function PrepareTestDir(): string
|
||||||
|
{
|
||||||
|
$sTestDir = tempnam(sys_get_temp_dir(), "ext_map");
|
||||||
|
unlink($sTestDir);
|
||||||
|
mkdir($sTestDir, 0777, true);
|
||||||
|
$this->aFileToClean[] = $sTestDir;
|
||||||
|
return $sTestDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function CreateExtensionFolder(string $sDir, string $sExtensionLabel, string $sExtensionCode, string $sExtensionVersion)
|
||||||
|
{
|
||||||
|
$sXmlDef = <<<XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<extension format="1.0">
|
||||||
|
<extension_code>$sExtensionCode</extension_code>
|
||||||
|
<label><![CDATA[$sExtensionLabel]]></label>
|
||||||
|
<description><![CDATA[BLABLA]]></description>
|
||||||
|
<version>$sExtensionVersion</version>
|
||||||
|
<modules type="array">
|
||||||
|
<module>
|
||||||
|
<id>aaa</id>
|
||||||
|
<version>tags/6.6.6</version>
|
||||||
|
</module>
|
||||||
|
</modules>
|
||||||
|
<release_date>2023-07-19</release_date>
|
||||||
|
<itop_version_min>3.2.0</itop_version_min>
|
||||||
|
<status></status>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<more_info_url></more_info_url>
|
||||||
|
</extension>
|
||||||
|
XML;
|
||||||
|
|
||||||
|
file_put_contents($sDir.'/extension.xml', $sXmlDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function CreateModule(string $sDir, string $sModuleLabel, string $sModuleCode, string $sVersion)
|
||||||
|
{
|
||||||
|
$sModuleDir = $sDir."/$sModuleCode";
|
||||||
|
if (! is_dir($sModuleDir)) {
|
||||||
|
mkdir($sModuleDir, 0777, true);
|
||||||
|
}
|
||||||
|
$sModuleContent = <<<PHP
|
||||||
|
<?php
|
||||||
|
SetupWebPage::AddModule(
|
||||||
|
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
|
||||||
|
'$sModuleCode/$sVersion',
|
||||||
|
[
|
||||||
|
'label' => '$sModuleLabel',
|
||||||
|
'category' => 'authentication',
|
||||||
|
'dependencies' => [],
|
||||||
|
'mandatory' => true,
|
||||||
|
'visible' => true,
|
||||||
|
'datamodel' => [],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
file_put_contents($sModuleDir."/module.{$sModuleCode}.php", $sModuleContent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user