mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 23:44:11 +01:00
Compare commits
74 Commits
feature/88
...
feature/91
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
defca2d31e | ||
|
|
b257d254d6 | ||
|
|
4d789aeccc | ||
|
|
7789d3ed0a | ||
|
|
2f14b341e8 | ||
|
|
44d917c79d | ||
|
|
f5be709fc6 | ||
|
|
f1c8591255 | ||
|
|
049a4942c2 | ||
|
|
b516466022 | ||
|
|
a2496f4e15 | ||
|
|
709a278df9 | ||
|
|
e1c96eefc4 | ||
|
|
d0ac19c8d1 | ||
|
|
6b4413fffc | ||
|
|
4e769a1836 | ||
|
|
ea44e39b2c | ||
|
|
fd6ce5f5c4 | ||
|
|
a54b11c933 | ||
|
|
85dd5448fe | ||
|
|
5b58e40fc9 | ||
|
|
2b21556c76 | ||
|
|
77626f8159 | ||
|
|
bb6248a6e7 | ||
|
|
130d98aa3f | ||
|
|
00c590232a | ||
|
|
97828225db | ||
|
|
03e59c9749 | ||
|
|
985a49dc9f | ||
|
|
adae35ccc4 | ||
|
|
f0c9629f5f | ||
|
|
4e96b297c2 | ||
|
|
ae620c6663 | ||
|
|
b5c51a2983 | ||
|
|
3b2d845c00 | ||
|
|
36c545a6c4 | ||
|
|
5ecb4936f0 | ||
|
|
af2c3b02bc | ||
|
|
cfc933b92b | ||
|
|
0582ae1038 | ||
|
|
13c18b611c | ||
|
|
8d2e0761e0 | ||
|
|
1e15eb1161 | ||
|
|
7df59427cb | ||
|
|
d647d92acf | ||
|
|
693e40b9c7 | ||
|
|
c3c2135ecc | ||
|
|
63e473e6d0 | ||
|
|
3a3f5736c0 | ||
|
|
0996e8fae0 | ||
|
|
43bd621731 | ||
|
|
d1e91087b9 | ||
|
|
73cb58a131 | ||
|
|
d1fde89129 | ||
|
|
1f4b96798a | ||
|
|
9768ffb19d | ||
|
|
e55bbf728b | ||
|
|
5f2604c610 | ||
|
|
57b3610100 | ||
|
|
9f3b8ec964 | ||
|
|
193c980057 | ||
|
|
fdfe9224c3 | ||
|
|
774fe22ece | ||
|
|
27b0f64328 | ||
|
|
8ad4670a2f | ||
|
|
f2e682c07c | ||
|
|
83973d102f | ||
|
|
85e28931f5 | ||
|
|
d33ca81198 | ||
|
|
1ef4462517 | ||
|
|
a2b0ad6c11 | ||
|
|
7844c9ffd0 | ||
|
|
1c45a4c49e | ||
|
|
8f47ca00a7 |
@@ -16,5 +16,5 @@ require_once(APPROOT.'/application/audit.category.class.inc.php');
|
||||
require_once(APPROOT.'/application/audit.domain.class.inc.php');
|
||||
require_once(APPROOT.'/application/audit.rule.class.inc.php');
|
||||
require_once(APPROOT.'/application/query.class.inc.php');
|
||||
require_once(APPROOT.'/setup/moduleinstallation.class.inc.php');
|
||||
require_once(APPROOT.'/setup/moduleinstallation/moduleinstallation.class.inc.php');
|
||||
require_once(APPROOT.'/application/utils.inc.php');
|
||||
|
||||
@@ -24,7 +24,7 @@ MetaModel::IncludeModule('application/user.dashboard.class.inc.php');
|
||||
MetaModel::IncludeModule('application/audit.rule.class.inc.php');
|
||||
MetaModel::IncludeModule('application/audit.domain.class.inc.php');
|
||||
MetaModel::IncludeModule('application/query.class.inc.php');
|
||||
MetaModel::IncludeModule('setup/moduleinstallation.class.inc.php');
|
||||
MetaModel::IncludeModule('setup/moduleinstallation/moduleinstallation.class.inc.php');
|
||||
|
||||
MetaModel::IncludeModule('core/event.class.inc.php');
|
||||
MetaModel::IncludeModule('core/action.class.inc.php');
|
||||
|
||||
@@ -2685,14 +2685,13 @@ class Config
|
||||
*
|
||||
* @param array $aParamValues
|
||||
* @param ?string $sModulesDir
|
||||
* @param bool $bPreserveModuleSettings
|
||||
*
|
||||
* @return void The current object is modified directly
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function UpdateFromParams($aParamValues, $sModulesDir = null, $bPreserveModuleSettings = false)
|
||||
public function UpdateFromParams($aParamValues, $sModulesDir = null)
|
||||
{
|
||||
if (isset($aParamValues['application_path'])) {
|
||||
$this->Set('app_root_url', $aParamValues['application_path']);
|
||||
@@ -2740,7 +2739,10 @@ class Config
|
||||
} else {
|
||||
$aSelectedModules = null;
|
||||
}
|
||||
$this->UpdateIncludes($sModulesDir, $aSelectedModules);
|
||||
|
||||
if (! is_null($sModulesDir)) {
|
||||
$this->UpdateIncludes($sModulesDir, $aSelectedModules);
|
||||
}
|
||||
|
||||
if (isset($aParamValues['source_dir'])) {
|
||||
$this->Set('source_dir', $aParamValues['source_dir']);
|
||||
@@ -2758,17 +2760,13 @@ class Config
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function UpdateIncludes($sModulesDir, $aSelectedModules = null)
|
||||
public function UpdateIncludes(string $sModulesDir, $aSelectedModules = null)
|
||||
{
|
||||
if ($sModulesDir === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize the arrays below with default values for the application...
|
||||
$oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values
|
||||
$aAddOns = $oEmptyConfig->GetAddOns();
|
||||
|
||||
$aModules = ModuleDiscovery::GetAvailableModules([APPROOT.$sModulesDir]);
|
||||
$aModules = ModuleDiscovery::GetModulesOrderedByDependencies([APPROOT.$sModulesDir]);
|
||||
foreach ($aModules as $sModuleId => $aModuleInfo) {
|
||||
list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId);
|
||||
if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules)) {
|
||||
|
||||
@@ -22,6 +22,8 @@ use Combodo\iTop\Application\EventRegister\ApplicationEvents;
|
||||
use Combodo\iTop\Core\MetaModel\FriendlyNameType;
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Service\Events\EventService;
|
||||
use Combodo\iTop\Setup\ModuleDependency\Module;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReader;
|
||||
|
||||
require_once APPROOT.'core/modulehandler.class.inc.php';
|
||||
require_once APPROOT.'core/querymodifier.class.inc.php';
|
||||
@@ -468,11 +470,35 @@ abstract class MetaModel
|
||||
* @return string
|
||||
* @throws \CoreException
|
||||
*/
|
||||
final public static function GetCreatedIn($sClass)
|
||||
final public static function GetModuleName($sClass)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
try {
|
||||
$oReflectionClass = new ReflectionClass($sClass);
|
||||
$sDir = realpath(dirname($oReflectionClass->getFileName()));
|
||||
$sApproot = realpath(APPROOT);
|
||||
while (($sDir !== $sApproot) && (str_contains($sDir, $sApproot))) {
|
||||
$aFiles = glob("$sDir/module.*.php");
|
||||
if (count($aFiles) > 1) {
|
||||
return 'core';
|
||||
}
|
||||
|
||||
return self::$m_aClassParams[$sClass]["created_in"] ?? "";
|
||||
if (count($aFiles) == 0) {
|
||||
$sDir = realpath(dirname($sDir));
|
||||
continue;
|
||||
}
|
||||
|
||||
$sModuleFilePath = $aFiles[0];
|
||||
$aModuleInfo = ModuleFileReader::GetInstance()->ReadModuleFileInformation($sModuleFilePath);
|
||||
$sModuleId = $aModuleInfo[ModuleFileReader::MODULE_INFO_ID];
|
||||
list($sModuleName, ) = ModuleDiscovery::GetModuleName($sModuleId);
|
||||
|
||||
return $sModuleName;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new CoreException("Cannot find class module", ['class' => $sClass], '', $e);
|
||||
}
|
||||
|
||||
return 'core';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3158,7 +3184,6 @@ abstract class MetaModel
|
||||
$aMandatParams = [
|
||||
"category" => "group classes by modules defining their visibility in the UI",
|
||||
"key_type" => "autoincrement | string",
|
||||
//"created_in" => "module_name where class is defined",
|
||||
"name_attcode" => "define which attribute is the class name, may be an array of attributes (format specified in the dictionary as 'Class:myclass/Name' => '%1\$s %2\$s...'",
|
||||
"state_attcode" => "define which attribute is representing the state (object lifecycle)",
|
||||
"reconc_keys" => "define the attributes that will 'almost uniquely' identify an object in batch processes",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -605,6 +605,7 @@ body {
|
||||
color:#a00000;
|
||||
}
|
||||
.setup-extension-tag {
|
||||
display: inline-flex;
|
||||
background-color: grey;
|
||||
border-radius: 8px;
|
||||
padding-left: 3px;
|
||||
@@ -681,9 +682,6 @@ body {
|
||||
overflow: auto;
|
||||
text-align: center;
|
||||
}
|
||||
#installation_progress {
|
||||
display: none;
|
||||
}
|
||||
#fresh_content{
|
||||
border: 0;
|
||||
min-height: 300px;
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Combodo\iTop\DBTools\Service;
|
||||
use CMDBSource;
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
use IssueLog;
|
||||
|
||||
class DBToolsUtils
|
||||
{
|
||||
|
||||
@@ -92,7 +92,7 @@ final class CoreUpdater
|
||||
$sFinalEnv = 'production';
|
||||
$oRuntimeEnv = new RunTimeEnvironmentCoreUpdater($sFinalEnv, false);
|
||||
$oRuntimeEnv->CheckDirectories($sFinalEnv);
|
||||
$oRuntimeEnv->CompileFrom('production');
|
||||
$oRuntimeEnv->CompileFrom($sFinalEnv);
|
||||
|
||||
$oRuntimeEnv->Rollback();
|
||||
|
||||
@@ -155,21 +155,13 @@ final class CoreUpdater
|
||||
APPROOT.'extensions',
|
||||
];
|
||||
$aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $aDirsToScanForModules);
|
||||
$aSelectedModules = [];
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule) {
|
||||
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) {
|
||||
continue;
|
||||
} else {
|
||||
$aSelectedModules[] = $sModuleId;
|
||||
}
|
||||
}
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'BeforeDatabaseCreation');
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'BeforeDatabaseCreation');
|
||||
$oRuntimeEnv->CreateDatabaseStructure($oConfig, 'upgrade');
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDatabaseCreation');
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'AfterDatabaseCreation');
|
||||
$oRuntimeEnv->UpdatePredefinedObjects();
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDatabaseSetup');
|
||||
$oRuntimeEnv->LoadData($aAvailableModules, $aSelectedModules, false /* no sample data*/);
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDataLoad');
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'AfterDatabaseSetup');
|
||||
$oRuntimeEnv->LoadData($aAvailableModules, false /* no sample data*/);
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'AfterDataLoad');
|
||||
$sDataModelVersion = $oRuntimeEnv->GetCurrentDataModelVersion();
|
||||
$oExtensionsMap = new iTopExtensionsMap();
|
||||
// Default choices = as before
|
||||
@@ -187,7 +179,7 @@ final class CoreUpdater
|
||||
$oRuntimeEnv->RecordInstallation(
|
||||
$oConfig,
|
||||
$sDataModelVersion,
|
||||
$aSelectedModules,
|
||||
array_keys($aAvailableModules),
|
||||
$aSelectedExtensionCodes,
|
||||
'Done by the iTop Core Updater'
|
||||
);
|
||||
|
||||
@@ -24,129 +24,13 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\JsonPage;
|
||||
use Combodo\iTop\HubConnector\Controller\HubController;
|
||||
|
||||
require_once(APPROOT.'application/utils.inc.php');
|
||||
require_once(APPROOT.'core/log.class.inc.php');
|
||||
IssueLog::Enable(APPROOT.'log/error.log');
|
||||
|
||||
require_once(APPROOT.'setup/runtimeenv.class.inc.php');
|
||||
require_once(APPROOT.'setup/backup.class.inc.php');
|
||||
require_once(APPROOT.'core/mutex.class.inc.php');
|
||||
require_once(APPROOT.'core/dict.class.inc.php');
|
||||
require_once(APPROOT.'setup/xmldataloader.class.inc.php');
|
||||
require_once(__DIR__.'/hubruntimeenvironment.class.inc.php');
|
||||
|
||||
/**
|
||||
* Overload of DBBackup to handle logging
|
||||
*/
|
||||
class DBBackupWithErrorReporting extends DBBackup
|
||||
{
|
||||
protected $aInfos = [];
|
||||
|
||||
protected $aErrors = [];
|
||||
|
||||
protected function LogInfo($sMsg)
|
||||
{
|
||||
$aInfos[] = $sMsg;
|
||||
}
|
||||
|
||||
protected function LogError($sMsg)
|
||||
{
|
||||
IssueLog::Error($sMsg);
|
||||
$aErrors[] = $sMsg;
|
||||
}
|
||||
|
||||
public function GetInfos()
|
||||
{
|
||||
return $this->aInfos;
|
||||
}
|
||||
|
||||
public function GetErrors()
|
||||
{
|
||||
return $this->aErrors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sTargetFile
|
||||
* @throws Exception
|
||||
* @return DBBackupWithErrorReporting
|
||||
*/
|
||||
function DoBackup($sTargetFile)
|
||||
{
|
||||
// Make sure the target directory exists
|
||||
$sBackupDir = dirname($sTargetFile);
|
||||
SetupUtils::builddir($sBackupDir);
|
||||
|
||||
$oBackup = new DBBackupWithErrorReporting();
|
||||
$oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
|
||||
$sSourceConfigFile = APPCONF.utils::GetCurrentEnvironment().'/'.ITOP_CONFIG_FILE;
|
||||
|
||||
$oMutex = new iTopMutex('backup.'.utils::GetCurrentEnvironment());
|
||||
$oMutex->Lock();
|
||||
try {
|
||||
$oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile);
|
||||
} catch (Exception $e) {
|
||||
$oMutex->Unlock();
|
||||
throw $e;
|
||||
}
|
||||
$oMutex->Unlock();
|
||||
return $oBackup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the status of the current ajax execution (as a JSON structure)
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param bool $bSuccess
|
||||
* @param number $iErrorCode
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
function ReportStatus($sMessage, $bSuccess, $iErrorCode = 0, $aMoreFields = [])
|
||||
{
|
||||
// Do not use AjaxPage during setup phases, because it uses InterfaceDiscovery in Twig compilation
|
||||
$oPage = new JsonPage();
|
||||
$aResult = [
|
||||
'code' => $iErrorCode,
|
||||
'message' => $sMessage,
|
||||
'fields' => $aMoreFields,
|
||||
];
|
||||
$oPage->SetData($aResult);
|
||||
$oPage->SetOutputDataOnly(true);
|
||||
$oPage->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to output the status of a successful execution
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
function ReportSuccess($sMessage, $aMoreFields = [])
|
||||
{
|
||||
ReportStatus($sMessage, true, 0, $aMoreFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to output the status of a failed execution
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param number $iErrorCode
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
function ReportError($sMessage, $iErrorCode, $aMoreFields = [])
|
||||
{
|
||||
if ($iErrorCode == 0) {
|
||||
// 0 means no error, so change it if no meaningful error code is supplied
|
||||
$iErrorCode = -1;
|
||||
}
|
||||
ReportStatus($sMessage, false, $iErrorCode, $aMoreFields);
|
||||
}
|
||||
require_once(__DIR__.'/src/Controller/HubController.php');
|
||||
|
||||
try {
|
||||
SetupUtils::ExitMaintenanceMode(false); // Reset maintenance mode in case of problem
|
||||
@@ -183,7 +67,7 @@ try {
|
||||
foreach ($aChecks as $oCheckResult) {
|
||||
if ($oCheckResult->iSeverity == CheckResult::ERROR) {
|
||||
$bFailed = true;
|
||||
ReportError($oCheckResult->sLabel, -2);
|
||||
HubController::GetInstance()->ReportError($oCheckResult->sLabel, -2);
|
||||
}
|
||||
}
|
||||
if (!$bFailed) {
|
||||
@@ -191,169 +75,27 @@ try {
|
||||
$fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
|
||||
if ($fFreeSpace !== false) {
|
||||
$sMessage = Dict::Format('iTopHub:BackupFreeDiskSpaceIn', SetupUtils::HumanReadableSize($fFreeSpace), dirname($sDBBackupPath));
|
||||
ReportSuccess($sMessage);
|
||||
HubController::GetInstance()->ReportSuccess($sMessage);
|
||||
} else {
|
||||
ReportError(Dict::S('iTopHub:FailedToCheckFreeDiskSpace'), -1);
|
||||
HubController::GetInstance()->ReportError(Dict::S('iTopHub:FailedToCheckFreeDiskSpace'), -1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'do_backup':
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
|
||||
|
||||
try {
|
||||
if (MetaModel::GetConfig()->Get('demo_mode')) {
|
||||
throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
}
|
||||
SetupLog::Info('Backup starts...');
|
||||
set_time_limit(0);
|
||||
$sBackupPath = APPROOT.'/data/backups/manual/backup-';
|
||||
$iSuffix = 1;
|
||||
$sSuffix = '';
|
||||
// Generate a unique name...
|
||||
do {
|
||||
$sBackupFile = $sBackupPath.date('Y-m-d-His').$sSuffix;
|
||||
$sSuffix = '-'.$iSuffix;
|
||||
$iSuffix++ ;
|
||||
} while (file_exists($sBackupFile));
|
||||
|
||||
$oBackup = DoBackup($sBackupFile);
|
||||
$aErrors = $oBackup->GetErrors();
|
||||
if (count($aErrors) > 0) {
|
||||
SetupLog::Error('Backup failed.');
|
||||
SetupLog::Error(implode("\n", $aErrors));
|
||||
ReportError(Dict::S('iTopHub:BackupFailed'), -1, $aErrors);
|
||||
} else {
|
||||
SetupLog::Info('Backup successfully completed.');
|
||||
ReportSuccess(Dict::S('iTopHub:BackupOk'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error($e->getMessage());
|
||||
ReportError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
HubController::GetInstance()->LaunchBackup();
|
||||
break;
|
||||
|
||||
case 'compile':
|
||||
SetupLog::Info('Deployment starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent')) {
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
// First step: prepare the datamodel, if it fails, roll-back
|
||||
$aSelectedExtensionCodes = utils::ReadParam('extension_codes', []);
|
||||
$aSelectedExtensionDirs = utils::ReadParam('extension_dirs', []);
|
||||
|
||||
$oRuntimeEnv = new HubRunTimeEnvironment('production', false); // use a temp environment: production-build
|
||||
$oRuntimeEnv->MoveSelectedExtensions(APPROOT.'/data/downloaded-extensions/', $aSelectedExtensionDirs);
|
||||
|
||||
$oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE);
|
||||
if ($oConfig->Get('demo_mode')) {
|
||||
throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
}
|
||||
|
||||
$aSelectModules = $oRuntimeEnv->CompileFrom('production', false); // WARNING symlinks does not seem to be compatible with manual Commit
|
||||
|
||||
$oRuntimeEnv->UpdateIncludes($oConfig);
|
||||
|
||||
$oRuntimeEnv->InitDataModel($oConfig, true /* model only */);
|
||||
|
||||
// Safety check: check the inter dependencies, will throw an exception in case of inconsistency
|
||||
$oRuntimeEnv->AnalyzeInstallation($oConfig, $oRuntimeEnv->GetBuildDir(), true);
|
||||
|
||||
$oRuntimeEnv->CheckMetaModel(); // Will throw an exception if a problem is detected
|
||||
|
||||
// Everything seems Ok so far, commit in env-production!
|
||||
$oRuntimeEnv->WriteConfigFileSafe($oConfig);
|
||||
$oRuntimeEnv->Commit();
|
||||
|
||||
// Report the success in a way that will be detected by the ajax caller
|
||||
SetupLog::Info('Compilation completed...');
|
||||
ReportSuccess('Ok'); // No access to Dict::S here
|
||||
HubController::GetInstance()->LaunchCompile();
|
||||
break;
|
||||
|
||||
case 'move_to_production':
|
||||
// Second step: update the schema and the data
|
||||
// Everything happening below is based on env-production
|
||||
$oRuntimeEnv = new RunTimeEnvironment('production', true);
|
||||
|
||||
try {
|
||||
SetupLog::Info('Move to production starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent')) {
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
// Load the "production" config file to clone & update it
|
||||
$oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE);
|
||||
SetupUtils::EnterReadOnlyMode($oConfig);
|
||||
|
||||
$oRuntimeEnv->InitDataModel($oConfig, true /* model only */);
|
||||
|
||||
$aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $oRuntimeEnv->GetBuildDir(), true);
|
||||
|
||||
$aSelectedModules = [];
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule) {
|
||||
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) {
|
||||
continue;
|
||||
} else {
|
||||
$aSelectedModules[] = $sModuleId;
|
||||
}
|
||||
}
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'BeforeDatabaseCreation');
|
||||
|
||||
$oRuntimeEnv->CreateDatabaseStructure($oConfig, 'upgrade');
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDatabaseCreation');
|
||||
|
||||
$oRuntimeEnv->UpdatePredefinedObjects();
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDatabaseSetup');
|
||||
|
||||
$oRuntimeEnv->LoadData($aAvailableModules, $aSelectedModules, false /* no sample data*/);
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDataLoad');
|
||||
|
||||
// Record the installation so that the "about box" knows about the installed modules
|
||||
$sDataModelVersion = $oRuntimeEnv->GetCurrentDataModelVersion();
|
||||
|
||||
$oExtensionsMap = new iTopExtensionsMap();
|
||||
|
||||
// Default choices = as before
|
||||
$oExtensionsMap->LoadChoicesFromDatabase($oConfig);
|
||||
foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) {
|
||||
// Plus all "remote" extensions
|
||||
if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE) {
|
||||
$oExtensionsMap->MarkAsChosen($oExtension->sCode);
|
||||
}
|
||||
}
|
||||
$aSelectedExtensionCodes = [];
|
||||
foreach ($oExtensionsMap->GetChoices() as $oExtension) {
|
||||
$aSelectedExtensionCodes[] = $oExtension->sCode;
|
||||
}
|
||||
$aSelectedExtensions = $oExtensionsMap->GetChoices();
|
||||
$oRuntimeEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModules, $aSelectedExtensionCodes, 'Done by the iTop Hub Connector');
|
||||
|
||||
// Report the success in a way that will be detected by the ajax caller
|
||||
SetupLog::Info('Deployment successfully completed.');
|
||||
ReportSuccess(Dict::S('iTopHub:CompiledOK'));
|
||||
} catch (Exception $e) {
|
||||
if (file_exists(utils::GetDataPath().'hub/compile_authent')) {
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
}
|
||||
// Note: at this point, the dictionnary is not necessarily loaded
|
||||
SetupLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage());
|
||||
SetupLog::Error('Debug trace: '.$e->getTraceAsString());
|
||||
ReportError($e->getMessage(), $e->getCode());
|
||||
} finally {
|
||||
SetupUtils::ExitReadOnlyMode();
|
||||
}
|
||||
HubController::GetInstance()->LaunchDeploy();
|
||||
break;
|
||||
|
||||
default:
|
||||
ReportError("Invalid operation: '$sOperation'", -1);
|
||||
HubController::GetInstance()->ReportError("Invalid operation: '$sOperation'", -1);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage());
|
||||
@@ -361,5 +103,5 @@ try {
|
||||
|
||||
utils::PopArchiveMode();
|
||||
|
||||
ReportError($e->getMessage(), $e->getCode());
|
||||
HubController::GetInstance()->ReportError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ function collect_configuration()
|
||||
|
||||
// iTop modules
|
||||
$oConfig = MetaModel::GetConfig();
|
||||
$aInstalledModules = ModuleInstallationService::GetInstance()->ReadFromDB($oConfig);
|
||||
$aInstalledModules = ModuleInstallationRepository::GetInstance()->ReadFromDB($oConfig);
|
||||
|
||||
foreach ($aInstalledModules as $aDBInfo) {
|
||||
$aConfiguration['itop_modules'][$aDBInfo['name']] = $aDBInfo['version'];
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\HubConnector\Controller;
|
||||
|
||||
use Combodo\iTop\Application\WebPage\JsonPage;
|
||||
use Combodo\iTop\HubConnector\Model\DBBackupWithErrorReporting;
|
||||
use Combodo\iTop\HubConnector\setup\HubRunTimeEnvironment;
|
||||
use Config;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use iTopExtension;
|
||||
use iTopExtensionsMap;
|
||||
use iTopMutex;
|
||||
use LoginWebPage;
|
||||
use MetaModel;
|
||||
use MFCompiler;
|
||||
use RunTimeEnvironment;
|
||||
use SecurityException;
|
||||
use SetupLog;
|
||||
use SetupUtils;
|
||||
use utils;
|
||||
|
||||
require_once(APPROOT.'setup/runtimeenv.class.inc.php');
|
||||
require_once(APPROOT.'setup/backup.class.inc.php');
|
||||
require_once(APPROOT.'core/mutex.class.inc.php');
|
||||
require_once(APPROOT.'core/dict.class.inc.php');
|
||||
require_once(APPROOT.'setup/xmldataloader.class.inc.php');
|
||||
require_once(__DIR__.'/../setup/hubruntimeenvironment.class.inc.php');
|
||||
|
||||
class HubController
|
||||
{
|
||||
private static HubController $oInstance;
|
||||
protected $bOutputHeaders = false;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): HubController
|
||||
{
|
||||
if (!isset(self::$oInstance)) {
|
||||
self::$oInstance = new HubController();
|
||||
}
|
||||
|
||||
return self::$oInstance;
|
||||
}
|
||||
|
||||
final public static function SetInstance(?HubController $oInstance): void
|
||||
{
|
||||
self::$oInstance = $oInstance;
|
||||
}
|
||||
|
||||
public function LaunchBackup()
|
||||
{
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
|
||||
|
||||
try {
|
||||
if (MetaModel::GetConfig()->Get('demo_mode')) {
|
||||
throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
}
|
||||
SetupLog::Info('Backup starts...');
|
||||
set_time_limit(0);
|
||||
$sBackupPath = APPROOT.'/data/backups/manual/backup-';
|
||||
$iSuffix = 1;
|
||||
$sSuffix = '';
|
||||
// Generate a unique name...
|
||||
do {
|
||||
$sBackupFile = $sBackupPath.date('Y-m-d-His').$sSuffix;
|
||||
$sSuffix = '-'.$iSuffix;
|
||||
$iSuffix++ ;
|
||||
} while (file_exists($sBackupFile));
|
||||
|
||||
$oBackup = $this->DoBackup($sBackupFile);
|
||||
$aErrors = $oBackup->GetErrors();
|
||||
if (count($aErrors) > 0) {
|
||||
SetupLog::Error('Backup failed.');
|
||||
SetupLog::Error(implode("\n", $aErrors));
|
||||
$this->ReportError(Dict::S('iTopHub:BackupFailed'), -1, $aErrors);
|
||||
} else {
|
||||
SetupLog::Info('Backup successfully completed.');
|
||||
$this->ReportSuccess(Dict::S('iTopHub:BackupOk'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error($e->getMessage());
|
||||
$this->ReportError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sTargetFile
|
||||
* @throws Exception
|
||||
* @return DBBackupWithErrorReporting
|
||||
*/
|
||||
public function DoBackup($sTargetFile): DBBackupWithErrorReporting
|
||||
{
|
||||
// Make sure the target directory exists
|
||||
$sBackupDir = dirname($sTargetFile);
|
||||
SetupUtils::builddir($sBackupDir);
|
||||
|
||||
$oBackup = new DBBackupWithErrorReporting();
|
||||
$oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
|
||||
$sSourceConfigFile = APPCONF.utils::GetCurrentEnvironment().'/'.ITOP_CONFIG_FILE;
|
||||
|
||||
$oMutex = new iTopMutex('backup.'.utils::GetCurrentEnvironment());
|
||||
$oMutex->Lock();
|
||||
try {
|
||||
$oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile);
|
||||
} catch (Exception $e) {
|
||||
$oMutex->Unlock();
|
||||
throw $e;
|
||||
}
|
||||
$oMutex->Unlock();
|
||||
return $oBackup;
|
||||
}
|
||||
|
||||
public function LaunchCompile()
|
||||
{
|
||||
SetupLog::Info('Deployment starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent')) {
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
// First step: prepare the datamodel, if it fails, roll-back
|
||||
$aSelectedExtensionCodes = utils::ReadParam('extension_codes', []);
|
||||
$aSelectedExtensionDirs = utils::ReadParam('extension_dirs', []);
|
||||
|
||||
$oRuntimeEnv = new HubRunTimeEnvironment('production', false); // use a temp environment: production-build
|
||||
$oRuntimeEnv->MoveSelectedExtensions(APPROOT.'/data/downloaded-extensions/', $aSelectedExtensionDirs);
|
||||
|
||||
$oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE);
|
||||
if ($oConfig->Get('demo_mode')) {
|
||||
throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
}
|
||||
|
||||
$aSelectModules = $oRuntimeEnv->CompileFrom('production'); // WARNING symlinks does not seem to be compatible with manual Commit
|
||||
|
||||
$oRuntimeEnv->UpdateIncludes($oConfig);
|
||||
|
||||
$oRuntimeEnv->InitDataModel($oConfig, true /* model only */);
|
||||
|
||||
// Safety check: check the inter dependencies, will throw an exception in case of inconsistency
|
||||
$oRuntimeEnv->AnalyzeInstallation($oConfig, $oRuntimeEnv->GetBuildDir(), true);
|
||||
|
||||
$oRuntimeEnv->CheckMetaModel(); // Will throw an exception if a problem is detected
|
||||
|
||||
// Everything seems Ok so far, commit in env-production!
|
||||
$oRuntimeEnv->WriteConfigFileSafe($oConfig);
|
||||
$oRuntimeEnv->Commit();
|
||||
|
||||
// Report the success in a way that will be detected by the ajax caller
|
||||
SetupLog::Info('Compilation completed...');
|
||||
|
||||
$this->ReportSuccess('Ok'); // No access to Dict::S here
|
||||
}
|
||||
|
||||
public function LaunchDeploy()
|
||||
{
|
||||
// Second step: update the schema and the data
|
||||
// Everything happening below is based on env-production
|
||||
$oRuntimeEnv = new RunTimeEnvironment('production', true);
|
||||
|
||||
try {
|
||||
SetupLog::Info('Move to production starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent')) {
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
// Load the "production" config file to clone & update it
|
||||
$oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE);
|
||||
SetupUtils::EnterReadOnlyMode($oConfig);
|
||||
|
||||
$oRuntimeEnv->InitDataModel($oConfig, true /* model only */);
|
||||
|
||||
$aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $oRuntimeEnv->GetBuildDir(), true);
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'BeforeDatabaseCreation');
|
||||
|
||||
$oRuntimeEnv->CreateDatabaseStructure($oConfig, 'upgrade');
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'AfterDatabaseCreation');
|
||||
|
||||
$oRuntimeEnv->UpdatePredefinedObjects();
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'AfterDatabaseSetup');
|
||||
|
||||
$oRuntimeEnv->LoadData($aAvailableModules, false /* no sample data*/);
|
||||
|
||||
$oRuntimeEnv->CallInstallerHandlers($aAvailableModules, 'AfterDataLoad');
|
||||
|
||||
// Record the installation so that the "about box" knows about the installed modules
|
||||
$sDataModelVersion = $oRuntimeEnv->GetCurrentDataModelVersion();
|
||||
|
||||
$oExtensionsMap = new iTopExtensionsMap();
|
||||
|
||||
// Default choices = as before
|
||||
$oExtensionsMap->LoadChoicesFromDatabase($oConfig);
|
||||
foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) {
|
||||
// Plus all "remote" extensions
|
||||
if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE) {
|
||||
$oExtensionsMap->MarkAsChosen($oExtension->sCode);
|
||||
}
|
||||
}
|
||||
$aSelectedExtensionCodes = [];
|
||||
foreach ($oExtensionsMap->GetChoices() as $oExtension) {
|
||||
$aSelectedExtensionCodes[] = $oExtension->sCode;
|
||||
}
|
||||
$aSelectedExtensions = $oExtensionsMap->GetChoices();
|
||||
$oRuntimeEnv->RecordInstallation($oConfig, $sDataModelVersion, array_keys($aAvailableModules), $aSelectedExtensionCodes, 'Done by the iTop Hub Connector');
|
||||
|
||||
// Report the success in a way that will be detected by the ajax caller
|
||||
SetupLog::Info('Deployment successfully completed.');
|
||||
$this->ReportSuccess(Dict::S('iTopHub:CompiledOK'));
|
||||
} catch (Exception $e) {
|
||||
if (file_exists(utils::GetDataPath().'hub/compile_authent')) {
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
}
|
||||
// Note: at this point, the dictionnary is not necessarily loaded
|
||||
SetupLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage());
|
||||
SetupLog::Error('Debug trace: '.$e->getTraceAsString());
|
||||
$this->ReportError($e->getMessage(), $e->getCode());
|
||||
} finally {
|
||||
SetupUtils::ExitReadOnlyMode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the status of the current ajax execution (as a JSON structure)
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param bool $bSuccess
|
||||
* @param number $iErrorCode
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
public function ReportStatus($sMessage, $bSuccess, $iErrorCode = 0, $aMoreFields = [])
|
||||
{
|
||||
// Do not use AjaxPage during setup phases, because it uses InterfaceDiscovery in Twig compilation
|
||||
$this->oLastJsonPage = new JsonPage();
|
||||
$this->oLastJsonPage->SetOutputHeaders($this->bOutputHeaders);
|
||||
$aResult = [
|
||||
'code' => $iErrorCode,
|
||||
'message' => $sMessage,
|
||||
'fields' => $aMoreFields,
|
||||
];
|
||||
$this->oLastJsonPage->SetData($aResult);
|
||||
$this->oLastJsonPage->SetOutputDataOnly(true);
|
||||
$this->oLastJsonPage->output();
|
||||
}
|
||||
|
||||
private ?JsonPage $oLastJsonPage = null;
|
||||
|
||||
public function GetLastJsonPage(): ?JsonPage
|
||||
{
|
||||
return $this->oLastJsonPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to output the status of a successful execution
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
public function ReportSuccess($sMessage, $aMoreFields = [])
|
||||
{
|
||||
$this->ReportStatus($sMessage, true, 0, $aMoreFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to output the status of a failed execution
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param number $iErrorCode
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
public function ReportError($sMessage, $iErrorCode, $aMoreFields = [])
|
||||
{
|
||||
if ($iErrorCode == 0) {
|
||||
// 0 means no error, so change it if no meaningful error code is supplied
|
||||
$iErrorCode = -1;
|
||||
}
|
||||
$this->ReportStatus($sMessage, false, $iErrorCode, $aMoreFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dont print headers for testing purpose mainly
|
||||
* @param bool bOutputHeaders
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function SetOutputHeaders(bool $bOutputHeaders): void
|
||||
{
|
||||
$this->bOutputHeaders = $bOutputHeaders;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\HubConnector\Model;
|
||||
|
||||
use DBBackup;
|
||||
use IssueLog;
|
||||
|
||||
/**
|
||||
* Overload of DBBackup to handle logging
|
||||
*/
|
||||
class DBBackupWithErrorReporting extends DBBackup
|
||||
{
|
||||
protected $aInfos = [];
|
||||
|
||||
protected $aErrors = [];
|
||||
|
||||
protected function LogInfo($sMsg)
|
||||
{
|
||||
$this->aInfos[] = $sMsg;
|
||||
}
|
||||
|
||||
protected function LogError($sMsg)
|
||||
{
|
||||
IssueLog::Error($sMsg);
|
||||
$this->aErrors[] = $sMsg;
|
||||
}
|
||||
|
||||
public function GetInfos(): array
|
||||
{
|
||||
return $this->aInfos;
|
||||
}
|
||||
|
||||
public function GetErrors(): array
|
||||
{
|
||||
return $this->aErrors;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\HubConnector\setup;
|
||||
|
||||
use Config;
|
||||
use Exception;
|
||||
use RunTimeEnvironment;
|
||||
use SetupUtils;
|
||||
|
||||
class HubRunTimeEnvironment extends RunTimeEnvironment
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $sEnvironment
|
||||
* @param string $bAutoCommit
|
||||
*/
|
||||
@@ -24,6 +32,7 @@ class HubRunTimeEnvironment extends RunTimeEnvironment
|
||||
|
||||
/**
|
||||
* Update the includes for the target environment
|
||||
*
|
||||
* @param Config $oConfig
|
||||
*/
|
||||
public function UpdateIncludes(Config $oConfig)
|
||||
@@ -33,7 +42,9 @@ class HubRunTimeEnvironment extends RunTimeEnvironment
|
||||
|
||||
/**
|
||||
* Move an extension (path to folder of this extension) to the target environment
|
||||
*
|
||||
* @param string $sExtensionDirectory The folder of the extension
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MoveExtension($sExtensionDirectory)
|
||||
@@ -57,8 +68,10 @@ class HubRunTimeEnvironment extends RunTimeEnvironment
|
||||
|
||||
/**
|
||||
* Move the selected extensions located in the given directory in data/<target-env>-modules
|
||||
*
|
||||
* @param string $sDownloadedExtensionsDir The directory to scan
|
||||
* @param string[] $aSelectedExtensionDirs The list of folders to move
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function MoveSelectedExtensions($sDownloadedExtensionsDir, $aSelectedExtensionDirs)
|
||||
@@ -12,8 +12,7 @@ SetupWebPage::AddModule(
|
||||
// Setup
|
||||
//
|
||||
'dependencies' => [
|
||||
'itop-structure/2.7.1',
|
||||
'itop-portal/3.0.0', // module_design_itop_design->module_designs->itop-portal
|
||||
'itop-structure/2.7.1 || itop-portal/3.0.0', // itop-portal : module_design_itop_design->module_designs->itop-portal
|
||||
],
|
||||
'mandatory' => false,
|
||||
'visible' => true,
|
||||
|
||||
14
setup/SetupDBBackup.php
Normal file
14
setup/SetupDBBackup.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class SetupDBBackup extends DBBackup
|
||||
{
|
||||
protected function LogInfo($sMsg)
|
||||
{
|
||||
SetupLog::Ok('Info - '.$sMsg);
|
||||
}
|
||||
|
||||
protected function LogError($sMsg)
|
||||
{
|
||||
SetupLog::Ok('Error - '.$sMsg);
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ header("Expires: Fri, 17 Jul 1970 05:00:00 GMT"); // Date in the past
|
||||
/**
|
||||
* Main program
|
||||
*/
|
||||
$sOperation = Utils::ReadParam('operation', '');
|
||||
$sOperation = utils::ReadParam('operation', '');
|
||||
try {
|
||||
SetupUtils::CheckSetupToken();
|
||||
|
||||
@@ -139,7 +139,6 @@ try {
|
||||
ini_set('display_startup_errors', true);
|
||||
|
||||
require_once(APPROOT.'/setup/wizardcontroller.class.inc.php');
|
||||
require_once(APPROOT.'/setup/wizardsteps.class.inc.php');
|
||||
|
||||
$sClass = utils::ReadParam('step_class', '');
|
||||
$sState = utils::ReadParam('step_state', '');
|
||||
@@ -164,7 +163,7 @@ try {
|
||||
break;
|
||||
|
||||
case 'toggle_use_symbolic_links':
|
||||
$sUseSymbolicLinks = Utils::ReadParam('bUseSymbolicLinks', false);
|
||||
$sUseSymbolicLinks = utils::ReadParam('bUseSymbolicLinks', false);
|
||||
$bUseSymbolicLinks = ($sUseSymbolicLinks === 'true');
|
||||
MFCompiler::SetUseSymbolicLinksFlag($bUseSymbolicLinks);
|
||||
echo "toggle useSymbolicLinks flag : $bUseSymbolicLinks";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,8 +21,8 @@
|
||||
use Combodo\iTop\Application\Branding;
|
||||
use Combodo\iTop\Application\WebPage\iTopWebPage;
|
||||
use Combodo\iTop\Application\WebPage\Page;
|
||||
use Combodo\iTop\DesignElement;
|
||||
use Combodo\iTop\DesignDocument;
|
||||
use Combodo\iTop\DesignElement;
|
||||
|
||||
require_once(APPROOT.'setup/setuputils.class.inc.php');
|
||||
require_once(APPROOT.'setup/modelfactory.class.inc.php');
|
||||
@@ -477,7 +477,7 @@ class MFCompiler
|
||||
$sClass = $oClass->getAttribute("id");
|
||||
$aAllClasses[] = $sClass;
|
||||
try {
|
||||
$sCompiledCode .= $this->CompileClass($oClass, $sModuleName, $sTempTargetDir, $sFinalTargetDir, $sRelativeDir);
|
||||
$sCompiledCode .= $this->CompileClass($oClass, $sTempTargetDir, $sFinalTargetDir, $sRelativeDir);
|
||||
} catch (DOMFormatException $e) {
|
||||
$sMessage = "Failed to process class '$sClass', ";
|
||||
if (!empty($sModuleRootDir)) {
|
||||
@@ -1189,7 +1189,6 @@ EOF
|
||||
|
||||
/**
|
||||
* @param \MFElement $oClass
|
||||
* @param string $sModuleName
|
||||
* @param string $sTempTargetDir
|
||||
* @param string $sFinalTargetDir
|
||||
* @param string $sModuleRelativeDir
|
||||
@@ -1197,7 +1196,7 @@ EOF
|
||||
* @return string
|
||||
* @throws \DOMFormatException
|
||||
*/
|
||||
protected function CompileClass($oClass, $sModuleName, $sTempTargetDir, $sFinalTargetDir, $sModuleRelativeDir)
|
||||
protected function CompileClass($oClass, $sTempTargetDir, $sFinalTargetDir, $sModuleRelativeDir)
|
||||
{
|
||||
$sClass = $oClass->getAttribute('id');
|
||||
$oProperties = $oClass->GetUniqueElement('properties');
|
||||
@@ -1210,7 +1209,6 @@ EOF
|
||||
$aClassParams = [];
|
||||
$aClassParams['category'] = $this->GetPropString($oProperties, 'category', '');
|
||||
$aClassParams['key_type'] = "'autoincrement'";
|
||||
$aClassParams['created_in'] = "'$sModuleName'";
|
||||
if ((bool)$this->GetPropNumber($oProperties, 'is_link', 0)) {
|
||||
$aClassParams['is_link'] = 'true';
|
||||
}
|
||||
@@ -3359,6 +3357,8 @@ EOF;
|
||||
|
||||
$bDataXmlPrecompiledFileExists = false;
|
||||
clearstatcache();
|
||||
|
||||
$iDataXmlFileLastModified = 0;
|
||||
if (!empty($sPrecompiledFileUri)) {
|
||||
$sDataXmlProvidedPrecompiledFile = $sTempTargetDir.DIRECTORY_SEPARATOR.$sPrecompiledFileUri;
|
||||
$bDataXmlPrecompiledFileExists = file_exists($sDataXmlProvidedPrecompiledFile) ;
|
||||
|
||||
@@ -34,7 +34,7 @@ require_once(APPROOT.'/application/startup.inc.php');
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
|
||||
|
||||
$sOperation = Utils::ReadParam('operation', 'step1');
|
||||
$sOperation = utils::ReadParam('operation', 'step1');
|
||||
$oP = new SetupPage('iTop email test utility');
|
||||
|
||||
// Although this page doesn't expose sensitive info, with it we can send multiple emails
|
||||
@@ -208,7 +208,7 @@ function DisplayStep2(SetupPage $oP, $sFrom, $sTo)
|
||||
$oP->add("<p>Sending an email to '".htmlentities($sTo, ENT_QUOTES, 'utf-8')."'... (From: '".htmlentities($sFrom, ENT_QUOTES, 'utf-8')."')</p>\n");
|
||||
$oP->add("<form method=\"post\">\n");
|
||||
|
||||
$oEmail = new Email();
|
||||
$oEmail = new EMail();
|
||||
$oEmail->SetRecipientTO($sTo);
|
||||
$oEmail->SetRecipientFrom($sFrom);
|
||||
$oEmail->SetSubject("Test iTop");
|
||||
@@ -256,8 +256,8 @@ try {
|
||||
|
||||
case 'step2':
|
||||
$oP->no_cache();
|
||||
$sTo = Utils::ReadParam('to', '', false, 'raw_data');
|
||||
$sFrom = Utils::ReadParam('from', '', false, 'raw_data');
|
||||
$sTo = utils::ReadParam('to', '', false, 'raw_data');
|
||||
$sFrom = utils::ReadParam('from', '', false, 'raw_data');
|
||||
DisplayStep2($oP, $sFrom, $sTo);
|
||||
break;
|
||||
|
||||
|
||||
@@ -3,143 +3,11 @@
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReader;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReaderException;
|
||||
|
||||
require_once(APPROOT.'/setup/itopextension.class.inc.php');
|
||||
require_once(APPROOT.'/setup/parameters.class.inc.php');
|
||||
require_once(APPROOT.'/core/cmdbsource.class.inc.php');
|
||||
require_once(APPROOT.'/setup/modulediscovery.class.inc.php');
|
||||
require_once(APPROOT.'/setup/moduleinstaller.class.inc.php');
|
||||
/**
|
||||
* Basic helper class to describe an extension, with some characteristics and a list of modules
|
||||
*/
|
||||
class iTopExtension
|
||||
{
|
||||
public const SOURCE_WIZARD = 'datamodels';
|
||||
public const SOURCE_MANUAL = 'extensions';
|
||||
public const SOURCE_REMOTE = 'data';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sCode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sVersion;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sInstalledVersion;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sLabel;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sDescription;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sSource;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $bMandatory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sMoreInfoUrl;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $bMarkedAsChosen;
|
||||
/**
|
||||
* If null, check if at least one module cannot be uninstalled
|
||||
* @var bool|null
|
||||
*/
|
||||
public ?bool $bCanBeUninstalled = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $bVisible;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $aModules;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $aModuleVersion;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $aModuleInfo;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sSourceDir;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $aMissingDependencies;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public bool $bInstalled = false;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public bool $bRemovedFromDisk = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->sCode = '';
|
||||
$this->sLabel = '';
|
||||
$this->sDescription = '';
|
||||
$this->sSource = self::SOURCE_WIZARD;
|
||||
$this->bMandatory = false;
|
||||
$this->sMoreInfoUrl = '';
|
||||
$this->bMarkedAsChosen = false;
|
||||
$this->sVersion = ITOP_VERSION;
|
||||
$this->sInstalledVersion = '';
|
||||
$this->aModules = [];
|
||||
$this->aModuleVersion = [];
|
||||
$this->aModuleInfo = [];
|
||||
$this->sSourceDir = '';
|
||||
$this->bVisible = true;
|
||||
$this->aMissingDependencies = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.3.0
|
||||
* @return bool
|
||||
*/
|
||||
public function CanBeUninstalled(): bool
|
||||
{
|
||||
if (!is_null($this->bCanBeUninstalled)) {
|
||||
return $this->bCanBeUninstalled;
|
||||
}
|
||||
foreach ($this->aModuleInfo as $sModuleCode => $aModuleInfo) {
|
||||
$this->bCanBeUninstalled = $aModuleInfo['uninstallable'] === 'yes';
|
||||
return $this->bCanBeUninstalled;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to discover all available extensions on a given iTop system
|
||||
@@ -308,28 +176,26 @@ class iTopExtensionsMap
|
||||
return $this->aExtensionsByCode[$sExtensionCode] ?? null;
|
||||
}
|
||||
|
||||
/*public function GetMissingExtensions(array $aSelectedExtensions)
|
||||
/**
|
||||
* @param array<string> $aExtensionCodes
|
||||
* @return void
|
||||
*/
|
||||
public function DeclareExtensionAsRemoved(array $aExtensionCodes): void
|
||||
{
|
||||
\SetupLog::Info(__METHOD__, null, ['selected' => $aSelectedExtensions]);
|
||||
$aExtensionsFromDb = array_keys($this->aExtensionsByCode);
|
||||
sort($aExtensionsFromDb);
|
||||
\SetupLog::Info(__METHOD__, null, ['found' => $aExtensionsFromDb]);
|
||||
|
||||
$aRes = [];
|
||||
foreach (array_diff($aExtensionsFromDb, $aSelectedExtensions) as $sExtensionCode) {
|
||||
$oExtension = $this->GetFromExtensionCode($sExtensionCode);
|
||||
if (!is_null($oExtension) && $oExtension->bVisible && $oExtension->sSource != iTopExtension::SOURCE_WIZARD) {
|
||||
|
||||
\SetupLog::Info(__METHOD__."$sExtensionCode", null, ['visible' => $oExtension->bVisible, 'mandatory' => $oExtension->bMandatory]);
|
||||
$aRes [] = $sExtensionCode;
|
||||
$aRemovedExtension = [];
|
||||
foreach ($aExtensionCodes as $sCode) {
|
||||
/** @var \iTopExtension $oExtension */
|
||||
$oExtension = $this->GetFromExtensionCode($sCode);
|
||||
if (!is_null($oExtension)) {
|
||||
$aRemovedExtension [] = $oExtension;
|
||||
\IssueLog::Info(__METHOD__.": remove extension locally", null, ['extension_code' => $oExtension->sCode]);
|
||||
} else {
|
||||
\SetupLog::Info(__METHOD__." MISSING $sExtensionCode");
|
||||
\IssueLog::Warning(__METHOD__." cannot find extensions", null, ['code' => $sCode]);
|
||||
}
|
||||
}
|
||||
\SetupLog::Info(__METHOD__, null, $aRes);
|
||||
|
||||
return $aRes;
|
||||
}*/
|
||||
ModuleDiscovery::DeclareRemovedExtensions($aRemovedExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read (recursively) a directory to find if it contains extensions (or modules)
|
||||
@@ -463,7 +329,7 @@ class iTopExtensionsMap
|
||||
$aSearchDirs = array_merge($aSearchDirs, $this->aScannedDirs);
|
||||
|
||||
try {
|
||||
ModuleDiscovery::GetAvailableModules($aSearchDirs, true);
|
||||
ModuleDiscovery::GetModulesOrderedByDependencies($aSearchDirs, true);
|
||||
} catch (MissingDependencyException $e) {
|
||||
// Some modules have missing dependencies
|
||||
// Let's check what is the impact at the "extensions" level
|
||||
@@ -503,6 +369,75 @@ class iTopExtensionsMap
|
||||
return array_merge($this->aInstalledExtensions ?? [], $this->aExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bKeepMissingDependencyExtensions
|
||||
*
|
||||
* @return array<\iTopExtension>>
|
||||
*/
|
||||
|
||||
public function GetAllExtensionsToDisplayInSetup(bool $bKeepMissingDependencyExtensions = false): 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) {
|
||||
$oExtension->bMandatory = ($oExtension->sSource === iTopExtension::SOURCE_REMOTE);
|
||||
}
|
||||
$aRes[$oExtension->sCode] = $oExtension;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aRes;
|
||||
}
|
||||
|
||||
public function GetAllExtensionsOptionInfo(): array
|
||||
{
|
||||
$aRes = [];
|
||||
foreach ($this->GetAllExtensionsToDisplayInSetup() as $sCode => $oExtension) {
|
||||
$aRes[] = [
|
||||
'extension_code' => $oExtension->sCode,
|
||||
'title' => $oExtension->sLabel,
|
||||
'description' => $oExtension->sDescription,
|
||||
'more_info' => $oExtension->sMoreInfoUrl,
|
||||
'default' => true, // by default offer to install all modules
|
||||
'modules' => $oExtension->aModules,
|
||||
'mandatory' => $oExtension->bMandatory,
|
||||
'source_label' => $this->GetExtensionSourceLabel($oExtension->sSource),
|
||||
'uninstallable' => $oExtension->CanBeUninstalled(),
|
||||
'missing' => $oExtension->bRemovedFromDisk,
|
||||
];
|
||||
}
|
||||
|
||||
return $aRes;
|
||||
}
|
||||
|
||||
protected function GetExtensionSourceLabel($sSource)
|
||||
{
|
||||
$sDecorationClass = '';
|
||||
switch ($sSource) {
|
||||
case iTopExtension::SOURCE_MANUAL:
|
||||
$sResult = 'Local extensions folder';
|
||||
$sDecorationClass = 'fas fa-folder';
|
||||
break;
|
||||
|
||||
case iTopExtension::SOURCE_REMOTE:
|
||||
$sResult = (ITOP_APPLICATION == 'iTop') ? 'iTop Hub' : 'ITSM Designer';
|
||||
$sDecorationClass = (ITOP_APPLICATION == 'iTop') ? 'fc fc-chameleon-icon' : 'fa pencil-ruler';
|
||||
break;
|
||||
|
||||
default:
|
||||
$sResult = '';
|
||||
}
|
||||
if ($sResult == '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '<i class="setup-extension--icon '.$sDecorationClass.'" data-tooltip-content="'.$sResult.'"></i>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given extension as chosen
|
||||
* @param string $sExtensionCode The code of the extension (code without version number)
|
||||
@@ -588,7 +523,7 @@ class iTopExtensionsMap
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function LoadInstalledExtensionsFromDatabase(Config $oConfig): array|false
|
||||
public function LoadInstalledExtensionsFromDatabase(Config $oConfig): array|false
|
||||
{
|
||||
try {
|
||||
if (CMDBSource::DBName() === null) {
|
||||
@@ -631,6 +566,27 @@ class iTopExtensionsMap
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetChoicesFromDatabase(Config $oConfig): array|false
|
||||
{
|
||||
try {
|
||||
if (CMDBSource::DBName() === null) {
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
}
|
||||
$sLatestInstallationDate = CMDBSource::QueryToScalar("SELECT max(installed) FROM ".$oConfig->Get('db_subname')."priv_extension_install");
|
||||
$aDBInfo = CMDBSource::QueryToArray("SELECT * FROM ".$oConfig->Get('db_subname')."priv_extension_install WHERE installed = '".$sLatestInstallationDate."'");
|
||||
|
||||
$aChoices = [];
|
||||
foreach ($aDBInfo as $aExtensionInfo) {
|
||||
$aChoices[] = $aExtensionInfo['code'];
|
||||
}
|
||||
|
||||
return $aChoices;
|
||||
} catch (MySQLException $e) {
|
||||
// No database or erroneous information
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the given module name is "chosen" since it is part of a "chosen" extension (in the specified source dir)
|
||||
* @param string $sModuleNameToFind
|
||||
|
||||
105
setup/feature_removal/AbstractSetupAudit.php
Normal file
105
setup/feature_removal/AbstractSetupAudit.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Setup\FeatureRemoval;
|
||||
|
||||
use ContextTag;
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
use IssueLog;
|
||||
use MetaModel;
|
||||
use SetupLog;
|
||||
|
||||
require_once APPROOT.'setup/feature_removal/ModelReflectionSerializer.php';
|
||||
|
||||
abstract class AbstractSetupAudit
|
||||
{
|
||||
protected bool $bClassesInitialized = false;
|
||||
protected array $aClassesBefore = [];
|
||||
protected array $aClassesAfter = [];
|
||||
protected array $aRemovedClasses = [];
|
||||
protected array $aFinalClassesToCleanup = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
abstract public function ComputeClasses(): void;
|
||||
|
||||
public function GetRemovedClasses(): array
|
||||
{
|
||||
$this->ComputeClasses();
|
||||
|
||||
if (count($this->aRemovedClasses) == 0) {
|
||||
if (count($this->aClassesBefore) == 0) {
|
||||
return $this->aRemovedClasses;
|
||||
}
|
||||
|
||||
if (count($this->aClassesAfter) == 0) {
|
||||
return $this->aRemovedClasses;
|
||||
}
|
||||
|
||||
$aExtensionsNames = array_diff($this->aClassesBefore, $this->aClassesAfter);
|
||||
$this->aRemovedClasses = [];
|
||||
$aClasses = array_values($aExtensionsNames);
|
||||
sort($aClasses);
|
||||
|
||||
foreach ($aClasses as $i => $sClass) {
|
||||
$this->aRemovedClasses[] = $sClass;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->aRemovedClasses;
|
||||
}
|
||||
|
||||
public function GetIssues(bool $bStopDataCheckAtFirstIssue = false): array
|
||||
{
|
||||
$this->aFinalClassesToCleanup = [];
|
||||
|
||||
foreach ($this->GetRemovedClasses() as $sClass) {
|
||||
if (MetaModel::IsAbstract($sClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!MetaModel::IsStandaloneClass($sClass)) {
|
||||
$iCount = $this->Count($sClass);
|
||||
$this->aFinalClassesToCleanup[$sClass] = $iCount;
|
||||
if ($bStopDataCheckAtFirstIssue && $iCount > 0) {
|
||||
//setup envt: should raise issue ASAP
|
||||
$this->LogInfoWithProperLogger("Setup audit found data to cleanup", null, $this->aFinalClassesToCleanup);
|
||||
return $this->aFinalClassesToCleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->LogInfoWithProperLogger("Setup audit found data to cleanup", null, ['data_to_cleanup' => $this->aFinalClassesToCleanup]);
|
||||
return $this->aFinalClassesToCleanup;
|
||||
}
|
||||
|
||||
public function GetDataToCleanupCount(): int
|
||||
{
|
||||
$res = 0;
|
||||
foreach ($this->aFinalClassesToCleanup as $sClass => $iCount) {
|
||||
$res += $iCount;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function Count($sClass): int
|
||||
{
|
||||
$oSearch = DBObjectSearch::FromOQL("SELECT $sClass", []);
|
||||
$oSearch->AllowAllData();
|
||||
$oSet = new DBObjectSet($oSearch);
|
||||
|
||||
return $oSet->Count();
|
||||
}
|
||||
|
||||
//could be shared with others in log APIs ?
|
||||
private function LogInfoWithProperLogger($sMessage, $sChannel = null, $aContext = []): void
|
||||
{
|
||||
if (ContextTag::Check(ContextTag::TAG_SETUP)) {
|
||||
SetupLog::Info($sMessage, $sChannel, $aContext);
|
||||
} else {
|
||||
IssueLog::Info($sMessage, $sChannel, $aContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
namespace Combodo\iTop\Setup\FeatureRemoval;
|
||||
|
||||
use Combodo\iTop\Setup\ModuleDependency\Module;
|
||||
use Config;
|
||||
use InstallationChoicesToModuleConverter;
|
||||
use iTopExtensionsMap;
|
||||
use MetaModel;
|
||||
use ModuleDiscovery;
|
||||
use RunTimeEnvironment;
|
||||
use SetupUtils;
|
||||
use utils;
|
||||
|
||||
class DryRemovalRuntimeEnvironment extends RunTimeEnvironment
|
||||
{
|
||||
public const DRY_REMOVAL_AUDIT_ENV = "extension-removal";
|
||||
|
||||
protected array $aExtensionsByCode;
|
||||
private bool $bExtensionMapModified = false;
|
||||
|
||||
/**
|
||||
* Toolset for building a run-time environment
|
||||
@@ -37,33 +42,54 @@ class DryRemovalRuntimeEnvironment extends RunTimeEnvironment
|
||||
|
||||
$sEnv = $this->sFinalEnv;
|
||||
$this->aExtensionsByCode = $aExtensionCodesToRemove;
|
||||
//SetupUtils::rrmdir(APPROOT."/data/$sEnv-modules");
|
||||
|
||||
$this->Cleanup();
|
||||
SetupUtils::copydir(APPROOT."/data/$sSourceEnv-modules", APPROOT."/data/$sEnv-modules");
|
||||
|
||||
if (count($aExtensionCodesToRemove) > 0) {
|
||||
$this->RemoveExtensionsLocally($aExtensionCodesToRemove);
|
||||
}
|
||||
$this->DeclareExtensionAsRemoved($aExtensionCodesToRemove);
|
||||
|
||||
$oDryRemovalConfig = clone(MetaModel::GetConfig());
|
||||
$oDryRemovalConfig->ChangeModulesPath($sSourceEnv, $this->sFinalEnv);
|
||||
$this->WriteConfigFileSafe($oDryRemovalConfig);
|
||||
|
||||
$sSourceDir = $oDryRemovalConfig->Get('source_dir');
|
||||
$aSearchDirs = $this->GetExtraDirsToCompile($sSourceDir);
|
||||
|
||||
$aModulesToLoad = $this->GetModulesToLoad($sSourceEnv, $aSearchDirs);
|
||||
|
||||
try {
|
||||
ModuleDiscovery::GetModulesOrderedByDependencies($aSearchDirs, true, $aModulesToLoad);
|
||||
} catch (\MissingDependencyException $e) {
|
||||
\IssueLog::Error("Cannot prepare setup due to dependency issue", null, ['msg' => $e->getMessage(), 'modules_to_load' => $aModulesToLoad]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function RemoveExtensionsLocally(array $aExtensionCodes): void
|
||||
private function DeclareExtensionAsRemoved(array $aExtensionCodes): void
|
||||
{
|
||||
$oExtensionsMap = new \iTopExtensionsMap($this->sFinalEnv);
|
||||
$oExtensionsMap = new iTopExtensionsMap($this->sFinalEnv);
|
||||
$oExtensionsMap->DeclareExtensionAsRemoved($aExtensionCodes);
|
||||
}
|
||||
|
||||
foreach ($aExtensionCodes as $sCode) {
|
||||
/** @var \iTopExtension $oExtension */
|
||||
$oExtension = $oExtensionsMap->GetFromExtensionCode($sCode);
|
||||
if (!is_null($oExtension)) {
|
||||
$sDir = $oExtension->sSourceDir;
|
||||
\IssueLog::Info(__METHOD__.": remove extension locally", null, [$oExtension->sCode => $sDir]);
|
||||
SetupUtils::rrmdir($sDir);
|
||||
} else {
|
||||
\IssueLog::Warning(__METHOD__." cannot find extensions", null, ['env' => $this->sFinalEnv, 'code' => $sCode]);
|
||||
}
|
||||
private function GetModulesToLoad(string $sSourceEnv, $aSearchDirs): array
|
||||
{
|
||||
$oSourceConfig = new Config(utils::GetConfigFilePath($sSourceEnv));
|
||||
$aChoices = iTopExtensionsMap::GetChoicesFromDatabase($oSourceConfig);
|
||||
$sSourceDir = $oSourceConfig->Get('source_dir');
|
||||
|
||||
$sInstallFilePath = APPROOT.$sSourceDir.'/installation.xml';
|
||||
if (! is_file($sInstallFilePath)) {
|
||||
$sInstallFilePath = null;
|
||||
}
|
||||
|
||||
$aModuleIdsToLoad = InstallationChoicesToModuleConverter::GetInstance()->GetModules($aChoices, $aSearchDirs, $sInstallFilePath);
|
||||
$aModulesToLoad = [];
|
||||
foreach ($aModuleIdsToLoad as $sModuleId) {
|
||||
$oModule = new Module($sModuleId);
|
||||
$sModuleName = $oModule->GetModuleName();
|
||||
$aModulesToLoad[] = $sModuleName;
|
||||
}
|
||||
return $aModulesToLoad;
|
||||
}
|
||||
|
||||
public function Cleanup()
|
||||
@@ -75,23 +101,4 @@ class DryRemovalRuntimeEnvironment extends RunTimeEnvironment
|
||||
SetupUtils::rrmdir(APPROOT."/conf/$sEnv");
|
||||
@unlink(APPROOT."/data/datamodel-$sEnv.xml");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \iTopExtensionsMap|null
|
||||
*/
|
||||
/*protected function GetExtensionMap(): ?iTopExtensionsMap
|
||||
{
|
||||
if (is_null(parent::GetExtensionMap())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$this->bExtensionMapModified) {
|
||||
$this->bExtensionMapModified = true;
|
||||
foreach ($this->aExtensionsByCode as $sCode) {
|
||||
parent::GetExtensionMap()->RemoveExtension($sCode);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::GetExtensionMap();
|
||||
}*/
|
||||
}
|
||||
|
||||
40
setup/feature_removal/InplaceSetupAudit.php
Normal file
40
setup/feature_removal/InplaceSetupAudit.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Setup\FeatureRemoval;
|
||||
|
||||
use MetaModel;
|
||||
|
||||
require_once __DIR__.'/AbstractSetupAudit.php';
|
||||
require_once APPROOT.'setup/feature_removal/ModelReflectionSerializer.php';
|
||||
|
||||
class InplaceSetupAudit extends AbstractSetupAudit
|
||||
{
|
||||
//file used when present to trigger audit exception when testing specific setups
|
||||
public const GETISSUE_ERROR_MSG_FILE_FORTESTONLY = '.setup_audit_error_msg.txt';
|
||||
|
||||
private string $sEnvAfter;
|
||||
|
||||
public function __construct(array $aClassesBefore, string $sEnvAfter)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->aClassesBefore = $aClassesBefore;
|
||||
$this->sEnvAfter = $sEnvAfter;
|
||||
}
|
||||
|
||||
public function ComputeClasses(): void
|
||||
{
|
||||
if ($this->bClassesInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sCurrentEnvt = MetaModel::GetEnvironment();
|
||||
|
||||
if ($sCurrentEnvt === $this->sEnvAfter) {
|
||||
$this->aClassesAfter = MetaModel::GetClasses();
|
||||
} else {
|
||||
$this->aClassesAfter = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvAfter);
|
||||
}
|
||||
|
||||
$this->bClassesInitialized = true;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,12 @@
|
||||
|
||||
namespace Combodo\iTop\Setup\FeatureRemoval;
|
||||
|
||||
use ContextTag;
|
||||
use CoreException;
|
||||
use Exception;
|
||||
use IssueLog;
|
||||
use SetupLog;
|
||||
use utils;
|
||||
|
||||
class ModelReflectionSerializer
|
||||
{
|
||||
@@ -29,27 +33,39 @@ class ModelReflectionSerializer
|
||||
|
||||
public function GetModelFromEnvironment(string $sEnv): array
|
||||
{
|
||||
\IssueLog::Info(__METHOD__, null, ['env' => $sEnv]);
|
||||
$sPHPExec = trim(\MetaModel::GetConfig()->Get('php_path'));
|
||||
IssueLog::Info(__METHOD__, null, ['env' => $sEnv]);
|
||||
$sPHPExec = trim(utils::GetConfig()->Get('php_path'));
|
||||
$sOutput = "";
|
||||
$iRes = 0;
|
||||
exec(sprintf("$sPHPExec %s/get_model_reflection.php --env='%s'", __DIR__, $sEnv), $sOutput, $iRes);
|
||||
|
||||
$sCommandLine = sprintf("$sPHPExec %s/get_model_reflection.php --env=%s", __DIR__, $sEnv);
|
||||
exec($sCommandLine, $sOutput, $iRes);
|
||||
if ($iRes != 0) {
|
||||
\IssueLog::Error("Cannot get classes", null, ['env' => $sEnv, 'code' => $iRes, "output" => $sOutput]);
|
||||
throw new CoreException("Cannot get classes");
|
||||
$this->LogErrorWithProperLogger("Cannot get classes", null, ['env' => $sEnv, 'code' => $iRes, "output" => $sOutput]);
|
||||
throw new CoreException("Cannot get classes from env ".$sEnv);
|
||||
}
|
||||
|
||||
$aClasses = json_decode($sOutput[0] ?? null, true);
|
||||
if (false === $aClasses) {
|
||||
\IssueLog::Error("Invalid JSON", null, ["output" => $sOutput]);
|
||||
$this->LogErrorWithProperLogger("Invalid JSON", null, ['env' => $sEnv, "output" => $sOutput]);
|
||||
throw new Exception("cannot get classes");
|
||||
}
|
||||
|
||||
if (!is_array($aClasses)) {
|
||||
\IssueLog::Error("not an array", null, ["classes" => $aClasses]);
|
||||
throw new Exception("cannot get classes");
|
||||
$this->LogErrorWithProperLogger("not an array", null, ['env' => $sEnv, "classes" => $aClasses, "output" => $sOutput]);
|
||||
throw new Exception("cannot get classes from $sEnv");
|
||||
}
|
||||
|
||||
return $aClasses;
|
||||
}
|
||||
|
||||
//could be shared with others in log APIs ?
|
||||
private function LogErrorWithProperLogger($sMessage, $sChannel = null, $aContext = []): void
|
||||
{
|
||||
if (ContextTag::Check(ContextTag::TAG_SETUP)) {
|
||||
SetupLog::Error($sMessage, $sChannel, $aContext);
|
||||
} else {
|
||||
IssueLog::Error($sMessage, $sChannel, $aContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,70 +2,51 @@
|
||||
|
||||
namespace Combodo\iTop\Setup\FeatureRemoval;
|
||||
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
use MetaModel;
|
||||
|
||||
require_once __DIR__.'/AbstractSetupAudit.php';
|
||||
require_once APPROOT.'setup/feature_removal/ModelReflectionSerializer.php';
|
||||
|
||||
class SetupAudit
|
||||
class SetupAudit extends AbstractSetupAudit
|
||||
{
|
||||
//file used when present to trigger audit exception when testing specific setups
|
||||
public const GETISSUE_ERROR_MSG_FILE_FORTESTONLY = '.setup_audit_error_msg.txt';
|
||||
|
||||
private string $sEnvBeforeExtensionRemoval;
|
||||
private string $sEnvAfterExtensionRemoval;
|
||||
private string $sEnvBefore;
|
||||
private string $sEnvAfter;
|
||||
|
||||
private array $aClassesBeforeRemoval;
|
||||
private array $aClassesAfterRemoval;
|
||||
private array $aRemovedClasses;
|
||||
private array $aFinalClassesRemoved;
|
||||
|
||||
public function __construct(string $sEnvBeforeExtensionRemoval, string $sEnvAfterExtensionRemoval = DryRemovalRuntimeEnvironment::DRY_REMOVAL_AUDIT_ENV)
|
||||
public function __construct(string $sEnvBefore, string $sEnvAfter)
|
||||
{
|
||||
$this->sEnvBeforeExtensionRemoval = $sEnvBeforeExtensionRemoval;
|
||||
$this->sEnvAfterExtensionRemoval = $sEnvAfterExtensionRemoval;
|
||||
|
||||
$sCurrentEnvt = MetaModel::GetEnvironment();
|
||||
if ($sCurrentEnvt === $this->sEnvBeforeExtensionRemoval) {
|
||||
$this->aClassesBeforeRemoval = MetaModel::GetClasses();
|
||||
} else {
|
||||
$this->aClassesBeforeRemoval = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvBeforeExtensionRemoval);
|
||||
}
|
||||
|
||||
if ($sCurrentEnvt === $this->sEnvAfterExtensionRemoval) {
|
||||
$this->aClassesAfterRemoval = MetaModel::GetClasses();
|
||||
} else {
|
||||
$this->aClassesAfterRemoval = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvAfterExtensionRemoval);
|
||||
}
|
||||
|
||||
$this->aRemovedClasses = [];
|
||||
$this->aFinalClassesRemoved = [];
|
||||
parent::__construct();
|
||||
$this->sEnvBefore = $sEnvBefore;
|
||||
$this->sEnvAfter = $sEnvAfter;
|
||||
}
|
||||
|
||||
/*public function SetSelectedExtensions(Config $oConfig, array $aSelectedExtensions)
|
||||
public function ComputeClasses(): void
|
||||
{
|
||||
$oExtensionsMap = new \iTopExtensionsMap();
|
||||
$oExtensionsMap->LoadChoicesFromDatabase($oConfig);
|
||||
if ($this->bClassesInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
sort($aSelectedExtensions);
|
||||
$this->aExtensionToRemove = $oExtensionsMap->GetMissingExtensions($aSelectedExtensions);
|
||||
sort($this->aExtensionToRemove);
|
||||
\SetupLog::Info(__METHOD__, null, ['aExtensionToRemove' => $this->aExtensionToRemove]);
|
||||
}*/
|
||||
$this->aClassesBefore = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvBefore);
|
||||
$this->aClassesAfter = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvAfter);
|
||||
|
||||
$this->bClassesInitialized = true;
|
||||
}
|
||||
|
||||
public function GetRemovedClasses(): array
|
||||
{
|
||||
$this->ComputeClasses();
|
||||
|
||||
if (count($this->aRemovedClasses) == 0) {
|
||||
if (count($this->aClassesBeforeRemoval) == 0) {
|
||||
if (count($this->aClassesBefore) == 0) {
|
||||
return $this->aRemovedClasses;
|
||||
}
|
||||
|
||||
if (count($this->aClassesAfterRemoval) == 0) {
|
||||
if (count($this->aClassesAfter) == 0) {
|
||||
return $this->aRemovedClasses;
|
||||
}
|
||||
|
||||
$aExtensionsNames = array_diff($this->aClassesBeforeRemoval, $this->aClassesAfterRemoval);
|
||||
$aExtensionsNames = array_diff($this->aClassesBefore, $this->aClassesAfter);
|
||||
$this->aRemovedClasses = [];
|
||||
$aClasses = array_values($aExtensionsNames);
|
||||
sort($aClasses);
|
||||
@@ -77,50 +58,4 @@ class SetupAudit
|
||||
|
||||
return $this->aRemovedClasses;
|
||||
}
|
||||
|
||||
/** test only: return file path that force audit error being raised
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetErrorMessageFilePathForTestOnly(): string
|
||||
{
|
||||
return APPROOT."/data/".self::GETISSUE_ERROR_MSG_FILE_FORTESTONLY;
|
||||
}
|
||||
|
||||
public function GetIssues(bool $bThrowExceptionAtFirstIssue = false): array
|
||||
{
|
||||
$sErrorMessageFilePath = self::GetErrorMessageFilePathForTestOnly();
|
||||
if ($bThrowExceptionAtFirstIssue && is_file($sErrorMessageFilePath)) {
|
||||
$sMsg = file_get_contents($sErrorMessageFilePath);
|
||||
throw new \Exception($sMsg);
|
||||
}
|
||||
|
||||
$this->aFinalClassesRemoved = [];
|
||||
|
||||
foreach ($this->GetRemovedClasses() as $sClass) {
|
||||
if (MetaModel::IsAbstract($sClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!MetaModel::IsStandaloneClass($sClass)) {
|
||||
$iCount = $this->Count($sClass);
|
||||
$this->aFinalClassesRemoved[$sClass] = $iCount;
|
||||
if ($bThrowExceptionAtFirstIssue && $iCount > 0) {
|
||||
//setup envt: should raise issue ASAP
|
||||
throw new \Exception($sClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->aFinalClassesRemoved;
|
||||
}
|
||||
|
||||
private function Count($sClass): int
|
||||
{
|
||||
$oSearch = DBObjectSearch::FromOQL("SELECT $sClass", []);
|
||||
$oSearch->AllowAllData();
|
||||
$oSet = new DBObjectSet($oSearch);
|
||||
|
||||
return $oSet->Count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ if (is_null($sEnv)) {
|
||||
$sConfFile = utils::GetConfigFilePath($sEnv);
|
||||
|
||||
try {
|
||||
MetaModel::Startup($sConfFile, false /* $bModelOnly */, true /* $bAllowCache */, false /* $bTraceSourceFiles */, $sEnv);
|
||||
MetaModel::Startup($sConfFile, false /* $bModelOnly */, false /* $bAllowCache */, false /* $bTraceSourceFiles */, $sEnv);
|
||||
} catch (\Throwable $e) {
|
||||
echo $e->getMessage();
|
||||
echo $e->getTraceAsString();
|
||||
|
||||
144
setup/itopextension.class.inc.php
Normal file
144
setup/itopextension.class.inc.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReader;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReaderException;
|
||||
|
||||
require_once(APPROOT.'/setup/parameters.class.inc.php');
|
||||
require_once(APPROOT.'/core/cmdbsource.class.inc.php');
|
||||
require_once(APPROOT.'/setup/modulediscovery.class.inc.php');
|
||||
require_once(APPROOT.'/setup/moduleinstaller.class.inc.php');
|
||||
|
||||
/**
|
||||
* Basic helper class to describe an extension, with some characteristics and a list of modules
|
||||
*/
|
||||
class iTopExtension
|
||||
{
|
||||
public const SOURCE_WIZARD = 'datamodels';
|
||||
public const SOURCE_MANUAL = 'extensions';
|
||||
public const SOURCE_REMOTE = 'data';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sCode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sVersion;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sInstalledVersion;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sLabel;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sDescription;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sSource;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $bMandatory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sMoreInfoUrl;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $bMarkedAsChosen;
|
||||
/**
|
||||
* If null, check if at least one module cannot be uninstalled
|
||||
* @var bool|null
|
||||
*/
|
||||
public ?bool $bCanBeUninstalled = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $bVisible;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $aModules;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $aModuleVersion;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public $aModuleInfo;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sSourceDir;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $aMissingDependencies;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public bool $bInstalled = false;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public bool $bRemovedFromDisk = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->sCode = '';
|
||||
$this->sLabel = '';
|
||||
$this->sDescription = '';
|
||||
$this->sSource = self::SOURCE_WIZARD;
|
||||
$this->bMandatory = false;
|
||||
$this->sMoreInfoUrl = '';
|
||||
$this->bMarkedAsChosen = false;
|
||||
$this->sVersion = ITOP_VERSION;
|
||||
$this->sInstalledVersion = '';
|
||||
$this->aModules = [];
|
||||
$this->aModuleVersion = [];
|
||||
$this->aModuleInfo = [];
|
||||
$this->sSourceDir = '';
|
||||
$this->bVisible = true;
|
||||
$this->aMissingDependencies = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.3.0
|
||||
* @return bool
|
||||
*/
|
||||
public function CanBeUninstalled(): bool
|
||||
{
|
||||
if (!is_null($this->bCanBeUninstalled)) {
|
||||
return $this->bCanBeUninstalled;
|
||||
}
|
||||
foreach ($this->aModuleInfo as $sModuleCode => $aModuleInfo) {
|
||||
if ($aModuleInfo['uninstallable'] !== 'yes') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1801,7 +1801,7 @@ EOF
|
||||
*/
|
||||
public function FindModules()
|
||||
{
|
||||
$aAvailableModules = ModuleDiscovery::GetAvailableModules($this->aRootDirs);
|
||||
$aAvailableModules = ModuleDiscovery::GetModulesOrderedByDependencies($this->aRootDirs);
|
||||
$aResult = [];
|
||||
foreach ($aAvailableModules as $sId => $aModule) {
|
||||
$oModule = new MFModule($sId, $aModule['root_dir'], $aModule['label'], isset($aModule['auto_select']));
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Combodo\iTop\Setup\ModuleDependency;
|
||||
require_once(APPROOT.'/setup/runtimeenv.class.inc.php');
|
||||
|
||||
use Combodo\iTop\PhpParser\Evaluation\PhpExpressionEvaluator;
|
||||
use ModuleFileReaderException;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReaderException;
|
||||
use RunTimeEnvironment;
|
||||
|
||||
/**
|
||||
@@ -61,19 +61,19 @@ class DependencyExpression
|
||||
}
|
||||
}
|
||||
|
||||
private static function GetPhpExpressionEvaluator(): PhpExpressionEvaluator
|
||||
public static function GetPhpExpressionEvaluator(): PhpExpressionEvaluator
|
||||
{
|
||||
if (!isset(static::$oPhpExpressionEvaluator)) {
|
||||
static::$oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
|
||||
if (!isset(self::$oPhpExpressionEvaluator)) {
|
||||
self::$oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
|
||||
}
|
||||
|
||||
return static::$oPhpExpressionEvaluator;
|
||||
return self::$oPhpExpressionEvaluator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return module names potentially required by current dependency
|
||||
*
|
||||
* @return array
|
||||
* @return array<string>
|
||||
*/
|
||||
public function GetRemainingModuleNamesToResolve(): array
|
||||
{
|
||||
|
||||
@@ -114,7 +114,7 @@ class Module
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array: list of unique module names
|
||||
* @return array<string> list of unique module names
|
||||
*/
|
||||
public function GetUnresolvedDependencyModuleNames(): array
|
||||
{
|
||||
|
||||
@@ -19,16 +19,16 @@ class ModuleDependencySort
|
||||
|
||||
final public static function GetInstance(): ModuleDependencySort
|
||||
{
|
||||
if (!isset(static::$oInstance)) {
|
||||
static::$oInstance = new static();
|
||||
if (!isset(self::$oInstance)) {
|
||||
self::$oInstance = new ModuleDependencySort();
|
||||
}
|
||||
|
||||
return static::$oInstance;
|
||||
return self::$oInstance;
|
||||
}
|
||||
|
||||
final public static function SetInstance(?ModuleDependencySort $oInstance): void
|
||||
{
|
||||
static::$oInstance = $oInstance;
|
||||
self::$oInstance = $oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +168,7 @@ class ModuleDependencySort
|
||||
foreach ($aCountDepsByModuleId as $sModuleId => $iInDegreeCounter) {
|
||||
$oModule = $aUnresolvedDependencyModules[$sModuleId];
|
||||
|
||||
if ($bOneLoopAtLeast && $iInDegreeCounter > 0) {
|
||||
if ($bOneLoopAtLeast && ($iInDegreeCounter > 0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@
|
||||
|
||||
use Combodo\iTop\PhpParser\Evaluation\PhpExpressionEvaluator;
|
||||
use Combodo\iTop\Setup\ModuleDependency\Module;
|
||||
use Combodo\iTop\Setup\ModuleDependency\ModuleDependencySort;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReader;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReaderException;
|
||||
|
||||
require_once(APPROOT.'setup/modulediscovery/ModuleFileReader.php');
|
||||
require_once(__DIR__.'/moduledependency/moduledependencysort.class.inc.php');
|
||||
|
||||
use Combodo\iTop\Setup\ModuleDependency\ModuleDependencySort;
|
||||
require_once(__DIR__.'/itopextension.class.inc.php');
|
||||
|
||||
class MissingDependencyException extends CoreException
|
||||
{
|
||||
@@ -95,6 +95,9 @@ class ModuleDiscovery
|
||||
protected static $m_aModules = [];
|
||||
protected static $m_aModuleVersionByName = [];
|
||||
|
||||
/** @var array<\iTopExtension> $m_aRemovedExtensions */
|
||||
protected static array $m_aRemovedExtensions = [];
|
||||
|
||||
// All the entries below are list of file paths relative to the module directory
|
||||
protected static $m_aFilesList = ['datamodel', 'webservice', 'dictionary', 'data.struct', 'data.sample'];
|
||||
|
||||
@@ -131,6 +134,10 @@ class ModuleDiscovery
|
||||
|
||||
list($sModuleName, $sModuleVersion) = static::GetModuleName($sId);
|
||||
|
||||
if (self::IsModuleInExtensionList(self::$m_aRemovedExtensions, $sModuleName, $sModuleVersion, $aArgs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_key_exists($sModuleName, self::$m_aModuleVersionByName)) {
|
||||
if (version_compare($sModuleVersion, self::$m_aModuleVersionByName[$sModuleName]['version'], '>')) {
|
||||
// Newer version, let's upgrade
|
||||
@@ -189,21 +196,6 @@ class ModuleDiscovery
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of "discovered" modules, ordered based on their (inter) dependencies
|
||||
*
|
||||
* @param bool $bAbortOnMissingDependency ...
|
||||
* @param array $aModulesToLoad List of modules to search for, defaults to all if omitted
|
||||
*
|
||||
* @return array
|
||||
* @throws \MissingDependencyException
|
||||
*/
|
||||
protected static function GetModules($bAbortOnMissingDependency = false, $aModulesToLoad = null)
|
||||
{
|
||||
// Order the modules to take into account their inter-dependencies
|
||||
return self::OrderModulesByDependencies(self::$m_aModules, $bAbortOnMissingDependency, $aModulesToLoad);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrange an list of modules, based on their (inter) dependencies
|
||||
* @param array $aModules The list of modules to process: 'id' => $aModuleInfo
|
||||
@@ -214,15 +206,20 @@ class ModuleDiscovery
|
||||
*/
|
||||
public static function OrderModulesByDependencies($aModules, $bAbortOnMissingDependency = false, $aModulesToLoad = null)
|
||||
{
|
||||
if (is_null($aModulesToLoad)) {
|
||||
if (is_null($aModulesToLoad) && count(self::$m_aRemovedExtensions) === 0) {
|
||||
$aFilteredModules = $aModules;
|
||||
} else {
|
||||
$aFilteredModules = [];
|
||||
foreach ($aModules as $sModuleId => $aModule) {
|
||||
foreach ($aModules as $sModuleId => $aModuleInfo) {
|
||||
$oModule = new Module($sModuleId);
|
||||
$sModuleName = $oModule->GetModuleName();
|
||||
if (in_array($sModuleName, $aModulesToLoad)) {
|
||||
$aFilteredModules[$sModuleId] = $aModule;
|
||||
|
||||
if (self::IsModuleInExtensionList(self::$m_aRemovedExtensions, $sModuleName, $oModule->GetVersion(), $aModuleInfo)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_null($aModulesToLoad) || in_array($sModuleName, $aModulesToLoad)) {
|
||||
$aFilteredModules[$sModuleId] = $aModuleInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,27 +227,19 @@ class ModuleDiscovery
|
||||
return ModuleDependencySort::GetInstance()->GetModulesOrderedForInstallation($aFilteredModules, $bAbortOnMissingDependency);
|
||||
}
|
||||
|
||||
private static function GetPhpExpressionEvaluator(): PhpExpressionEvaluator
|
||||
/**
|
||||
* @param array<\iTopExtension> $aRemovedExtension
|
||||
* @return void
|
||||
*/
|
||||
public static function DeclareRemovedExtensions(array $aRemovedExtension): void
|
||||
{
|
||||
if (!isset(static::$oPhpExpressionEvaluator)) {
|
||||
static::$oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
|
||||
if (self::$m_aRemovedExtensions != $aRemovedExtension) {
|
||||
self::ResetCache();
|
||||
}
|
||||
|
||||
return static::$oPhpExpressionEvaluator;
|
||||
self::$m_aRemovedExtensions = $aRemovedExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search (on the disk) for all defined iTop modules, load them and returns the list (as an array)
|
||||
* of the possible iTop modules to install
|
||||
*
|
||||
* @param $aSearchDirs array of directories to search (absolute paths)
|
||||
* @param bool $bAbortOnMissingDependency ...
|
||||
* @param array $aModulesToLoad List of modules to search for, defaults to all if omitted
|
||||
*
|
||||
* @return array A big array moduleID => ModuleData
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function GetAvailableModules($aSearchDirs, $bAbortOnMissingDependency = false, $aModulesToLoad = null)
|
||||
private static function Init($aSearchDirs): void
|
||||
{
|
||||
if (self::$m_aSearchDirs != $aSearchDirs) {
|
||||
self::ResetCache();
|
||||
@@ -269,13 +258,60 @@ class ModuleDiscovery
|
||||
clearstatcache();
|
||||
self::ListModuleFiles(basename($sSearchDir), dirname($sSearchDir));
|
||||
}
|
||||
return self::GetModules($bAbortOnMissingDependency, $aModulesToLoad);
|
||||
} else {
|
||||
// Reuse the previous results
|
||||
return self::GetModules($bAbortOnMissingDependency, $aModulesToLoad);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all modules found on disk ordered by dependencies. Skipping modules coming from extensions declared as removed (@see ModuleDiscovery::DeclareRemovedExtensions)
|
||||
* @param $aSearchDirs array of directories to search (absolute paths)
|
||||
* @param bool $bAbortOnMissingDependency ...
|
||||
* @param array $aModulesToLoad List of modules to search for, defaults to all if omitted
|
||||
*
|
||||
* @return array A big array moduleID => ModuleData
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function GetModulesOrderedByDependencies($aSearchDirs, $bAbortOnMissingDependency = false, $aModulesToLoad = null)
|
||||
{
|
||||
self::Init($aSearchDirs);
|
||||
|
||||
return self::OrderModulesByDependencies(self::$m_aModules, $bAbortOnMissingDependency, $aModulesToLoad);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use \ModuleDiscovery::GetModulesOrderedByDependencies instead
|
||||
*/
|
||||
public static function GetAvailableModules($aSearchDirs, $bAbortOnMissingDependency = false, $aModulesToLoad = null)
|
||||
{
|
||||
return ModuleDiscovery::GetModulesOrderedByDependencies($aSearchDirs, $bAbortOnMissingDependency, $aModulesToLoad);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all modules found on disk (without any dependency consideration). Skipping modules coming from extensions declared as removed (@see ModuleDiscovery::DeclareRemovedExtensions)
|
||||
*
|
||||
* @param $aSearchDirs array of directories to search (absolute paths)
|
||||
*
|
||||
* @return array A big array moduleID => ModuleData
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function GetAllModules($aSearchDirs)
|
||||
{
|
||||
self::Init($aSearchDirs);
|
||||
|
||||
$aNonRemovedModules = [];
|
||||
foreach (self::$m_aModules as $sModuleId => $aModuleInfo) {
|
||||
$oModule = new Module($sModuleId);
|
||||
$sModuleName = $oModule->GetModuleName();
|
||||
|
||||
if (self::IsModuleInExtensionList(self::$m_aRemovedExtensions, $sModuleName, $oModule->GetVersion(), $aModuleInfo)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$aNonRemovedModules[$sModuleId] = $aModuleInfo;
|
||||
}
|
||||
|
||||
return $aNonRemovedModules;
|
||||
}
|
||||
|
||||
public static function ResetCache()
|
||||
{
|
||||
self::$m_aSearchDirs = null;
|
||||
@@ -285,10 +321,12 @@ class ModuleDiscovery
|
||||
|
||||
/**
|
||||
* Helper function to interpret the name of a module
|
||||
*
|
||||
* @param $sModuleId string Identifier of the module, in the form 'name/version'
|
||||
* @return array(name, version)
|
||||
*
|
||||
* @return array of 2 elements (name, version)
|
||||
*/
|
||||
public static function GetModuleName($sModuleId)
|
||||
public static function GetModuleName($sModuleId): array
|
||||
{
|
||||
$aMatches = [];
|
||||
if (preg_match('!^(.*)/(.*)$!', $sModuleId, $aMatches)) {
|
||||
@@ -342,6 +380,59 @@ class ModuleDiscovery
|
||||
throw new Exception("Data directory (".$sDirectory.") not found or not readable.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<\iTopExtension> $aExtensions
|
||||
* @param string $sModuleName
|
||||
* @param string $sModuleVersion
|
||||
* @param array $aModuleInfo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function IsModuleInExtensionList(array $aExtensions, string $sModuleName, string $sModuleVersion, array $aModuleInfo): bool
|
||||
{
|
||||
if (count($aExtensions) === 0) {
|
||||
return false;
|
||||
}
|
||||
$aNonMatchingPaths = [];
|
||||
$sModuleFilePath = $aModuleInfo[ModuleFileReader::MODULE_FILE_PATH];
|
||||
|
||||
/** @var \iTopExtension $oExtension */
|
||||
foreach ($aExtensions as $oExtension) {
|
||||
$sCurrentVersion = $oExtension->aModuleVersion[$sModuleName] ?? null;
|
||||
if (is_null($sCurrentVersion)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($sModuleVersion !== $sCurrentVersion) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$aCurrentModuleInfo = $oExtension->aModuleInfo[$sModuleName] ?? null;
|
||||
if (is_null($aCurrentModuleInfo)) {
|
||||
SetupLog::Warning("Missing $sModuleName in ".$oExtension->sLabel.". it should not happen");
|
||||
continue;
|
||||
}
|
||||
|
||||
// use case: same module coming from 2 different extensions
|
||||
// we remove only the one coming from removed extensions
|
||||
$sCurrentModuleFilePath = $aCurrentModuleInfo[ModuleFileReader::MODULE_FILE_PATH];
|
||||
if (realpath($sModuleFilePath) !== realpath($sCurrentModuleFilePath)) {
|
||||
$aNonMatchingPaths[] = $sCurrentModuleFilePath;
|
||||
continue;
|
||||
}
|
||||
|
||||
SetupLog::Info("Module considered as removed", null, ['extension_code' => $oExtension->sCode, 'module_name' => $sModuleName, 'module_version' => $sModuleVersion, ModuleFileReader::MODULE_FILE_PATH => $sCurrentModuleFilePath]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (count($aNonMatchingPaths) > 0) {
|
||||
//add log for support
|
||||
SetupLog::Debug("Module kept as it came from non removed extensions", null, ['module_name' => $sModuleName, 'module_version' => $sModuleVersion, ModuleFileReader::MODULE_FILE_PATH => $sModuleFilePath, 'non_matching_paths' => $aNonMatchingPaths]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // End of class
|
||||
|
||||
/** Alias for backward compatibility with old module files in which
|
||||
|
||||
@@ -7,15 +7,15 @@ use CoreException;
|
||||
use Exception;
|
||||
use ParseError;
|
||||
use PhpParser\Error;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\ParserFactory;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Arg;
|
||||
|
||||
require_once __DIR__.'/ModuleFileReaderException.php';
|
||||
require_once APPROOT.'sources/PhpParser/Evaluation/PhpExpressionEvaluator.php';
|
||||
@@ -36,6 +36,7 @@ class ModuleFileReader
|
||||
public const MODULE_INFO_PATH = 0;
|
||||
public const MODULE_INFO_ID = 1;
|
||||
public const MODULE_INFO_CONFIG = 2;
|
||||
public const MODULE_FILE_PATH = "module_file_path";
|
||||
|
||||
public const STATIC_CALLWHITELIST = [
|
||||
"utils::GetItopVersionWikiSyntax",
|
||||
@@ -48,21 +49,23 @@ class ModuleFileReader
|
||||
|
||||
final public static function GetInstance(): ModuleFileReader
|
||||
{
|
||||
if (!isset(static::$oInstance)) {
|
||||
static::$oInstance = new static();
|
||||
if (!isset(self::$oInstance)) {
|
||||
self::$oInstance = new ModuleFileReader();
|
||||
}
|
||||
|
||||
return static::$oInstance;
|
||||
return self::$oInstance;
|
||||
}
|
||||
|
||||
final public static function SetInstance(?ModuleFileReader $oInstance): void
|
||||
{
|
||||
static::$oInstance = $oInstance;
|
||||
self::$oInstance = $oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the information from a module file (module.xxx.php)
|
||||
* @param string $sModuleFile
|
||||
*
|
||||
* @param string $sModuleFilePath
|
||||
*
|
||||
* @return array
|
||||
* @throws ModuleFileReaderException
|
||||
*/
|
||||
@@ -108,7 +111,9 @@ class ModuleFileReader
|
||||
* Read the information from a module file (module.xxx.php)
|
||||
* Warning: this method is using eval() function to load the ModuleInstallerAPI classes.
|
||||
* Current method is never called at design/runtime. It is acceptable to use it during setup only.
|
||||
* @param string $sModuleFile
|
||||
*
|
||||
* @param string $sModuleFilePath
|
||||
*
|
||||
* @return array
|
||||
* @throws ModuleFileReaderException
|
||||
*/
|
||||
@@ -164,7 +169,7 @@ class ModuleFileReader
|
||||
private function CompleteModuleInfoWithFilePath(array &$aModuleInfo)
|
||||
{
|
||||
if (count($aModuleInfo) == 3) {
|
||||
$aModuleInfo[static::MODULE_INFO_CONFIG]['module_file_path'] = $aModuleInfo[static::MODULE_INFO_PATH];
|
||||
$aModuleInfo[static::MODULE_INFO_CONFIG][self::MODULE_FILE_PATH] = $aModuleInfo[static::MODULE_INFO_PATH];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,15 +180,21 @@ class ModuleFileReader
|
||||
}
|
||||
|
||||
$sModuleInstallerClass = $aModuleInfo['installer'];
|
||||
if (strlen($sModuleInstallerClass) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!class_exists($sModuleInstallerClass)) {
|
||||
$sModuleFilePath = $aModuleInfo['module_file_path'];
|
||||
$sModuleFilePath = $aModuleInfo[self::MODULE_FILE_PATH];
|
||||
$this->ReadModuleFileInformationUnsafe($sModuleFilePath);
|
||||
}
|
||||
|
||||
if (!class_exists($sModuleInstallerClass)) {
|
||||
\IssueLog::Error(__METHOD__, null, $aModuleInfo);
|
||||
throw new CoreException("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']);
|
||||
}
|
||||
if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI')) {
|
||||
\IssueLog::Error(__METHOD__, null, $aModuleInfo);
|
||||
throw new CoreException("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']);
|
||||
}
|
||||
|
||||
@@ -192,7 +203,7 @@ class ModuleFileReader
|
||||
|
||||
/**
|
||||
* @param string $sModuleFilePath
|
||||
* @param \PhpParser\Node\Expr\Assign $oAssignation
|
||||
* @param \PhpParser\Node\Stmt\Expression $oExpression
|
||||
*
|
||||
* @return array|null
|
||||
* @throws ModuleFileReaderException
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/ModuleInstallationService.php';
|
||||
require_once __DIR__.'/ModuleInstallationRepository.php';
|
||||
|
||||
class AnalyzeInstallation
|
||||
{
|
||||
private static AnalyzeInstallation $oInstance;
|
||||
private ?array $aAvailableModules = null;
|
||||
private ?array $aSelectInstall = null;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
@@ -23,7 +22,7 @@ class AnalyzeInstallation
|
||||
|
||||
final public static function SetInstance(?AnalyzeInstallation $oInstance): void
|
||||
{
|
||||
static::$oInstance = $oInstance;
|
||||
self::$oInstance = $oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +57,7 @@ class AnalyzeInstallation
|
||||
* )
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
||||
public function AnalyzeInstallation(?Config $oConfig, mixed $modulesPath, bool $bAbortOnMissingDependency = false, ?array $aModulesToLoad = null)
|
||||
{
|
||||
$aRes = [
|
||||
@@ -73,7 +73,7 @@ class AnalyzeInstallation
|
||||
//test only
|
||||
$aAvailableModules = $this->aAvailableModules;
|
||||
} else {
|
||||
$aAvailableModules = ModuleDiscovery::GetAvailableModules($aDirs, $bAbortOnMissingDependency, $aModulesToLoad);
|
||||
$aAvailableModules = ModuleDiscovery::GetModulesOrderedByDependencies($aDirs, $bAbortOnMissingDependency, $aModulesToLoad);
|
||||
}
|
||||
|
||||
foreach ($aAvailableModules as $sModuleId => $aModuleInfo) {
|
||||
@@ -96,7 +96,7 @@ class AnalyzeInstallation
|
||||
$aRes[$sModuleName] = $aModuleInfo;
|
||||
}
|
||||
|
||||
$aCurrentlyInstalledModules = ModuleInstallationService::GetInstance()->ReadComputeInstalledModules($oConfig);
|
||||
$aCurrentlyInstalledModules = ModuleInstallationRepository::GetInstance()->ReadComputeInstalledModules($oConfig);
|
||||
|
||||
// Adjust the list of proposed modules
|
||||
foreach ($aCurrentlyInstalledModules as $sModuleName => $aModuleDB) {
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Setup\ModuleDependency\DependencyExpression;
|
||||
|
||||
require_once __DIR__.'/ModuleInstallationException.php';
|
||||
require_once(APPROOT.'/setup/moduledependency/module.class.inc.php');
|
||||
|
||||
class InstallationChoicesToModuleConverter
|
||||
{
|
||||
private static ?InstallationChoicesToModuleConverter $oInstance;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): InstallationChoicesToModuleConverter
|
||||
{
|
||||
if (!isset(self::$oInstance)) {
|
||||
self::$oInstance = new InstallationChoicesToModuleConverter();
|
||||
}
|
||||
|
||||
return self::$oInstance;
|
||||
}
|
||||
|
||||
final public static function SetInstance(?InstallationChoicesToModuleConverter $oInstance): void
|
||||
{
|
||||
self::$oInstance = $oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aInstallationChoices
|
||||
* @param array $aSearchDirs
|
||||
*
|
||||
* @return array
|
||||
* @throws \ModuleInstallationException
|
||||
*/
|
||||
public function GetModules(array $aInstallationChoices, array $aSearchDirs, ?string $sInstallationFilePath = null): array
|
||||
{
|
||||
$aPackageModules = ModuleDiscovery::GetAllModules($aSearchDirs);
|
||||
|
||||
$bInstallationFileProvided = ! is_null($sInstallationFilePath) && is_file($sInstallationFilePath);
|
||||
|
||||
if ($bInstallationFileProvided) {
|
||||
$oXMLParameters = new XMLParameters($sInstallationFilePath);
|
||||
$aSteps = $oXMLParameters->Get('steps', []);
|
||||
if (!is_array($aSteps)) {
|
||||
return [];
|
||||
}
|
||||
$aInstalledModuleNames = $this->FindInstalledPackageModules($aPackageModules, $aInstallationChoices, $aSteps);
|
||||
} else {
|
||||
$aInstalledModuleNames = $this->FindInstalledPackageModules($aPackageModules, $aInstallationChoices);
|
||||
}
|
||||
|
||||
$aInstalledModules = [];
|
||||
foreach (array_keys($aPackageModules) as $sModuleId) {
|
||||
list($sModuleName) = ModuleDiscovery::GetModuleName($sModuleId);
|
||||
if (in_array($sModuleName, $aInstalledModuleNames)) {
|
||||
$aInstalledModules[] = $sModuleId;
|
||||
}
|
||||
}
|
||||
|
||||
return $aInstalledModules;
|
||||
}
|
||||
|
||||
private function FindInstalledPackageModules(array $aPackageModules, array $aInstallationChoices, array $aInstallationDescription = null): array
|
||||
{
|
||||
$aInstalledModules = [];
|
||||
|
||||
$this->ProcessDefaultModules($aPackageModules, $aInstalledModules);
|
||||
|
||||
if (is_null($aInstallationDescription)) {
|
||||
//in legacy usecase: choices are flat modules list already
|
||||
foreach ($aInstallationChoices as $sModuleName) {
|
||||
$aInstalledModules[$sModuleName] = true;
|
||||
}
|
||||
} else {
|
||||
$this->GetModuleNamesFromInstallationChoices($aInstallationChoices, $aInstallationDescription, $aInstalledModules);
|
||||
}
|
||||
|
||||
$this->ProcessAutoSelectModules($aPackageModules, $aInstalledModules);
|
||||
|
||||
return array_keys($aInstalledModules);
|
||||
}
|
||||
|
||||
private function IsDefaultModule(string $sModuleId, array $aModule): bool
|
||||
{
|
||||
if (($sModuleId === ROOT_MODULE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($aModule['auto_select'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($aModule['category'] === 'authentication') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !$aModule['visible'];
|
||||
}
|
||||
|
||||
private function ProcessDefaultModules(array &$aPackageModules, array &$aInstalledModules): void
|
||||
{
|
||||
foreach ($aPackageModules as $sModuleId => $aModule) {
|
||||
if ($this->IsDefaultModule($sModuleId, $aModule)) {
|
||||
list($sModuleName) = ModuleDiscovery::GetModuleName($sModuleId);
|
||||
$aInstalledModules[$sModuleName] = true;
|
||||
unset($aPackageModules[$sModuleId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function IsAutoSelectedModule(array $aInstalledModules, string $sModuleId, array $aModule): bool
|
||||
{
|
||||
if (($sModuleId === ROOT_MODULE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($aModule['auto_select'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
SetupInfo::SetSelectedModules($aInstalledModules);
|
||||
return DependencyExpression::GetPhpExpressionEvaluator()->ParseAndEvaluateBooleanExpression($aModule['auto_select']);
|
||||
} catch (Exception $e) {
|
||||
IssueLog::Error('Error evaluating module auto-select', null, [
|
||||
'module' => $sModuleId,
|
||||
'error' => $e->getMessage(),
|
||||
'evaluated code' => $aModule['auto_select'],
|
||||
'stacktrace' => $e->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function ProcessAutoSelectModules(array $aPackageModules, array &$aInstalledModules): void
|
||||
{
|
||||
foreach ($aPackageModules as $sModuleId => $aModule) {
|
||||
if ($this->IsAutoSelectedModule($aInstalledModules, $sModuleId, $aModule)) {
|
||||
list($sModuleName) = ModuleDiscovery::GetModuleName($sModuleId);
|
||||
$aInstalledModules[$sModuleName] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function GetModuleNamesFromInstallationChoices(array $aInstallationChoices, array $aInstallationDescription, array &$aModuleNames): void
|
||||
{
|
||||
foreach ($aInstallationDescription as $aStepInfo) {
|
||||
$aOptions = $aStepInfo['options'] ?? null;
|
||||
if (is_array($aOptions)) {
|
||||
foreach ($aOptions as $aChoiceInfo) {
|
||||
$this->ProcessSelectedChoice($aInstallationChoices, $aChoiceInfo, $aModuleNames);
|
||||
}
|
||||
}
|
||||
$aOptions = $aStepInfo['alternatives'] ?? null;
|
||||
if (is_array($aOptions)) {
|
||||
foreach ($aOptions as $aChoiceInfo) {
|
||||
$this->ProcessSelectedChoice($aInstallationChoices, $aChoiceInfo, $aModuleNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function ProcessSelectedChoice(array $aInstallationChoices, array $aChoiceInfo, array &$aInstalledModules)
|
||||
{
|
||||
if (!is_array($aChoiceInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sMandatory = $aChoiceInfo['mandatory'] ?? 'false';
|
||||
|
||||
$aCurrentModules = $aChoiceInfo['modules'] ?? [];
|
||||
$sExtensionCode = $aChoiceInfo['extension_code'];
|
||||
|
||||
$bSelected = ($sMandatory === 'true') || in_array($sExtensionCode, $aInstallationChoices);
|
||||
|
||||
if (!$bSelected) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($aCurrentModules as $sModuleId) {
|
||||
$aInstalledModules[$sModuleId] = true;
|
||||
}
|
||||
|
||||
$aAlternatives = $aChoiceInfo['alternatives'] ?? null;
|
||||
if (is_array($aAlternatives)) {
|
||||
foreach ($aAlternatives as $aSubChoiceInfo) {
|
||||
$this->ProcessSelectedChoice($aInstallationChoices, $aSubChoiceInfo, $aInstalledModules);
|
||||
}
|
||||
}
|
||||
|
||||
$aSubOptionsChoiceInfo = $aChoiceInfo['sub_options'] ?? null;
|
||||
if (is_array($aSubOptionsChoiceInfo)) {
|
||||
$aSubOptions = $aSubOptionsChoiceInfo['options'] ?? null;
|
||||
if (is_array($aSubOptions)) {
|
||||
foreach ($aSubOptions as $aSubChoiceInfo) {
|
||||
$this->ProcessSelectedChoice($aInstallationChoices, $aSubChoiceInfo, $aInstalledModules);
|
||||
}
|
||||
}
|
||||
$aSubAlternatives = $aSubOptionsChoiceInfo['alternatives'] ?? null;
|
||||
if (is_array($aSubAlternatives)) {
|
||||
foreach ($aSubAlternatives as $aSubChoiceInfo) {
|
||||
$this->ProcessSelectedChoice($aInstallationChoices, $aSubChoiceInfo, $aInstalledModules);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
5
setup/moduleinstallation/ModuleInstallationException.php
Normal file
5
setup/moduleinstallation/ModuleInstallationException.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class ModuleInstallationException extends Exception
|
||||
{
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
<?php
|
||||
|
||||
class ModuleInstallationService
|
||||
class ModuleInstallationRepository
|
||||
{
|
||||
private static ModuleInstallationService $oInstance;
|
||||
private static ModuleInstallationRepository $oInstance;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): ModuleInstallationService
|
||||
final public static function GetInstance(): ModuleInstallationRepository
|
||||
{
|
||||
if (!isset(self::$oInstance)) {
|
||||
self::$oInstance = new ModuleInstallationService();
|
||||
self::$oInstance = new ModuleInstallationRepository();
|
||||
}
|
||||
|
||||
return self::$oInstance;
|
||||
}
|
||||
|
||||
final public static function SetInstance(?ModuleInstallationService $oInstance): void
|
||||
final public static function SetInstance(?ModuleInstallationRepository $oInstance): void
|
||||
{
|
||||
static::$oInstance = $oInstance;
|
||||
self::$oInstance = $oInstance;
|
||||
}
|
||||
|
||||
private ?array $aSelectInstall = null;
|
||||
@@ -95,8 +95,17 @@ SQL;
|
||||
$aSelectInstall = CMDBSource::QueryToArray($sSQLQuery);
|
||||
} catch (MySQLException $e) {
|
||||
// No database or erroneous information
|
||||
$this->log_error('Can not connect to the database: host: '.$oConfig->Get('db_host').', user:'.$oConfig->Get('db_user').', pwd:'.$oConfig->Get('db_pwd').', db name:'.$oConfig->Get('db_name'));
|
||||
$this->log_error('Exception '.$e->getMessage());
|
||||
SetupLog::Error(
|
||||
'Can not connect to the database',
|
||||
null,
|
||||
[
|
||||
'host' => $oConfig->Get('db_host'),
|
||||
'user' => $oConfig->Get('db_user'),
|
||||
'pwd:' => $oConfig->Get('db_pwd'),
|
||||
'db name' => $oConfig->Get('db_name'),
|
||||
'msg' => $e->getMessage(),
|
||||
]
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -129,8 +138,10 @@ SQL;
|
||||
// so assume that the datamodel version is equal to the application version
|
||||
$aResult['datamodel_version'] = $aResult['product_version'];
|
||||
}
|
||||
$this->log_info("GetApplicationVersion returns: product_name: ".$aResult['product_name'].', product_version: '.$aResult['product_version']);
|
||||
return empty($aResult) ? false : $aResult;
|
||||
|
||||
SetupLog::Info(__METHOD__, null, ["product_name" => $aResult['product_name'], "product_version" => $aResult['product_version']]);
|
||||
|
||||
return count($aResult) == 0 ? false : $aResult;
|
||||
}
|
||||
|
||||
private function ComputeInstalledModules(array $aSelectInstall): array
|
||||
@@ -181,4 +192,47 @@ SQL;
|
||||
|
||||
return $aInstallByModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return previous module installation. offset is applied on parent_id.
|
||||
* @param $iOffset: by default (offset=0) returns current installation
|
||||
* @return array
|
||||
*/
|
||||
public static function GetPreviousModuleInstallationsByOffset(int $iOffset = 0): array
|
||||
{
|
||||
$oFilter = DBObjectSearch::FromOQL('SELECT ModuleInstallation AS mi WHERE mi.parent_id=0 AND mi.name!="datamodel"');
|
||||
$oSet = new DBObjectSet($oFilter, ['installed' => false]); // Most recent first
|
||||
$oSet->SetLimit($iOffset + 1);
|
||||
|
||||
$iParentId = 0;
|
||||
while (!is_null($oModuleInstallation = $oSet->Fetch())) {
|
||||
/** @var \DBObject $oModuleInstallation */
|
||||
if ($iOffset == 0) {
|
||||
$iParentId = $oModuleInstallation->Get('id');
|
||||
break;
|
||||
}
|
||||
$iOffset--;
|
||||
}
|
||||
|
||||
if ($iParentId === 0) {
|
||||
IssueLog::Error("no ITOP_APPLICATION ModuleInstallation found", null, ['offset' => $iOffset]);
|
||||
throw new \Exception("no ITOP_APPLICATION ModuleInstallation found");
|
||||
}
|
||||
|
||||
$oFilter = DBObjectSearch::FromOQL("SELECT ModuleInstallation AS mi WHERE mi.id=$iParentId OR mi.parent_id=$iParentId");
|
||||
$oSet = new DBObjectSet($oFilter); // Most recent first
|
||||
$aRawValues = $oSet->ToArrayOfValues();
|
||||
$aValues = [];
|
||||
foreach ($aRawValues as $aRawValue) {
|
||||
$aValue = [];
|
||||
foreach ($aRawValue as $sAliasAttCode => $sValue) {
|
||||
// remove 'mi.' from AttCode
|
||||
$sAttCode = substr($sAliasAttCode, 3);
|
||||
$aValue[$sAttCode] = $sValue;
|
||||
}
|
||||
|
||||
$aValues[] = $aValue;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,7 @@ abstract class ModuleInstallerAPI
|
||||
if (in_array($sTo, $aNewValues)) {
|
||||
$sEnumCol = $oAttDef->Get("sql");
|
||||
$aFields = CMDBSource::QueryToArray("SHOW COLUMNS FROM `$sTableName` WHERE Field = '$sEnumCol'");
|
||||
$aCurrentValues = [];
|
||||
if (isset($aFields[0]['Type'])) {
|
||||
$sColType = $aFields[0]['Type'];
|
||||
// Note: the parsing should rely on str_getcsv (requires PHP 5.3) to cope with escaped string
|
||||
|
||||
@@ -7,6 +7,7 @@ class InvalidParameterException extends Exception
|
||||
abstract class Parameters
|
||||
{
|
||||
public $aData = null;
|
||||
private ?array $aParamValues = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -26,24 +27,26 @@ abstract class Parameters
|
||||
*/
|
||||
public function GetParamForConfigArray()
|
||||
{
|
||||
$aDBParams = $this->Get('database');
|
||||
$aParamValues = [
|
||||
'mode' => $this->Get('mode'),
|
||||
'db_server' => $aDBParams['server'],
|
||||
'db_user' => $aDBParams['user'],
|
||||
'db_pwd' => $aDBParams['pwd'],
|
||||
'db_name' => $aDBParams['name'],
|
||||
'new_db_name' => $aDBParams['name'],
|
||||
'db_prefix' => $aDBParams['prefix'],
|
||||
'db_tls_enabled' => $aDBParams['db_tls_enabled'],
|
||||
'db_tls_ca' => $aDBParams['db_tls_ca'],
|
||||
'application_path' => $this->Get('url', ''),
|
||||
'language' => $this->Get('language', ''),
|
||||
'graphviz_path' => $this->Get('graphviz_path', ''),
|
||||
'source_dir' => $this->Get('source_dir', ''),
|
||||
];
|
||||
if (is_null($this->aParamValues)) {
|
||||
$aDBParams = $this->Get('database');
|
||||
$this->aParamValues = [
|
||||
'mode' => $this->Get('mode'),
|
||||
'db_server' => $aDBParams['server'],
|
||||
'db_user' => $aDBParams['user'],
|
||||
'db_pwd' => $aDBParams['pwd'],
|
||||
'db_name' => $aDBParams['name'],
|
||||
'new_db_name' => $aDBParams['name'],
|
||||
'db_prefix' => $aDBParams['prefix'],
|
||||
'db_tls_enabled' => $aDBParams['db_tls_enabled'],
|
||||
'db_tls_ca' => $aDBParams['db_tls_ca'],
|
||||
'application_path' => $this->Get('url', ''),
|
||||
'language' => $this->Get('language', ''),
|
||||
'graphviz_path' => $this->Get('graphviz_path', ''),
|
||||
'source_dir' => $this->Get('source_dir', ''),
|
||||
];
|
||||
}
|
||||
|
||||
return $aParamValues;
|
||||
return $this->aParamValues;
|
||||
}
|
||||
|
||||
public function Set($sCode, $value)
|
||||
@@ -104,7 +107,9 @@ class PHPParameters extends Parameters
|
||||
{
|
||||
if ($this->aData == null) {
|
||||
require_once($sParametersFile);
|
||||
$this->aData = $ITOP_PARAMS; // Defined in the file loaded just above
|
||||
if (isset($ITOP_PARAMS)) {
|
||||
$this->aData = $ITOP_PARAMS; // Defined in the file loaded just above
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ require_once APPROOT."setup/modulediscovery.class.inc.php";
|
||||
require_once APPROOT.'setup/modelfactory.class.inc.php';
|
||||
require_once APPROOT.'setup/compiler.class.inc.php';
|
||||
require_once APPROOT.'setup/extensionsmap.class.inc.php';
|
||||
require_once APPROOT.'setup/AnalyzeInstallation.php';
|
||||
require_once APPROOT.'setup/moduleinstallation/AnalyzeInstallation.php';
|
||||
require_once APPROOT.'/setup/moduleinstallation/InstallationChoicesToModuleConverter.php';
|
||||
|
||||
define('MODULE_ACTION_OPTIONAL', 1);
|
||||
define('MODULE_ACTION_MANDATORY', 2);
|
||||
@@ -126,11 +127,10 @@ class RunTimeEnvironment
|
||||
* from the given file
|
||||
* @param $oConfig object The configuration (volatile, not necessarily already on disk)
|
||||
* @param $bModelOnly boolean Whether or not to allow loading a data model with no corresponding DB
|
||||
* @return none
|
||||
*/
|
||||
public function InitDataModel($oConfig, $bModelOnly = true, $bUseCache = false)
|
||||
public function InitDataModel($oConfig, $bModelOnly = true, $bUseCache = false): void
|
||||
{
|
||||
require_once APPROOT.'/setup/moduleinstallation.class.inc.php';
|
||||
require_once APPROOT.'/setup/moduleinstallation/moduleinstallation.class.inc.php';
|
||||
|
||||
$sConfigFile = $oConfig->GetLoadedFile();
|
||||
if (strlen($sConfigFile) > 0) {
|
||||
@@ -226,12 +226,30 @@ class RunTimeEnvironment
|
||||
return ($oExtension->sSource == iTopExtension::SOURCE_REMOTE);
|
||||
}
|
||||
|
||||
public function GetExtraDirsToCompile(string $sSourceDir): array
|
||||
{
|
||||
$sSourceDirFull = APPROOT.$sSourceDir;
|
||||
if (!is_dir($sSourceDirFull)) {
|
||||
throw new Exception("The source directory '$sSourceDirFull' does not exist (or could not be read)");
|
||||
}
|
||||
$aDirsToCompile = [$sSourceDirFull];
|
||||
|
||||
if (is_dir(APPROOT.'extensions')) {
|
||||
$aDirsToCompile[] = APPROOT.'extensions';
|
||||
}
|
||||
$sExtraDir = utils::GetDataPath().$this->sTargetEnv.'-modules/';
|
||||
if (is_dir($sExtraDir)) {
|
||||
$aDirsToCompile[] = $sExtraDir;
|
||||
}
|
||||
|
||||
return $aDirsToCompile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the installed modules (only the installed ones)
|
||||
*/
|
||||
protected function GetMFModulesToCompile($sSourceEnv, $sSourceDir)
|
||||
{
|
||||
\SetupLog::Info(__METHOD__);
|
||||
$sSourceDirFull = APPROOT.$sSourceDir;
|
||||
if (!is_dir($sSourceDirFull)) {
|
||||
throw new Exception("The source directory '$sSourceDirFull' does not exist (or could not be read)");
|
||||
@@ -348,6 +366,7 @@ class RunTimeEnvironment
|
||||
//
|
||||
$oFactory = new ModelFactory($sSourceDirFull);
|
||||
$aModulesToCompile = $this->GetMFModulesToCompile($sSourceEnv, $sSourceDir);
|
||||
$oModule = null;
|
||||
foreach ($aModulesToCompile as $oModule) {
|
||||
if ($oModule instanceof MFDeltaModule) {
|
||||
// Just before loading the delta, let's save an image of the datamodel
|
||||
@@ -357,7 +376,7 @@ class RunTimeEnvironment
|
||||
$oFactory->LoadModule($oModule);
|
||||
}
|
||||
|
||||
if ($oModule instanceof MFDeltaModule) {
|
||||
if (!is_null($oModule) && ($oModule instanceof MFDeltaModule)) {
|
||||
// A delta was loaded, let's save a second copy of the datamodel
|
||||
$oFactory->SaveToFile(utils::GetDataPath().'datamodel-'.$this->sTargetEnv.'-with-delta.xml');
|
||||
} else {
|
||||
@@ -549,9 +568,14 @@ class RunTimeEnvironment
|
||||
//
|
||||
$aAvailableModules = $this->AnalyzeInstallation($oConfig, $this->GetBuildDir());
|
||||
foreach ($aSelectedModuleCodes as $sModuleId) {
|
||||
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!array_key_exists($sModuleId, $aAvailableModules)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$aModuleData = $aAvailableModules[$sModuleId];
|
||||
$sName = $sModuleId;
|
||||
$sVersion = $aModuleData['available_version'];
|
||||
@@ -625,7 +649,7 @@ class RunTimeEnvironment
|
||||
public function GetApplicationVersion(Config $oConfig)
|
||||
{
|
||||
try {
|
||||
$aSelectInstall = ModuleInstallationService::GetInstance()->ReadFromDB($oConfig);
|
||||
$aSelectInstall = ModuleInstallationRepository::GetInstance()->ReadFromDB($oConfig);
|
||||
} catch (MySQLException $e) {
|
||||
// No database or erroneous information
|
||||
$this->log_error('Can not connect to the database: host: '.$oConfig->Get('db_host').', user:'.$oConfig->Get('db_user').', pwd:'.$oConfig->Get('db_pwd').', db name:'.$oConfig->Get('db_name'));
|
||||
@@ -663,7 +687,8 @@ class RunTimeEnvironment
|
||||
$aResult['datamodel_version'] = $aResult['product_version'];
|
||||
}
|
||||
$this->log_info("GetApplicationVersion returns: product_name: ".$aResult['product_name'].', product_version: '.$aResult['product_version']);
|
||||
return empty($aResult) ? false : $aResult;
|
||||
|
||||
return count($aResult) == 0 ? false : $aResult;
|
||||
}
|
||||
|
||||
public static function MakeDirSafe($sDir)
|
||||
@@ -851,16 +876,20 @@ class RunTimeEnvironment
|
||||
/**
|
||||
* Call the given handler method for all selected modules having an installation handler
|
||||
* @param array[] $aAvailableModules
|
||||
* @param string[] $aSelectedModules
|
||||
* @param string $sHandlerName
|
||||
* @param string[]|null $aSelectedModules
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function CallInstallerHandlers($aAvailableModules, $aSelectedModules, $sHandlerName)
|
||||
public function CallInstallerHandlers($aAvailableModules, $sHandlerName, $aSelectedModules = null)
|
||||
{
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule) {
|
||||
if (($sModuleId != ROOT_MODULE) && in_array($sModuleId, $aSelectedModules)) {
|
||||
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_null($aSelectedModules) || in_array($sModuleId, $aSelectedModules)) {
|
||||
$aArgs = [MetaModel::GetConfig(), $aModule['installed_version'], $aModule['available_version']];
|
||||
RunTimeEnvironment::CallInstallerHandler($aAvailableModules[$sModuleId], $sHandlerName, $aArgs);
|
||||
RunTimeEnvironment::CallInstallerHandler($aModule, $sHandlerName, $aArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -887,6 +916,7 @@ class RunTimeEnvironment
|
||||
try {
|
||||
call_user_func_array($aCallSpec, $aArgs);
|
||||
} catch (Exception $e) {
|
||||
$sModuleId = $aModuleInfo[ModuleFileReader::MODULE_INFO_ID] ?? "";
|
||||
$sErrorMessage = "Module $sModuleId : error when calling module installer class $sModuleInstallerClass for $sHandlerName handler";
|
||||
$aExceptionContextData = [
|
||||
'ModulelId' => $sModuleId,
|
||||
@@ -903,10 +933,10 @@ class RunTimeEnvironment
|
||||
/**
|
||||
* Load data from XML files for the selected modules (structural data and/or sample data)
|
||||
* @param array[] $aAvailableModules All available modules and their definition
|
||||
* @param string[] $aSelectedModules List of selected modules
|
||||
* @param bool $bSampleData Wether or not to load sample data
|
||||
* @param null|string[] $aSelectedModules List of selected modules
|
||||
*/
|
||||
public function LoadData($aAvailableModules, $aSelectedModules, $bSampleData)
|
||||
public function LoadData($aAvailableModules, $bSampleData, $aSelectedModules = null)
|
||||
{
|
||||
$oDataLoader = new XMLDataLoader();
|
||||
|
||||
@@ -919,30 +949,33 @@ class RunTimeEnvironment
|
||||
$aFiles = [];
|
||||
$aPreviouslyLoadedFiles = [];
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule) {
|
||||
if (($sModuleId != ROOT_MODULE)) {
|
||||
$sRelativePath = 'env-'.$this->sTargetEnv.'/'.basename($aModule['root_dir']);
|
||||
// Load data only for selected AND newly installed modules
|
||||
if (in_array($sModuleId, $aSelectedModules)) {
|
||||
if ($aModule['installed_version'] != '') {
|
||||
// Simulate the load of the previously loaded XML files to get the mapping of the keys
|
||||
if ($bSampleData) {
|
||||
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.sample']);
|
||||
} else {
|
||||
// Load only structural data
|
||||
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
}
|
||||
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sRelativePath = 'env-'.$this->sTargetEnv.'/'.basename($aModule['root_dir']);
|
||||
// Load data only for selected AND newly installed modules
|
||||
if (is_null($aSelectedModules) || in_array($sModuleId, $aSelectedModules)) {
|
||||
if ($aModule['installed_version'] != '') {
|
||||
// Simulate the load of the previously loaded XML files to get the mapping of the keys
|
||||
if ($bSampleData) {
|
||||
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.sample']);
|
||||
} else {
|
||||
if ($bSampleData) {
|
||||
$aFiles = static::MergeWithRelativeDir($aFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
$aFiles = static::MergeWithRelativeDir($aFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.sample']);
|
||||
} else {
|
||||
// Load only structural data
|
||||
$aFiles = static::MergeWithRelativeDir($aFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
}
|
||||
// Load only structural data
|
||||
$aPreviouslyLoadedFiles = static::MergeWithRelativeDir($aPreviouslyLoadedFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
}
|
||||
} else {
|
||||
if ($bSampleData) {
|
||||
$aFiles = static::MergeWithRelativeDir($aFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
$aFiles = static::MergeWithRelativeDir($aFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.sample']);
|
||||
} else {
|
||||
// Load only structural data
|
||||
$aFiles = static::MergeWithRelativeDir($aFiles, $sRelativePath, $aAvailableModules[$sModuleId]['data.struct']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Simulate the load of the previously loaded files, in order to initialize
|
||||
@@ -951,7 +984,7 @@ class RunTimeEnvironment
|
||||
foreach ($aPreviouslyLoadedFiles as $sFileRelativePath) {
|
||||
$sFileName = APPROOT.$sFileRelativePath;
|
||||
SetupLog::Info("Loading file: $sFileName (just to get the keys mapping)");
|
||||
if (empty($sFileName) || !file_exists($sFileName)) {
|
||||
if (!file_exists($sFileName)) {
|
||||
throw(new Exception("File $sFileName does not exist"));
|
||||
}
|
||||
|
||||
@@ -963,7 +996,7 @@ class RunTimeEnvironment
|
||||
foreach ($aFiles as $sFileRelativePath) {
|
||||
$sFileName = APPROOT.$sFileRelativePath;
|
||||
SetupLog::Info("Loading file: $sFileName");
|
||||
if (empty($sFileName) || !file_exists($sFileName)) {
|
||||
if (!file_exists($sFileName)) {
|
||||
throw(new Exception("File $sFileName does not exist"));
|
||||
}
|
||||
|
||||
@@ -1029,4 +1062,4 @@ class RunTimeEnvironment
|
||||
|
||||
return sprintf("Checked %d classes in %.1f ms. No error found.\n", $iCount, $fDuration * 1000.0);
|
||||
}
|
||||
} // End of class
|
||||
} // End of class
|
||||
|
||||
972
setup/sequencers/ApplicationInstallSequencer.php
Normal file
972
setup/sequencers/ApplicationInstallSequencer.php
Normal file
@@ -0,0 +1,972 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
require_once(APPROOT.'setup/parameters.class.inc.php');
|
||||
require_once(APPROOT.'setup/xmldataloader.class.inc.php');
|
||||
require_once(APPROOT.'setup/backup.class.inc.php');
|
||||
|
||||
require_once(APPROOT.'setup/sequencers/StepSequencer.php');
|
||||
require_once(APPROOT.'setup/SetupDBBackup.php');
|
||||
|
||||
/**
|
||||
* The base class for the installation process.
|
||||
* The installation process is split into a sequence of unitary steps
|
||||
* for performance reasons (i.e; timeout, memory usage) and also in order
|
||||
* to provide some feedback about the progress of the installation.
|
||||
*
|
||||
* This class can be used for a step by step interactive installation
|
||||
* while displaying a progress bar, or in an unattended manner
|
||||
* (for example from the command line), to run all the steps
|
||||
* in one go.
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
class ApplicationInstallSequencer extends StepSequencer
|
||||
{
|
||||
/** @var \Parameters */
|
||||
protected $oParams;
|
||||
protected static $bMetaModelStarted = false;
|
||||
|
||||
protected Config $oConfig;
|
||||
|
||||
/**
|
||||
* @param \Parameters $oParams
|
||||
*
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function __construct($oParams)
|
||||
{
|
||||
$this->oParams = $oParams;
|
||||
|
||||
$aParamValues = $oParams->GetParamForConfigArray();
|
||||
$this->oConfig = new Config();
|
||||
$this->oConfig->UpdateFromParams($aParamValues);
|
||||
utils::SetConfig($this->oConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function GetTargetEnv()
|
||||
{
|
||||
$sTargetEnvironment = $this->oParams->Get('target_env', '');
|
||||
if ($sTargetEnvironment !== '') {
|
||||
return $sTargetEnvironment;
|
||||
}
|
||||
|
||||
return 'production';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function GetTargetDir()
|
||||
{
|
||||
$sTargetEnv = $this->GetTargetEnv();
|
||||
return 'env-'.$sTargetEnv;
|
||||
}
|
||||
|
||||
protected function GetConfig()
|
||||
{
|
||||
$sTargetEnvironment = $this->GetTargetEnv();
|
||||
$sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE;
|
||||
try {
|
||||
$oConfig = new Config($sConfigFile);
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
$oConfig->UpdateFromParams($aParamValues);
|
||||
|
||||
return $oConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the next step of the installation and reports about the progress
|
||||
* and the next step to perform
|
||||
*
|
||||
* @param string $sStep The identifier of the step to execute
|
||||
* @param string|null $sInstallComment
|
||||
*
|
||||
* @return array (status => , message => , percentage-completed => , next-step => , next-step-label => )
|
||||
*/
|
||||
public function ExecuteStep($sStep = '', $sInstallComment = null)
|
||||
{
|
||||
try {
|
||||
$fStart = microtime(true);
|
||||
SetupLog::Info("##### STEP {$sStep} start");
|
||||
$this->EnterReadOnlyMode();
|
||||
switch ($sStep) {
|
||||
case '':
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'percentage-completed' => 0,
|
||||
'next-step' => 'copy',
|
||||
'next-step-label' => 'Copying data model files',
|
||||
];
|
||||
|
||||
// Log the parameters...
|
||||
$oDoc = new DOMDocument('1.0', 'UTF-8');
|
||||
$oDoc->preserveWhiteSpace = false;
|
||||
$oDoc->formatOutput = true;
|
||||
$this->oParams->ToXML($oDoc, null, 'installation');
|
||||
$sXML = $oDoc->saveXML();
|
||||
$sSafeXml = preg_replace("|<pwd>([^<]*)</pwd>|", "<pwd>**removed**</pwd>", $sXML);
|
||||
SetupLog::Info("======= Installation starts =======\nParameters:\n$sSafeXml\n");
|
||||
|
||||
// Save the response file as a stand-alone file as well
|
||||
$sFileName = 'install-'.date('Y-m-d');
|
||||
$index = 0;
|
||||
while (file_exists(APPROOT.'log/'.$sFileName.'.xml')) {
|
||||
$index++;
|
||||
$sFileName = 'install-'.date('Y-m-d').'-'.$index;
|
||||
}
|
||||
file_put_contents(APPROOT.'log/'.$sFileName.'.xml', $sSafeXml);
|
||||
|
||||
break;
|
||||
|
||||
case 'copy':
|
||||
$aPreinstall = $this->oParams->Get('preinstall');
|
||||
$aCopies = $aPreinstall['copies'] ?? [];
|
||||
|
||||
$this->DoCopy($aCopies);
|
||||
$sReport = "Copying...";
|
||||
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => $sReport,
|
||||
];
|
||||
if (isset($aPreinstall['backup'])) {
|
||||
$aResult['next-step'] = 'backup';
|
||||
$aResult['next-step-label'] = 'Performing a backup of the database';
|
||||
$aResult['percentage-completed'] = 20;
|
||||
} else {
|
||||
$aResult['next-step'] = 'compile';
|
||||
$aResult['next-step-label'] = 'Compiling the data model';
|
||||
$aResult['percentage-completed'] = 20;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backup':
|
||||
$aPreinstall = $this->oParams->Get('preinstall');
|
||||
// __DB__-%Y-%m-%d
|
||||
$sDestination = $aPreinstall['backup']['destination'];
|
||||
$sSourceConfigFile = $aPreinstall['backup']['configuration_file'];
|
||||
$sMySQLBinDir = $this->oParams->Get('mysql_bindir', null);
|
||||
$this->DoBackup($sDestination, $sSourceConfigFile, $sMySQLBinDir);
|
||||
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => "Created backup",
|
||||
'next-step' => 'compile',
|
||||
'next-step-label' => 'Compiling the data model',
|
||||
'percentage-completed' => 20,
|
||||
];
|
||||
break;
|
||||
|
||||
case 'compile':
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules');
|
||||
$sSourceDir = $this->oParams->Get('source_dir', 'datamodels/latest');
|
||||
$sExtensionDir = $this->oParams->Get('extensions_dir', 'extensions');
|
||||
$aMiscOptions = $this->oParams->Get('options', []);
|
||||
$aRemovedExtensionCodes = $this->oParams->Get('removed_extensions', []);
|
||||
|
||||
$bUseSymbolicLinks = null;
|
||||
if ((isset($aMiscOptions['symlinks']) && $aMiscOptions['symlinks'])) {
|
||||
if (function_exists('symlink')) {
|
||||
$bUseSymbolicLinks = true;
|
||||
SetupLog::Info("Using symbolic links instead of copying data model files (for developers only!)");
|
||||
} else {
|
||||
SetupLog::Info("Symbolic links (function symlinks) does not seem to be supported on this platform (OS/PHP version).");
|
||||
}
|
||||
}
|
||||
|
||||
$this->DoCompile(
|
||||
$aRemovedExtensionCodes,
|
||||
$aSelectedModules,
|
||||
$sSourceDir,
|
||||
$sExtensionDir,
|
||||
$bUseSymbolicLinks
|
||||
);
|
||||
|
||||
$sNextStep = 'db-schema';
|
||||
$sNextStepLabel = 'Updating database schema';
|
||||
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => $sNextStep,
|
||||
'next-step-label' => $sNextStepLabel,
|
||||
'percentage-completed' => 40,
|
||||
];
|
||||
break;
|
||||
|
||||
case 'db-schema':
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules', []);
|
||||
|
||||
$this->DoUpdateDBSchema(
|
||||
$aSelectedModules
|
||||
);
|
||||
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'after-db-create',
|
||||
'next-step-label' => 'Creating profiles',
|
||||
'percentage-completed' => 60,
|
||||
];
|
||||
break;
|
||||
|
||||
case 'after-db-create':
|
||||
$aAdminParams = $this->oParams->Get('admin_account');
|
||||
$sAdminUser = $aAdminParams['user'];
|
||||
$sAdminPwd = $aAdminParams['pwd'];
|
||||
$sAdminLanguage = $aAdminParams['language'];
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules', []);
|
||||
|
||||
$this->AfterDBCreate(
|
||||
$sAdminUser,
|
||||
$sAdminPwd,
|
||||
$sAdminLanguage,
|
||||
$aSelectedModules
|
||||
);
|
||||
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'load-data',
|
||||
'next-step-label' => 'Loading data',
|
||||
'percentage-completed' => 80,
|
||||
];
|
||||
break;
|
||||
|
||||
case 'load-data':
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules');
|
||||
$bSampleData = ($this->oParams->Get('sample_data', 0) == 1);
|
||||
|
||||
$this->DoLoadFiles(
|
||||
$aSelectedModules,
|
||||
$bSampleData
|
||||
);
|
||||
|
||||
$aResult = [
|
||||
'status' => self::INFO,
|
||||
'message' => 'All data loaded',
|
||||
'next-step' => 'create-config',
|
||||
'next-step-label' => 'Creating the configuration File',
|
||||
'percentage-completed' => 99,
|
||||
];
|
||||
break;
|
||||
|
||||
case 'create-config':
|
||||
$sPreviousConfigFile = $this->oParams->Get('previous_configuration_file', '');
|
||||
$sDataModelVersion = $this->oParams->Get('datamodel_version', '0.0.0');
|
||||
$aSelectedModuleCodes = $this->oParams->Get('selected_modules', []);
|
||||
$aSelectedExtensionCodes = $this->oParams->Get('selected_extensions', []);
|
||||
|
||||
$this->DoCreateConfig(
|
||||
$sPreviousConfigFile,
|
||||
$sDataModelVersion,
|
||||
$aSelectedModuleCodes,
|
||||
$aSelectedExtensionCodes,
|
||||
$sInstallComment
|
||||
);
|
||||
|
||||
$aResult = [
|
||||
'status' => self::INFO,
|
||||
'message' => 'Configuration file created',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Completed',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
$this->ExitReadOnlyMode();
|
||||
break;
|
||||
|
||||
default:
|
||||
$aResult = [
|
||||
'status' => self::ERROR,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => "Unknown setup step '$sStep'.",
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$aResult = [
|
||||
'status' => self::ERROR,
|
||||
'message' => $e->getMessage(),
|
||||
'next-step' => '',
|
||||
'next-step-label' => '',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
|
||||
SetupLog::Error('An exception occurred: '.$e->getMessage().' at line '.$e->getLine().' in file '.$e->getFile());
|
||||
$idx = 0;
|
||||
// Log the call stack, but not the parameters since they may contain passwords or other sensitive data
|
||||
SetupLog::Ok("Call stack:");
|
||||
foreach ($e->getTrace() as $aTrace) {
|
||||
$sLine = empty($aTrace['line']) ? "" : $aTrace['line'];
|
||||
$sFile = empty($aTrace['file']) ? "" : $aTrace['file'];
|
||||
$sClass = empty($aTrace['class']) ? "" : $aTrace['class'];
|
||||
$sType = empty($aTrace['type']) ? "" : $aTrace['type'];
|
||||
$sFunction = empty($aTrace['function']) ? "" : $aTrace['function'];
|
||||
$sVerb = empty($sClass) ? $sFunction : "$sClass{$sType}$sFunction";
|
||||
SetupLog::Ok("#$idx $sFile($sLine): $sVerb(...)");
|
||||
$idx++;
|
||||
}
|
||||
} finally {
|
||||
$fDuration = round(microtime(true) - $fStart, 2);
|
||||
SetupLog::Info("##### STEP {$sStep} duration: {$fDuration}s");
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
protected function EnterReadOnlyMode()
|
||||
{
|
||||
if ($this->GetTargetEnv() != 'production') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SetupUtils::IsInReadOnlyMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetupUtils::EnterReadOnlyMode($this->GetConfig());
|
||||
}
|
||||
|
||||
protected function ExitReadOnlyMode()
|
||||
{
|
||||
if ($this->GetTargetEnv() != 'production') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetupUtils::IsInReadOnlyMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetupUtils::ExitReadOnlyMode();
|
||||
}
|
||||
|
||||
protected function DoCopy($aCopies)
|
||||
{
|
||||
$aReports = [];
|
||||
foreach ($aCopies as $aCopy) {
|
||||
$sSource = $aCopy['source'];
|
||||
$sDestination = APPROOT.$aCopy['destination'];
|
||||
|
||||
SetupUtils::builddir($sDestination);
|
||||
SetupUtils::tidydir($sDestination);
|
||||
SetupUtils::copydir($sSource, $sDestination);
|
||||
$aReports[] = "'{$aCopy['source']}' to '{$aCopy['destination']}' (OK)";
|
||||
}
|
||||
if (count($aReports) > 0) {
|
||||
$sReport = "Copies: ".count($aReports).': '.implode('; ', $aReports);
|
||||
} else {
|
||||
$sReport = "No file copy";
|
||||
}
|
||||
return $sReport;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sBackupFileFormat
|
||||
* @param string $sSourceConfigFile
|
||||
* @param string $sMySQLBinDir
|
||||
*
|
||||
* @throws \BackupException
|
||||
* @throws \CoreException
|
||||
* @throws \MySQLException
|
||||
* @since 2.5.0 uses a {@link Config} object to store DB parameters
|
||||
*/
|
||||
protected function DoBackup($sBackupFileFormat, $sSourceConfigFile, $sMySQLBinDir = null)
|
||||
{
|
||||
$oBackup = new SetupDBBackup($this->oConfig);
|
||||
$sTargetFile = $oBackup->MakeName($sBackupFileFormat);
|
||||
if (!empty($sMySQLBinDir)) {
|
||||
$oBackup->SetMySQLBinDir($sMySQLBinDir);
|
||||
}
|
||||
|
||||
CMDBSource::InitFromConfig($this->oConfig);
|
||||
$oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aRemovedExtensionCodes
|
||||
* @param array $aSelectedModules
|
||||
* @param string $sSourceDir
|
||||
* @param string $sExtensionDir
|
||||
* @param boolean $bUseSymbolicLinks
|
||||
*
|
||||
* @return void
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
*
|
||||
* @since 3.1.0 N°2013 added the aParamValues param
|
||||
*/
|
||||
protected function DoCompile($aRemovedExtensionCodes, $aSelectedModules, $sSourceDir, $sExtensionDir, $bUseSymbolicLinks = null)
|
||||
{
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
*/
|
||||
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
|
||||
|
||||
SetupLog::Info("Compiling data model.");
|
||||
|
||||
require_once(APPROOT.'setup/modulediscovery.class.inc.php');
|
||||
require_once(APPROOT.'setup/modelfactory.class.inc.php');
|
||||
require_once(APPROOT.'setup/compiler.class.inc.php');
|
||||
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
$sEnvironment = $this->GetTargetEnv();
|
||||
$sTargetDir = $this->GetTargetDir();
|
||||
|
||||
if (empty($sSourceDir) || empty($sTargetDir)) {
|
||||
throw new Exception("missing parameter source_dir and/or target_dir");
|
||||
}
|
||||
|
||||
$sSourcePath = APPROOT.$sSourceDir;
|
||||
$aDirsToScan = [$sSourcePath];
|
||||
$sExtensionsPath = APPROOT.$sExtensionDir;
|
||||
if (is_dir($sExtensionsPath)) {
|
||||
// if the extensions dir exists, scan it for additional modules as well
|
||||
$aDirsToScan[] = $sExtensionsPath;
|
||||
}
|
||||
$sExtraPath = APPROOT.'/data/'.$sEnvironment.'-modules/';
|
||||
if (is_dir($sExtraPath)) {
|
||||
// if the extra dir exists, scan it for additional modules as well
|
||||
$aDirsToScan[] = $sExtraPath;
|
||||
}
|
||||
$sTargetPath = APPROOT.$sTargetDir;
|
||||
|
||||
if (!is_dir($sSourcePath)) {
|
||||
throw new Exception("Failed to find the source directory '$sSourcePath', please check the rights of the web server");
|
||||
}
|
||||
|
||||
$bIsAlreadyInMaintenanceMode = SetupUtils::IsInMaintenanceMode();
|
||||
|
||||
if (($sEnvironment == 'production') && !$bIsAlreadyInMaintenanceMode) {
|
||||
$sConfigFilePath = utils::GetConfigFilePath($sEnvironment);
|
||||
if (is_file($sConfigFilePath)) {
|
||||
$oConfig = new Config($sConfigFilePath);
|
||||
$oConfig->UpdateFromParams($aParamValues);
|
||||
SetupUtils::EnterMaintenanceMode($oConfig);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (!is_dir($sTargetPath)) {
|
||||
if (!mkdir($sTargetPath)) {
|
||||
throw new Exception("Failed to create directory '$sTargetPath', please check the rights of the web server");
|
||||
} else {
|
||||
// adjust the rights if and only if the directory was just created
|
||||
// owner:rwx user/group:rx
|
||||
chmod($sTargetPath, 0755);
|
||||
}
|
||||
} elseif (substr($sTargetPath, 0, strlen(APPROOT)) == APPROOT) {
|
||||
// If the directory is under the root folder - as expected - let's clean-it before compiling
|
||||
SetupUtils::tidydir($sTargetPath);
|
||||
}
|
||||
|
||||
$oExtensionsMap = new iTopExtensionsMap('production', $aDirsToScan);
|
||||
$oExtensionsMap->DeclareExtensionAsRemoved($aRemovedExtensionCodes);
|
||||
|
||||
$oFactory = new ModelFactory($aDirsToScan);
|
||||
|
||||
$oDictModule = new MFDictModule('dictionaries', 'iTop Dictionaries', APPROOT.'dictionaries');
|
||||
$oFactory->LoadModule($oDictModule);
|
||||
|
||||
$sDeltaFile = APPROOT.'core/datamodel.core.xml';
|
||||
if (file_exists($sDeltaFile)) {
|
||||
$oCoreModule = new MFCoreModule('core', 'Core Module', $sDeltaFile);
|
||||
$oFactory->LoadModule($oCoreModule);
|
||||
}
|
||||
$sDeltaFile = APPROOT.'application/datamodel.application.xml';
|
||||
if (file_exists($sDeltaFile)) {
|
||||
$oApplicationModule = new MFCoreModule('application', 'Application Module', $sDeltaFile);
|
||||
$oFactory->LoadModule($oApplicationModule);
|
||||
}
|
||||
|
||||
$aModules = $oFactory->FindModules();
|
||||
|
||||
foreach ($aModules as $oModule) {
|
||||
$sModule = $oModule->GetName();
|
||||
if (in_array($sModule, $aSelectedModules)) {
|
||||
$oFactory->LoadModule($oModule);
|
||||
}
|
||||
}
|
||||
// Dump the "reference" model, just before loading any actual delta
|
||||
$oFactory->SaveToFile(utils::GetDataPath().'datamodel-'.$sEnvironment.'.xml');
|
||||
|
||||
$sDeltaFile = utils::GetDataPath().$sEnvironment.'.delta.xml';
|
||||
if (file_exists($sDeltaFile)) {
|
||||
$oDelta = new MFDeltaModule($sDeltaFile);
|
||||
$oFactory->LoadModule($oDelta);
|
||||
$oFactory->SaveToFile(utils::GetDataPath().'datamodel-'.$sEnvironment.'-with-delta.xml');
|
||||
}
|
||||
|
||||
$oMFCompiler = new MFCompiler($oFactory, $sEnvironment);
|
||||
$oMFCompiler->Compile($sTargetPath, null, $bUseSymbolicLinks);
|
||||
//$aCompilerLog = $oMFCompiler->GetLog();
|
||||
//SetupLog::Info(implode("\n", $aCompilerLog));
|
||||
SetupLog::Info("Data model successfully compiled to '$sTargetPath'.");
|
||||
|
||||
$sCacheDir = APPROOT.'/data/cache-'.$sEnvironment.'/';
|
||||
SetupUtils::builddir($sCacheDir);
|
||||
SetupUtils::tidydir($sCacheDir);
|
||||
} catch (Exception $e) {
|
||||
if (($sEnvironment == 'production') && !$bIsAlreadyInMaintenanceMode) {
|
||||
SetupUtils::ExitMaintenanceMode();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// Special case to patch a ugly patch in itop-config-mgmt
|
||||
$sFileToPatch = $sTargetPath.'/itop-config-mgmt-1.0.0/model.itop-config-mgmt.php';
|
||||
if (file_exists($sFileToPatch)) {
|
||||
$sContent = file_get_contents($sFileToPatch);
|
||||
|
||||
$sContent = str_replace("require_once(APPROOT.'modules/itop-welcome-itil/model.itop-welcome-itil.php');", "//\n// The line below is no longer needed in iTop 2.0 -- patched by the setup program\n// require_once(APPROOT.'modules/itop-welcome-itil/model.itop-welcome-itil.php');", $sContent);
|
||||
|
||||
file_put_contents($sFileToPatch, $sContent);
|
||||
}
|
||||
|
||||
// Set an "Instance UUID" identifying this machine based on a file located in the data directory
|
||||
$sInstanceUUIDFile = utils::GetDataPath().'instance.txt';
|
||||
SetupUtils::builddir(utils::GetDataPath());
|
||||
if (!file_exists($sInstanceUUIDFile)) {
|
||||
$sIntanceUUID = utils::CreateUUID('filesystem');
|
||||
file_put_contents($sInstanceUUIDFile, $sIntanceUUID);
|
||||
}
|
||||
if (($sEnvironment == 'production') && !$bIsAlreadyInMaintenanceMode) {
|
||||
SetupUtils::ExitMaintenanceMode();
|
||||
}
|
||||
}
|
||||
|
||||
protected function GetModelInfoPath(string $sEnv): string
|
||||
{
|
||||
return APPROOT."data/beforecompilation_".$sEnv."_modelinfo.json";
|
||||
}
|
||||
|
||||
protected function SaveModelInfo(string $sEnvironment): bool
|
||||
{
|
||||
$sModelInfoPath = $this->GetModelInfoPath($sEnvironment);
|
||||
try {
|
||||
$aModelInfo = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($sEnvironment);
|
||||
} catch (Exception $e) {
|
||||
//logged already
|
||||
return is_file($sModelInfoPath);
|
||||
}
|
||||
|
||||
return (bool) file_put_contents($sModelInfoPath, json_encode($aModelInfo));
|
||||
}
|
||||
|
||||
protected function GetPreviousModelInfo(string $sEnvironment): array
|
||||
{
|
||||
$sContent = file_get_contents($this->GetModelInfoPath($sEnvironment));
|
||||
$aModelInfo = json_decode($sContent, true);
|
||||
|
||||
if (false === $aModelInfo) {
|
||||
throw new Exception("Could not read (before compilation) previous model to audit data");
|
||||
}
|
||||
|
||||
return $aModelInfo;
|
||||
}
|
||||
|
||||
protected function IsSetupDataAuditEnabled($sSkipDataAudit, array $aParamValues): bool
|
||||
{
|
||||
if ($sSkipDataAudit === "checked") {
|
||||
SetupLog::Info("Setup data audit disabled", null, ['skip-data-audit' => $sSkipDataAudit]);
|
||||
return false;
|
||||
}
|
||||
|
||||
$sMode = $aParamValues['mode'];
|
||||
if ($sMode !== "upgrade") {
|
||||
//first install
|
||||
return false;
|
||||
}
|
||||
|
||||
$sPath = APPROOT.$this->GetTargetDir();
|
||||
if (!is_dir($sPath)) {
|
||||
SetupLog::Info("Reinstallation of an iTop from a backup (No ".$this->GetTargetDir()." found). Setup data audit disabled", null, ['skip-data-audit' => $sSkipDataAudit]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $aSelectedModules
|
||||
*
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
protected function DoUpdateDBSchema($aSelectedModules)
|
||||
{
|
||||
$sTargetEnvironment = $this->GetTargetEnv();
|
||||
$sModulesDir = $this->GetTargetDir();
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
*/
|
||||
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
|
||||
SetupLog::Info("Update Database Schema for environment '$sTargetEnvironment'.");
|
||||
$sMode = $aParamValues['mode'];
|
||||
$sDBPrefix = $aParamValues['db_prefix'];
|
||||
$sDBName = $aParamValues['db_name'];
|
||||
|
||||
$oConfig = new Config();
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
|
||||
|
||||
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
|
||||
$oProductionEnv->InitDataModel($oConfig, true); // load data model only
|
||||
|
||||
// Migrate columns
|
||||
self::MoveColumns($sDBPrefix);
|
||||
|
||||
// Migrate application data format
|
||||
//
|
||||
// priv_internalUser caused troubles because MySQL transforms table names to lower case under Windows
|
||||
// This becomes an issue when moving your installation data to/from Windows
|
||||
// Starting 2.0, all table names must be lowercase
|
||||
if ($sMode != 'install') {
|
||||
SetupLog::Info("Renaming '{$sDBPrefix}priv_internalUser' into '{$sDBPrefix}priv_internaluser' (lowercase)");
|
||||
// This command will have no effect under Windows...
|
||||
// and it has been written in two steps so as to make it work under windows!
|
||||
CMDBSource::SelectDB($sDBName);
|
||||
try {
|
||||
$sRepair = "RENAME TABLE `{$sDBPrefix}priv_internalUser` TO `{$sDBPrefix}priv_internaluser_other`, `{$sDBPrefix}priv_internaluser_other` TO `{$sDBPrefix}priv_internaluser`";
|
||||
CMDBSource::Query($sRepair);
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Info("Renaming '{$sDBPrefix}priv_internalUser' failed (already done in a previous upgrade?)");
|
||||
}
|
||||
|
||||
// let's remove the records in priv_change which have no counterpart in priv_changeop
|
||||
SetupLog::Info("Cleanup of '{$sDBPrefix}priv_change' to remove orphan records");
|
||||
CMDBSource::SelectDB($sDBName);
|
||||
try {
|
||||
$sTotalCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_change`";
|
||||
$iTotalCount = (int)CMDBSource::QueryToScalar($sTotalCount);
|
||||
SetupLog::Info("There is a total of $iTotalCount records in {$sDBPrefix}priv_change.");
|
||||
|
||||
$sOrphanCount = "SELECT COUNT(c.id) FROM `{$sDBPrefix}priv_change` AS c left join `{$sDBPrefix}priv_changeop` AS o ON c.id = o.changeid WHERE o.id IS NULL";
|
||||
$iOrphanCount = (int)CMDBSource::QueryToScalar($sOrphanCount);
|
||||
SetupLog::Info("There are $iOrphanCount useless records in {$sDBPrefix}priv_change (".sprintf('%.2f', ((100.0 * $iOrphanCount) / $iTotalCount))."%)");
|
||||
if ($iOrphanCount > 0) {
|
||||
//N°3793
|
||||
if ($iOrphanCount > 100000) {
|
||||
SetupLog::Info("There are too much useless records ($iOrphanCount) in {$sDBPrefix}priv_change. Cleanup cannot be done during setup.");
|
||||
} else {
|
||||
SetupLog::Info("Removing the orphan records...");
|
||||
$sCleanup = "DELETE FROM `{$sDBPrefix}priv_change` USING `{$sDBPrefix}priv_change` LEFT JOIN `{$sDBPrefix}priv_changeop` ON `{$sDBPrefix}priv_change`.id = `{$sDBPrefix}priv_changeop`.changeid WHERE `{$sDBPrefix}priv_changeop`.id IS NULL;";
|
||||
CMDBSource::Query($sCleanup);
|
||||
SetupLog::Info("Cleanup completed successfully.");
|
||||
}
|
||||
} else {
|
||||
SetupLog::Info("Ok, nothing to cleanup.");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Info("Cleanup of orphan records in `{$sDBPrefix}priv_change` failed: ".$e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Module specific actions (migrate the data)
|
||||
$aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT.$sModulesDir);
|
||||
$oProductionEnv->CallInstallerHandlers($aAvailableModules, 'BeforeDatabaseCreation', $aSelectedModules);
|
||||
|
||||
if (!$oProductionEnv->CreateDatabaseStructure(MetaModel::GetConfig(), $sMode)) {
|
||||
throw new Exception("Failed to create/upgrade the database structure for environment '$sTargetEnvironment'");
|
||||
}
|
||||
|
||||
// Set a DBProperty with a unique ID to identify this instance of iTop
|
||||
$sUUID = DBProperty::GetProperty('database_uuid', '');
|
||||
if ($sUUID === '') {
|
||||
$sUUID = utils::CreateUUID('database');
|
||||
DBProperty::SetProperty('database_uuid', $sUUID, 'Installation/upgrade of '.ITOP_APPLICATION, 'Unique ID of this '.ITOP_APPLICATION.' Database');
|
||||
}
|
||||
|
||||
// priv_change now has an 'origin' field to distinguish between the various input sources
|
||||
// Let's initialize the field with 'interactive' for all records were it's null
|
||||
// Then check if some records should hold a different value, based on a pattern matching in the userinfo field
|
||||
CMDBSource::SelectDB($sDBName);
|
||||
try {
|
||||
$sCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_change` WHERE `origin` IS NULL";
|
||||
$iCount = (int)CMDBSource::QueryToScalar($sCount);
|
||||
if ($iCount > 0) {
|
||||
SetupLog::Info("Initializing '{$sDBPrefix}priv_change.origin' ($iCount records to update)");
|
||||
|
||||
// By default all uninitialized values are considered as 'interactive'
|
||||
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'interactive' WHERE `origin` IS NULL";
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
// CSV Import was identified by the comment at the end
|
||||
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'csv-import.php' WHERE `userinfo` LIKE '%Web Service (CSV)'";
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
// CSV Import was identified by the comment at the end
|
||||
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'csv-interactive' WHERE `userinfo` LIKE '%(CSV)' AND origin = 'interactive'";
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
// Syncho data sources were identified by the comment at the end
|
||||
// Unfortunately the comment is localized, so we have to search for all possible patterns
|
||||
$sCurrentLanguage = Dict::GetUserLanguage();
|
||||
$aSuffixes = [];
|
||||
foreach (array_keys(Dict::GetLanguages()) as $sLangCode) {
|
||||
Dict::SetUserLanguage($sLangCode);
|
||||
$sSuffix = CMDBSource::Quote('%'.Dict::S('Core:SyncDataExchangeComment'));
|
||||
$aSuffixes[$sSuffix] = true;
|
||||
}
|
||||
Dict::SetUserLanguage($sCurrentLanguage);
|
||||
$sCondition = "`userinfo` LIKE ".implode(" OR `userinfo` LIKE ", array_keys($aSuffixes));
|
||||
|
||||
$sInit = "UPDATE `{$sDBPrefix}priv_change` SET `origin` = 'synchro-data-source' WHERE ($sCondition)";
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
SetupLog::Info("Initialization of '{$sDBPrefix}priv_change.origin' completed.");
|
||||
} else {
|
||||
SetupLog::Info("'{$sDBPrefix}priv_change.origin' already initialized, nothing to do.");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error("Initializing '{$sDBPrefix}priv_change.origin' failed: ".$e->getMessage());
|
||||
}
|
||||
|
||||
// priv_async_task now has a 'status' field to distinguish between the various statuses rather than just relying on the date columns
|
||||
// Let's initialize the field with 'planned' or 'error' for all records were it's null
|
||||
CMDBSource::SelectDB($sDBName);
|
||||
try {
|
||||
$sCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_async_task` WHERE `status` IS NULL";
|
||||
$iCount = (int)CMDBSource::QueryToScalar($sCount);
|
||||
if ($iCount > 0) {
|
||||
SetupLog::Info("Initializing '{$sDBPrefix}priv_async_task.status' ($iCount records to update)");
|
||||
|
||||
$sInit = "UPDATE `{$sDBPrefix}priv_async_task` SET `status` = 'planned' WHERE (`status` IS NULL) AND (`started` IS NULL)";
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
$sInit = "UPDATE `{$sDBPrefix}priv_async_task` SET `status` = 'error' WHERE (`status` IS NULL) AND (`started` IS NOT NULL)";
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
SetupLog::Info("Initialization of '{$sDBPrefix}priv_async_task.status' completed.");
|
||||
} else {
|
||||
SetupLog::Info("'{$sDBPrefix}priv_async_task.status' already initialized, nothing to do.");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error("Initializing '{$sDBPrefix}priv_async_task.status' failed: ".$e->getMessage());
|
||||
}
|
||||
|
||||
SetupLog::Info("Database Schema Successfully Updated for environment '$sTargetEnvironment'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sDBPrefix
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
protected static function MoveColumns($sDBPrefix)
|
||||
{
|
||||
// In 2.6.0 the 'fields' attribute has been moved from Query to QueryOQL for dependencies reasons
|
||||
ModuleInstallerAPI::MoveColumnInDB($sDBPrefix.'priv_query', 'fields', $sDBPrefix.'priv_query_oql', 'fields');
|
||||
}
|
||||
|
||||
protected function AfterDBCreate(
|
||||
$sAdminUser,
|
||||
$sAdminPwd,
|
||||
$sAdminLanguage,
|
||||
$aSelectedModules
|
||||
) {
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
$sTargetEnvironment = $this->GetTargetEnv();
|
||||
$sModulesDir = $this->GetTargetDir();
|
||||
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
*/
|
||||
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
|
||||
SetupLog::Info('After Database Creation');
|
||||
|
||||
$sMode = $aParamValues['mode'];
|
||||
$oConfig = new Config();
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
|
||||
|
||||
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
|
||||
$oProductionEnv->InitDataModel($oConfig, true); // load data model and connect to the database
|
||||
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
|
||||
self::$bMetaModelStarted = true; // No need to reload the final MetaModel in case the installer runs synchronously
|
||||
|
||||
// Perform here additional DB setup... profiles, etc...
|
||||
//
|
||||
$aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT.$sModulesDir);
|
||||
$oProductionEnv->CallInstallerHandlers($aAvailableModules, 'AfterDatabaseCreation', $aSelectedModules);
|
||||
|
||||
$oProductionEnv->UpdatePredefinedObjects();
|
||||
|
||||
if ($sMode == 'install') {
|
||||
if (!self::CreateAdminAccount(MetaModel::GetConfig(), $sAdminUser, $sAdminPwd, $sAdminLanguage)) {
|
||||
throw(new Exception("Failed to create the administrator account '$sAdminUser'"));
|
||||
} else {
|
||||
SetupLog::Info("Administrator account '$sAdminUser' created.");
|
||||
}
|
||||
}
|
||||
|
||||
// Perform final setup tasks here
|
||||
//
|
||||
$oProductionEnv->CallInstallerHandlers($aAvailableModules, 'AfterDatabaseSetup', $aSelectedModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create and administrator account for iTop
|
||||
* @return boolean true on success, false otherwise
|
||||
*/
|
||||
protected static function CreateAdminAccount(Config $oConfig, $sAdminUser, $sAdminPwd, $sLanguage)
|
||||
{
|
||||
SetupLog::Info('CreateAdminAccount');
|
||||
|
||||
if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function DoLoadFiles(
|
||||
$aSelectedModules,
|
||||
$bSampleData = false
|
||||
) {
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
$sTargetEnvironment = $this->GetTargetEnv();
|
||||
$sModulesDir = $this->GetTargetDir();
|
||||
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
*/
|
||||
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
|
||||
|
||||
$oConfig = new Config();
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
|
||||
|
||||
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
|
||||
|
||||
//Load the MetaModel if needed (asynchronous mode)
|
||||
if (!self::$bMetaModelStarted) {
|
||||
$oProductionEnv->InitDataModel($oConfig, false); // load data model and connect to the database
|
||||
|
||||
self::$bMetaModelStarted = true; // No need to reload the final MetaModel in case the installer runs synchronously
|
||||
}
|
||||
|
||||
$aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, APPROOT.$sModulesDir);
|
||||
$oProductionEnv->LoadData($aAvailableModules, $bSampleData, $aSelectedModules);
|
||||
|
||||
// Perform after dbload setup tasks here
|
||||
//
|
||||
$oProductionEnv->CallInstallerHandlers($aAvailableModules, 'AfterDataLoad', $aSelectedModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sPreviousConfigFile
|
||||
* @param string $sDataModelVersion
|
||||
* @param array $aSelectedModuleCodes
|
||||
* @param array $aSelectedExtensionCodes
|
||||
* @param string|null $sInstallComment
|
||||
*
|
||||
* @param null $sInstallComment
|
||||
*
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function DoCreateConfig(
|
||||
$sPreviousConfigFile,
|
||||
$sDataModelVersion,
|
||||
$aSelectedModuleCodes,
|
||||
$aSelectedExtensionCodes,
|
||||
$sInstallComment = null
|
||||
) {
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
$sTargetEnvironment = $this->GetTargetEnv();
|
||||
$sModulesDir = $this->GetTargetDir();
|
||||
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
*/
|
||||
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
|
||||
|
||||
$aParamValues['selected_modules'] = implode(',', $aSelectedModuleCodes);
|
||||
$sMode = $aParamValues['mode'];
|
||||
|
||||
if ($sMode == 'upgrade') {
|
||||
try {
|
||||
$oOldConfig = new Config($sPreviousConfigFile);
|
||||
$oConfig = clone($oOldConfig);
|
||||
} catch (Exception $e) {
|
||||
// In case the previous configuration is corrupted... start with a blank new one
|
||||
$oConfig = new Config();
|
||||
}
|
||||
} else {
|
||||
$oConfig = new Config();
|
||||
// To preserve backward compatibility while upgrading to 2.0.3 (when tracking_level_linked_set_default has been introduced)
|
||||
// the default value on upgrade differs from the default value at first install
|
||||
$oConfig->Set('tracking_level_linked_set_default', LINKSET_TRACKING_NONE, 'first_install');
|
||||
}
|
||||
|
||||
$oConfig->Set('access_mode', ACCESS_FULL);
|
||||
// Final config update: add the modules
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
|
||||
|
||||
// Record which modules are installed...
|
||||
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
|
||||
$oProductionEnv->InitDataModel($oConfig, true); // load data model and connect to the database
|
||||
|
||||
if (!$oProductionEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModuleCodes, $aSelectedExtensionCodes, $sInstallComment)) {
|
||||
throw new Exception("Failed to record the installation information");
|
||||
}
|
||||
|
||||
// Make sure the root configuration directory exists
|
||||
if (!file_exists(APPCONF)) {
|
||||
mkdir(APPCONF);
|
||||
chmod(APPCONF, 0770); // RWX for owner and group, nothing for others
|
||||
SetupLog::Info("Created configuration directory: ".APPCONF);
|
||||
}
|
||||
|
||||
// Write the final configuration file
|
||||
$sConfigFile = APPCONF.(($sTargetEnvironment == '') ? 'production' : $sTargetEnvironment).'/'.ITOP_CONFIG_FILE;
|
||||
$sConfigDir = dirname($sConfigFile);
|
||||
@mkdir($sConfigDir);
|
||||
@chmod($sConfigDir, 0770); // RWX for owner and group, nothing for others
|
||||
|
||||
$oConfig->WriteToFile($sConfigFile);
|
||||
|
||||
// try to make the final config file read-only
|
||||
@chmod($sConfigFile, 0440); // Read-only for owner and group, nothing for others
|
||||
|
||||
// Ready to go !!
|
||||
require_once(APPROOT.'core/dict.class.inc.php');
|
||||
MetaModel::ResetAllCaches();
|
||||
}
|
||||
}
|
||||
232
setup/sequencers/DataAuditSequencer.php
Normal file
232
setup/sequencers/DataAuditSequencer.php
Normal file
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
require_once(APPROOT.'setup/parameters.class.inc.php');
|
||||
require_once(APPROOT.'setup/xmldataloader.class.inc.php');
|
||||
require_once APPROOT.'setup/feature_removal/SetupAudit.php';
|
||||
|
||||
require_once(APPROOT.'setup/sequencers/StepSequencer.php');
|
||||
require_once(APPROOT.'setup/sequencers/ApplicationInstallSequencer.php');
|
||||
|
||||
use Combodo\iTop\Setup\FeatureRemoval\SetupAudit;
|
||||
|
||||
class DataAuditSequencer extends ApplicationInstallSequencer
|
||||
{
|
||||
public const DATA_AUDIT_FAILED = 100;
|
||||
|
||||
protected function GetTempEnv()
|
||||
{
|
||||
$sTargetEnv = $this->GetTargetEnv();
|
||||
return 'dry-'.$sTargetEnv;
|
||||
}
|
||||
|
||||
protected function GetTargetDir()
|
||||
{
|
||||
$sTargetEnv = $this->GetTempEnv();
|
||||
return 'env-'.$sTargetEnv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the next step of the installation and reports about the progress
|
||||
* and the next step to perform
|
||||
*
|
||||
* @param string $sStep The identifier of the step to execute
|
||||
* @param string|null $sInstallComment
|
||||
*
|
||||
* @return array (status => , message => , percentage-completed => , next-step => , next-step-label => )
|
||||
*/
|
||||
public function ExecuteStep($sStep = '', $sInstallComment = null)
|
||||
{
|
||||
try {
|
||||
$fStart = microtime(true);
|
||||
SetupLog::Info("##### STEP {$sStep} start");
|
||||
$this->EnterReadOnlyMode();
|
||||
switch ($sStep) {
|
||||
case '':
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'percentage-completed' => 20,
|
||||
'next-step' => 'compile',
|
||||
'next-step-label' => 'Compiling the data model',
|
||||
];
|
||||
|
||||
// Log the parameters...
|
||||
$oDoc = new DOMDocument('1.0', 'UTF-8');
|
||||
$oDoc->preserveWhiteSpace = false;
|
||||
$oDoc->formatOutput = true;
|
||||
$this->oParams->ToXML($oDoc, null, 'installation');
|
||||
$sXML = $oDoc->saveXML();
|
||||
$sSafeXml = preg_replace("|<pwd>([^<]*)</pwd>|", "<pwd>**removed**</pwd>", $sXML);
|
||||
SetupLog::Info("======= Data Audit starts =======\nParameters:\n$sSafeXml\n");
|
||||
|
||||
// Save the response file as a stand-alone file as well
|
||||
$sFileName = 'data-audit-'.date('Y-m-d');
|
||||
$index = 0;
|
||||
while (file_exists(APPROOT.'log/'.$sFileName.'.xml')) {
|
||||
$index++;
|
||||
$sFileName = 'data-audit-'.date('Y-m-d').'-'.$index;
|
||||
}
|
||||
file_put_contents(APPROOT.'log/'.$sFileName.'.xml', $sSafeXml);
|
||||
|
||||
break;
|
||||
|
||||
case 'compile':
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules');
|
||||
$sSourceDir = $this->oParams->Get('source_dir', 'datamodels/latest');
|
||||
$sExtensionDir = $this->oParams->Get('extensions_dir', 'extensions');
|
||||
$aRemovedExtensionCodes = $this->oParams->Get('removed_extensions', []);
|
||||
|
||||
$this->DoCompile(
|
||||
$aRemovedExtensionCodes,
|
||||
$aSelectedModules,
|
||||
$sSourceDir,
|
||||
$sExtensionDir,
|
||||
false
|
||||
);
|
||||
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'write-config',
|
||||
'next-step-label' => 'Writing audit config',
|
||||
'percentage-completed' => 40,
|
||||
];
|
||||
break;
|
||||
case 'write-config':
|
||||
$this->DoWriteConfig();
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'setup-audit',
|
||||
'next-step-label' => 'Checking data consistency with the new data model',
|
||||
'percentage-completed' => 60,
|
||||
];
|
||||
break;
|
||||
case 'setup-audit':
|
||||
$this->DoSetupAudit();
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'cleanup',
|
||||
'next-step-label' => 'Temporary folders cleanup',
|
||||
'percentage-completed' => 80,
|
||||
];
|
||||
break;
|
||||
case 'cleanup' :
|
||||
$this->DoCleanup();
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Completed',
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
break;
|
||||
default:
|
||||
$aResult = [
|
||||
'status' => self::ERROR,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => "Unknown setup step '$sStep'.",
|
||||
'percentage-completed' => 100,
|
||||
];
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$aResult = [
|
||||
'status' => self::ERROR,
|
||||
'message' => $e->getMessage(),
|
||||
'next-step' => '',
|
||||
'next-step-label' => '',
|
||||
'percentage-completed' => 100,
|
||||
'error_code' => $e->getCode(),
|
||||
];
|
||||
|
||||
SetupLog::Error('An exception occurred: '.$e->getMessage().' at line '.$e->getLine().' in file '.$e->getFile());
|
||||
$idx = 0;
|
||||
// Log the call stack, but not the parameters since they may contain passwords or other sensitive data
|
||||
SetupLog::Ok("Call stack:");
|
||||
foreach ($e->getTrace() as $aTrace) {
|
||||
$sLine = empty($aTrace['line']) ? "" : $aTrace['line'];
|
||||
$sFile = empty($aTrace['file']) ? "" : $aTrace['file'];
|
||||
$sClass = empty($aTrace['class']) ? "" : $aTrace['class'];
|
||||
$sType = empty($aTrace['type']) ? "" : $aTrace['type'];
|
||||
$sFunction = empty($aTrace['function']) ? "" : $aTrace['function'];
|
||||
$sVerb = empty($sClass) ? $sFunction : "$sClass{$sType}$sFunction";
|
||||
SetupLog::Ok("#$idx $sFile($sLine): $sVerb(...)");
|
||||
$idx++;
|
||||
}
|
||||
$this->ExitReadOnlyMode();
|
||||
} finally {
|
||||
$fDuration = round(microtime(true) - $fStart, 2);
|
||||
SetupLog::Info("##### STEP {$sStep} duration: {$fDuration}s");
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
protected function DoWriteConfig()
|
||||
{
|
||||
$sConfigFilePath = utils::GetConfigFilePath($this->GetTargetEnv());
|
||||
if (is_file($sConfigFilePath)) {
|
||||
$oConfig = new Config($sConfigFilePath);
|
||||
|
||||
$sTempConfigFileName = utils::GetConfigFilePath($this->GetTempEnv());
|
||||
$sConfigDir = dirname($sTempConfigFileName);
|
||||
@mkdir($sConfigDir);
|
||||
@chmod($sConfigDir, 0770); // RWX for owner and group, nothing for others
|
||||
|
||||
return $oConfig->WriteToFile($sTempConfigFileName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function DoSetupAudit()
|
||||
{
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
*/
|
||||
$oContextTag = new ContextTag(ContextTag::TAG_SETUP);
|
||||
|
||||
$sTargetEnvironment = $this->GetTempEnv();
|
||||
$sPreviousEnvironment = $this->GetTargetEnv();
|
||||
|
||||
$oSetupAudit = new SetupAudit($sPreviousEnvironment, $sTargetEnvironment);
|
||||
|
||||
//Make sure the MetaModel is started before analysing for issues
|
||||
$sConfFile = utils::GetConfigFilePath($sPreviousEnvironment);
|
||||
MetaModel::Startup($sConfFile, false /* $bModelOnly */, false /* $bAllowCache */, false /* $bTraceSourceFiles */, $sPreviousEnvironment);
|
||||
$oSetupAudit->GetIssues(true);
|
||||
$iCount = $oSetupAudit->GetDataToCleanupCount();
|
||||
|
||||
if ($iCount > 0) {
|
||||
throw new Exception("$iCount elements require data adjustments or cleanup in the backoffice prior to upgrading iTop", static::DATA_AUDIT_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
protected function DoCleanup()
|
||||
{
|
||||
$sDestination = APPROOT.$this->GetTargetDir();
|
||||
SetupUtils::tidydir($sDestination);
|
||||
SetupUtils::rmdir_safe($sDestination);
|
||||
}
|
||||
}
|
||||
94
setup/sequencers/StepSequencer.php
Normal file
94
setup/sequencers/StepSequencer.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
abstract class StepSequencer
|
||||
{
|
||||
public const OK = 1;
|
||||
public const ERROR = 2;
|
||||
public const WARNING = 3;
|
||||
public const INFO = 4;
|
||||
|
||||
/**
|
||||
* Runs all the installation steps in one go and directly outputs
|
||||
* some information about the progress and the success of the various
|
||||
* sequential steps.
|
||||
*
|
||||
* @param bool $bVerbose
|
||||
* @param string|null $sMessage
|
||||
* @param string|null $sComment
|
||||
*
|
||||
* @return boolean True if the installation was successful, false otherwise
|
||||
*/
|
||||
public function ExecuteAllSteps($bVerbose = true, &$sMessage = null, $sComment = null)
|
||||
{
|
||||
$sStep = '';
|
||||
$sStepLabel = '';
|
||||
$iOverallStatus = self::OK;
|
||||
do {
|
||||
if ($bVerbose) {
|
||||
if ($sStep != '') {
|
||||
echo "$sStepLabel\n";
|
||||
echo "Executing '$sStep'\n";
|
||||
} else {
|
||||
echo "Starting...\n";
|
||||
}
|
||||
}
|
||||
$aRes = $this->ExecuteStep($sStep, $sComment);
|
||||
$sStep = $aRes['next-step'];
|
||||
$sStepLabel = $aRes['next-step-label'];
|
||||
$sMessage = $aRes['message'];
|
||||
if ($bVerbose) {
|
||||
switch ($aRes['status']) {
|
||||
case self::OK:
|
||||
echo "Ok. ".$aRes['percentage-completed']." % done.\n";
|
||||
break;
|
||||
|
||||
case self::ERROR:
|
||||
$iOverallStatus = self::ERROR;
|
||||
echo "Error: ".$aRes['message']."\n";
|
||||
break;
|
||||
|
||||
case self::WARNING:
|
||||
$iOverallStatus = self::WARNING;
|
||||
echo "Warning: ".$aRes['message']."\n";
|
||||
echo $aRes['percentage-completed']." % done.\n";
|
||||
break;
|
||||
|
||||
case self::INFO:
|
||||
echo "Info: ".$aRes['message']."\n";
|
||||
echo $aRes['percentage-completed']." % done.\n";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch ($aRes['status']) {
|
||||
case self::ERROR:
|
||||
$iOverallStatus = self::ERROR;
|
||||
break;
|
||||
case self::WARNING:
|
||||
$iOverallStatus = self::WARNING;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (($aRes['status'] != self::ERROR) && ($aRes['next-step'] != ''));
|
||||
|
||||
return ($iOverallStatus == self::OK);
|
||||
}
|
||||
|
||||
abstract public function ExecuteStep($sStep = '', $sComment = null);
|
||||
}
|
||||
@@ -25,21 +25,17 @@ function WizardAsyncAction(sActionCode, oParams, OnErrorFunction)
|
||||
|
||||
function WizardUpdateButtons()
|
||||
{
|
||||
if (CanMoveForward())
|
||||
{
|
||||
if (CanMoveForward()) {
|
||||
$("#btn_next").prop('disabled', false);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
$("#btn_next").prop('disabled', true);
|
||||
}
|
||||
|
||||
if (CanMoveBackward())
|
||||
{
|
||||
if (CanMoveBackward()) {
|
||||
$("#btn_back").prop('disabled', false);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
$("#btn_back").prop('disabled', true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,32 +254,23 @@ class SetupUtils
|
||||
|
||||
if (!utils::IsModeCLI()) {
|
||||
$sUploadTmpDir = self::GetUploadTmpDir();
|
||||
if (empty($sUploadTmpDir)) {
|
||||
$sUploadTmpDir = '/tmp';
|
||||
$aResult[] = new CheckResult(
|
||||
CheckResult::WARNING,
|
||||
"Temporary directory for files upload is not defined (upload_tmp_dir), assuming that $sUploadTmpDir is used."
|
||||
);
|
||||
}
|
||||
// check that the upload directory is indeed writable from PHP
|
||||
if (!empty($sUploadTmpDir)) {
|
||||
if (!file_exists($sUploadTmpDir)) {
|
||||
if (!file_exists($sUploadTmpDir)) {
|
||||
$aResult[] = new CheckResult(
|
||||
CheckResult::ERROR,
|
||||
"Temporary directory for files upload ($sUploadTmpDir) does not exist or cannot be read by PHP."
|
||||
);
|
||||
} else {
|
||||
if (!is_writable($sUploadTmpDir)) {
|
||||
$aResult[] = new CheckResult(
|
||||
CheckResult::ERROR,
|
||||
"Temporary directory for files upload ($sUploadTmpDir) does not exist or cannot be read by PHP."
|
||||
"Temporary directory for files upload ($sUploadTmpDir) is not writable."
|
||||
);
|
||||
} else {
|
||||
if (!is_writable($sUploadTmpDir)) {
|
||||
$aResult[] = new CheckResult(
|
||||
CheckResult::ERROR,
|
||||
"Temporary directory for files upload ($sUploadTmpDir) is not writable."
|
||||
);
|
||||
} else {
|
||||
$aResult[] = new CheckResult(
|
||||
CheckResult::TRACE,
|
||||
"Info - Temporary directory for files upload ($sUploadTmpDir) is writable."
|
||||
);
|
||||
}
|
||||
$aResult[] = new CheckResult(
|
||||
CheckResult::TRACE,
|
||||
"Info - Temporary directory for files upload ($sUploadTmpDir) is writable."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -518,7 +509,7 @@ class SetupUtils
|
||||
}
|
||||
require_once(APPROOT.'setup/modulediscovery.class.inc.php');
|
||||
try {
|
||||
ModuleDiscovery::GetAvailableModules($aDirsToScan, true, $aSelectedModules);
|
||||
ModuleDiscovery::GetModulesOrderedByDependencies($aDirsToScan, true, $aSelectedModules);
|
||||
} catch (Exception $e) {
|
||||
$aResult[] = new CheckResult(CheckResult::ERROR, $e->getMessage());
|
||||
}
|
||||
@@ -599,7 +590,7 @@ class SetupUtils
|
||||
// create and test destination location
|
||||
//
|
||||
$sDestDir = dirname($sDBBackupPath);
|
||||
setuputils::builddir($sDestDir);
|
||||
SetupUtils::builddir($sDestDir);
|
||||
if (!is_dir($sDestDir)) {
|
||||
$aResult[] = new CheckResult(CheckResult::ERROR, "$sDestDir does not exist and could not be created.");
|
||||
}
|
||||
@@ -1555,7 +1546,7 @@ JS
|
||||
return $sHtml;
|
||||
}
|
||||
|
||||
public static function GetConfig($oWizard)
|
||||
public static function GetConfig(WizardController $oWizard)
|
||||
{
|
||||
$oConfig = new Config();
|
||||
$sSourceDir = $oWizard->GetParameter('source_dir', '');
|
||||
@@ -1570,7 +1561,7 @@ JS
|
||||
|
||||
$aParamValues = $oWizard->GetParamForConfigArray();
|
||||
$aParamValues['source_dir'] = $sRelativeSourceDir;
|
||||
$oConfig->UpdateFromParams($aParamValues, null);
|
||||
$oConfig->UpdateFromParams($aParamValues);
|
||||
|
||||
return $oConfig;
|
||||
}
|
||||
@@ -1602,6 +1593,10 @@ JS
|
||||
$aDirsToScan[] = $sExtraDir;
|
||||
}
|
||||
$oProductionEnv = new RunTimeEnvironment();
|
||||
$aRemovedExtensionCodes = json_decode($oWizard->GetParameter('removed_extensions'), true) ?? [];
|
||||
$oExtensionsMap = new iTopExtensionsMap('production', $aDirsToScan);
|
||||
$oExtensionsMap->DeclareExtensionAsRemoved($aRemovedExtensionCodes);
|
||||
|
||||
$aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, $aDirsToScan, $bAbortOnMissingDependency, $aModulesToLoad);
|
||||
|
||||
foreach ($aAvailableModules as $key => $aModule) {
|
||||
@@ -1627,7 +1622,7 @@ JS
|
||||
|
||||
$aParamValues = $oWizard->GetParamForConfigArray();
|
||||
$aParamValues['source_dir'] = '';
|
||||
$oConfig->UpdateFromParams($aParamValues, null);
|
||||
$oConfig->UpdateFromParams($aParamValues);
|
||||
|
||||
$oProductionEnv = new RunTimeEnvironment();
|
||||
return $oProductionEnv->GetApplicationVersion($oConfig);
|
||||
|
||||
@@ -6,7 +6,6 @@ use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReaderException;
|
||||
require_once(APPROOT.'/application/utils.inc.php');
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
require_once(APPROOT.'/setup/wizardcontroller.class.inc.php');
|
||||
require_once(APPROOT.'/setup/wizardsteps.class.inc.php');
|
||||
|
||||
class InstallationFileService
|
||||
{
|
||||
@@ -71,12 +70,12 @@ class InstallationFileService
|
||||
return $this->aAfterComputationSelectedExtensions;
|
||||
}
|
||||
|
||||
public function SetItopExtensionsMap(ItopExtensionsMap $oItopExtensionsMap): void
|
||||
public function SetItopExtensionsMap(iTopExtensionsMap $oItopExtensionsMap): void
|
||||
{
|
||||
$this->oItopExtensionsMap = $oItopExtensionsMap;
|
||||
}
|
||||
|
||||
public function GetItopExtensionsMap(): ItopExtensionsMap
|
||||
public function GetItopExtensionsMap(): iTopExtensionsMap
|
||||
{
|
||||
if (is_null($this->oItopExtensionsMap)) {
|
||||
$this->oItopExtensionsMap = new iTopExtensionsMap($this->sTargetEnvironment);
|
||||
@@ -259,7 +258,7 @@ class InstallationFileService
|
||||
{
|
||||
$sProductionModuleDir = APPROOT.'data/'.$this->sTargetEnvironment.'-modules/';
|
||||
|
||||
$aAvailableModules = $this->GetProductionEnv()->AnalyzeInstallation(MetaModel::GetConfig(), $this->GetExtraDirs(), false, null);
|
||||
$aAvailableModules = $this->GetProductionEnv()->AnalyzeInstallation(MetaModel::GetConfig(), $this->GetExtraDirs());
|
||||
|
||||
$this->aAutoSelectModules = [];
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule) {
|
||||
|
||||
@@ -272,7 +272,7 @@ $bFoundIssues = false;
|
||||
$bInstall = utils::ReadParam('install', true, true /* CLI allowed */);
|
||||
if ($bInstall) {
|
||||
echo "Starting the unattended installation...\n";
|
||||
$oWizard = new ApplicationInstaller($oParams);
|
||||
$oWizard = new ApplicationInstallSequencer($oParams);
|
||||
$bRes = $oWizard->ExecuteAllSteps();
|
||||
if (!$bRes) {
|
||||
echo "\nencountered installation issues!";
|
||||
|
||||
@@ -32,7 +32,6 @@ require_once(APPROOT.'/application/utils.inc.php');
|
||||
require_once(APPROOT.'/core/config.class.inc.php');
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
require_once(APPROOT.'/setup/wizardcontroller.class.inc.php');
|
||||
require_once(APPROOT.'/setup/wizardsteps.class.inc.php');
|
||||
|
||||
Session::Start();
|
||||
clearstatcache(); // Make sure we know what we are doing !
|
||||
|
||||
@@ -16,9 +16,32 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
require_once(APPROOT.'setup/setuputils.class.inc.php');
|
||||
require_once(APPROOT.'setup/parameters.class.inc.php');
|
||||
require_once(APPROOT.'setup/applicationinstaller.class.inc.php');
|
||||
require_once(APPROOT.'core/mutex.class.inc.php');
|
||||
require_once(APPROOT.'setup/extensionsmap.class.inc.php');
|
||||
|
||||
require_once(APPROOT.'setup/wizardsteps/WizardStep.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/AbstractWizStepInstall.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepWelcome.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepInstallOrUpgrade.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepDetectedInfo.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepLicense.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepLicense2.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/AbstractWizStepMiscParams.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepAdminAccount.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepInstall.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepDataAudit.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepDBParams.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepDone.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepInstallMiscParams.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepModulesChoice.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepSummary.php');
|
||||
require_once(APPROOT.'setup/wizardsteps/WizStepUpgradeMiscParams.php');
|
||||
|
||||
/**
|
||||
* Engine for displaying the various pages of a "wizard"
|
||||
* Each "step" of the wizard must be implemented as
|
||||
@@ -54,7 +77,7 @@ class WizardController
|
||||
|
||||
/**
|
||||
* Pushes information about the current step onto the stack
|
||||
* @param hash $aStepInfo Array('class' => , 'state' => )
|
||||
* @param array $aStepInfo Array('class' => , 'state' => )
|
||||
*/
|
||||
protected function PushStep($aStepInfo)
|
||||
{
|
||||
@@ -148,9 +171,11 @@ class WizardController
|
||||
/** @var \WizardStep $oStep */
|
||||
$oStep = new $sCurrentStepClass($this, $sCurrentState);
|
||||
if ($oStep->ValidateParams()) {
|
||||
$this->PushStep(['class' => $sCurrentStepClass, 'state' => $sCurrentState]);
|
||||
if ($oStep->CanComeBack()) {
|
||||
$this->PushStep(['class' => $sCurrentStepClass, 'state' => $sCurrentState]);
|
||||
}
|
||||
$aPossibleSteps = $oStep->GetPossibleSteps();
|
||||
$aNextStepInfo = $oStep->ProcessParams(true); // true => moving forward
|
||||
$aNextStepInfo = $oStep->UpdateWizardStateAndGetNextStep(true); // true => moving forward
|
||||
if (in_array($aNextStepInfo['class'], $aPossibleSteps)) {
|
||||
$oNextStep = new $aNextStepInfo['class']($this, $aNextStepInfo['state']);
|
||||
$this->DisplayStep($oNextStep);
|
||||
@@ -170,7 +195,7 @@ class WizardController
|
||||
$sCurrentStepClass = utils::ReadParam('_class', $this->sInitialStepClass);
|
||||
$sCurrentState = utils::ReadParam('_state', $this->sInitialState);
|
||||
$oStep = new $sCurrentStepClass($this, $sCurrentState);
|
||||
$aNextStepInfo = $oStep->ProcessParams(false); // false => Moving backwards
|
||||
$aNextStepInfo = $oStep->UpdateWizardStateAndGetNextStep(false); // false => Moving backwards
|
||||
|
||||
// Display the previous step
|
||||
$aCurrentStepInfo = $this->PopStep();
|
||||
@@ -360,325 +385,3 @@ on the page's parameters
|
||||
return $sOutput;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class to build "steps" for the wizard controller
|
||||
* If a step needs to maintain an internal "state" (for complex steps)
|
||||
* then it's up to the derived class to implement the behavior based on
|
||||
* the internal 'sCurrentState' variable.
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
abstract class WizardStep
|
||||
{
|
||||
/**
|
||||
* A reference to the WizardController
|
||||
* @var WizardController
|
||||
*/
|
||||
protected $oWizard;
|
||||
/**
|
||||
* Current 'state' of the wizard step. Simple 'steps' can ignore it
|
||||
* @var string
|
||||
*/
|
||||
protected $sCurrentState;
|
||||
|
||||
public function __construct(WizardController $oWizard, $sCurrentState)
|
||||
{
|
||||
$this->oWizard = $oWizard;
|
||||
$this->sCurrentState = $sCurrentState;
|
||||
}
|
||||
|
||||
public function GetState()
|
||||
{
|
||||
return $this->sCurrentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the wizard page for the current class/state
|
||||
* The page can contain any number of "<input/>" fields, but no "<form>...</form>" tag
|
||||
* The name of the input fields (and their id if one is supplied) MUST NOT start with "_"
|
||||
* (this is reserved for the wizard's own parameters)
|
||||
* @return void
|
||||
*/
|
||||
abstract public function Display(WebPage $oPage);
|
||||
/**
|
||||
* Displays the wizard page for the current class/state
|
||||
* return UIBlock
|
||||
* The name of the input fields (and their id if one is supplied) MUST NOT start with "_"
|
||||
* (this is reserved for the wizard's own parameters)
|
||||
* @return \Combodo\iTop\Application\UI\Base\UIBlock
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function DisplayBlock(WebPage $oPage)
|
||||
{
|
||||
return new Html($this->Display($oPage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the page's parameters and (if moving forward) returns the next step/state to be displayed
|
||||
* @param bool $bMoveForward True if the wizard is moving forward 'Next >>' button pressed, false otherwise
|
||||
* @return hash array('class' => $sNextClass, 'state' => $sNextState)
|
||||
*/
|
||||
abstract public function ProcessParams($bMoveForward = true);
|
||||
|
||||
/**
|
||||
* Returns the list of possible steps from this step forward
|
||||
* @return array Array of strings (step classes)
|
||||
*/
|
||||
abstract public function GetPossibleSteps();
|
||||
|
||||
/**
|
||||
* Returns title of the current step
|
||||
* @return string The title of the wizard page for the current step
|
||||
*/
|
||||
abstract public function GetTitle();
|
||||
|
||||
/**
|
||||
* Tells whether the parameters are Ok to move forward
|
||||
* @return boolean True to move forward, false to stey on the same step
|
||||
*/
|
||||
public function ValidateParams()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this step/state is the last one of the wizard (dead-end)
|
||||
* @return boolean True if the 'Next >>' button should be displayed
|
||||
*/
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return 'return true;';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label for the " Next >> " button
|
||||
* @return string The label for the button
|
||||
*/
|
||||
public function GetNextButtonLabel()
|
||||
{
|
||||
return 'Next';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this step/state allows to go back or not
|
||||
* @return boolean True if the '<< Back' button should be displayed
|
||||
*/
|
||||
public function CanMoveBackward()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Back" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveBackward()
|
||||
{
|
||||
return 'return true;';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this step of the wizard requires that the configuration file be writable
|
||||
* @return bool True if the wizard will possibly need to modify the configuration at some point
|
||||
*/
|
||||
public function RequiresWritableConfig()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload this function to implement asynchronous action(s) (AJAX)
|
||||
* @param string $sCode The code of the action (if several actions need to be distinguished)
|
||||
* @param hash $aParameters The action's parameters name => value
|
||||
*/
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Example of a simple Setup Wizard with some parameters to store
|
||||
* the installation mode (install | upgrade) and a simple asynchronous
|
||||
* (AJAX) action.
|
||||
*
|
||||
* The setup wizard is executed by the following code:
|
||||
*
|
||||
* $oWizard = new WizardController('Step1');
|
||||
* $oWizard->Run();
|
||||
*
|
||||
class Step1 extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Welcome';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array('Step2', 'Step2bis');
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
$sNextStep = '';
|
||||
$sInstallMode = utils::ReadParam('install_mode');
|
||||
if ($sInstallMode == 'install')
|
||||
{
|
||||
$this->oWizard->SetParameter('install_mode', 'install');
|
||||
$sNextStep = 'Step2';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->oWizard->SetParameter('install_mode', 'upgrade');
|
||||
$sNextStep = 'Step2bis';
|
||||
|
||||
}
|
||||
return array('class' => $sNextStep, 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 1!');
|
||||
$sInstallMode = $this->oWizard->GetParameter('install_mode', 'install');
|
||||
$sChecked = ($sInstallMode == 'install') ? ' checked ' : '';
|
||||
$oPage->p('<input type="radio" name="install_mode" value="install"'.$sChecked.'/> Install');
|
||||
$sChecked = ($sInstallMode == 'upgrade') ? ' checked ' : '';
|
||||
$oPage->p('<input type="radio" name="install_mode" value="upgrade"'.$sChecked.'/> Upgrade');
|
||||
}
|
||||
}
|
||||
|
||||
class Step2 extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Installation Parameters';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array('Step3');
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
return array('class' => 'Step3', 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 2! (Installation)');
|
||||
}
|
||||
}
|
||||
|
||||
class Step2bis extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Upgrade Parameters';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array('Step2ter');
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
$sUpgradeInfo = utils::ReadParam('upgrade_info');
|
||||
$this->oWizard->SetParameter('upgrade_info', $sUpgradeInfo);
|
||||
$sAdditionalUpgradeInfo = utils::ReadParam('additional_upgrade_info');
|
||||
$this->oWizard->SetParameter('additional_upgrade_info', $sAdditionalUpgradeInfo);
|
||||
return array('class' => 'Step2ter', 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 2bis! (Upgrade)');
|
||||
$sUpgradeInfo = $this->oWizard->GetParameter('upgrade_info', '');
|
||||
$oPage->p('Type your name here: <input type="text" id="upgrade_info" name="upgrade_info" value="'.$sUpgradeInfo.'" size="20"/><span id="v_upgrade_info"></span>');
|
||||
$sAdditionalUpgradeInfo = $this->oWizard->GetParameter('additional_upgrade_info', '');
|
||||
$oPage->p('The installer replies: <input type="text" name="additional_upgrade_info" value="'.$sAdditionalUpgradeInfo.'" size="20"/>');
|
||||
|
||||
$oPage->add_ready_script("$('#upgrade_info').change(function() {
|
||||
$('#v_upgrade_info').html('<img src=\"../images/indicator.gif\"/>');
|
||||
WizardAsyncAction('', { upgrade_info: $('#upgrade_info').val() }); });");
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
usleep(300000); // 300 ms
|
||||
$sName = $aParameters['upgrade_info'];
|
||||
$sReply = addslashes("Hello ".$sName);
|
||||
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#v_upgrade_info").html('');
|
||||
$("input[name=additional_upgrade_info]").val("$sReply");
|
||||
EOF
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Step2ter extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Additional Upgrade Info';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array('Step3');
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
return array('class' => 'Step3', 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 2ter! (Upgrade)');
|
||||
}
|
||||
}
|
||||
|
||||
class Step3 extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Installation Complete';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
return array('class' => '', 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is the FINAL Step');
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
End of the example */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
111
setup/wizardsteps/AbstractWizStepInstall.php
Normal file
111
setup/wizardsteps/AbstractWizStepInstall.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
abstract class AbstractWizStepInstall extends WizardStep
|
||||
{
|
||||
/**
|
||||
* Prepare the parameters to execute the installation asynchronously
|
||||
* @return array A big hash array that can be converted to XML or JSON with all the needed parameters
|
||||
*/
|
||||
protected function BuildConfig()
|
||||
{
|
||||
$sMode = $this->oWizard->GetParameter('install_mode', 'install');
|
||||
$aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
|
||||
$aSelectedExtensions = json_decode($this->oWizard->GetParameter('selected_extensions'), true);
|
||||
$sBackupDestination = '';
|
||||
$sPreviousConfigurationFile = '';
|
||||
$sDBName = $this->oWizard->GetParameter('db_name');
|
||||
if ($sMode == 'upgrade') {
|
||||
$sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', '');
|
||||
if (!empty($sPreviousVersionDir)) {
|
||||
$aPreviousInstance = SetupUtils::GetPreviousInstance($sPreviousVersionDir);
|
||||
if ($aPreviousInstance['found']) {
|
||||
$sPreviousConfigurationFile = $aPreviousInstance['configuration_file'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->oWizard->GetParameter('db_backup', false)) {
|
||||
$sBackupDestination = $this->oWizard->GetParameter('db_backup_path', '');
|
||||
}
|
||||
} else {
|
||||
|
||||
$sDBNewName = $this->oWizard->GetParameter('db_new_name', '');
|
||||
if ($sDBNewName != '') {
|
||||
$sDBName = $sDBNewName; // Database will be created
|
||||
}
|
||||
}
|
||||
|
||||
$sSourceDir = $this->oWizard->GetParameter('source_dir');
|
||||
$aCopies = [];
|
||||
if (($sMode == 'upgrade') && ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous')) {
|
||||
$sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir');
|
||||
$aCopies[] = ['source' => $sSourceDir, 'destination' => 'modules']; // Source is an absolute path, destination is relative to APPROOT
|
||||
$aCopies[] = ['source' => $sPreviousVersionDir.'/portal', 'destination' => 'portal']; // Source is an absolute path, destination is relative to APPROOT
|
||||
$sSourceDir = APPROOT.'modules';
|
||||
}
|
||||
|
||||
$aInstallParams = [
|
||||
'mode' => $sMode,
|
||||
'preinstall' => [
|
||||
'copies' => $aCopies,
|
||||
// 'backup' => see below
|
||||
],
|
||||
'source_dir' => str_replace(APPROOT, '', $sSourceDir),
|
||||
'datamodel_version' => $this->oWizard->GetParameter('datamodel_version'), //TODO: let the installer compute this automatically...
|
||||
'previous_configuration_file' => $sPreviousConfigurationFile,
|
||||
'extensions_dir' => 'extensions',
|
||||
'target_env' => 'production',
|
||||
'workspace_dir' => '',
|
||||
'database' => [
|
||||
'server' => $this->oWizard->GetParameter('db_server'),
|
||||
'user' => $this->oWizard->GetParameter('db_user'),
|
||||
'pwd' => $this->oWizard->GetParameter('db_pwd'),
|
||||
'name' => $sDBName,
|
||||
'db_tls_enabled' => $this->oWizard->GetParameter('db_tls_enabled'),
|
||||
'db_tls_ca' => $this->oWizard->GetParameter('db_tls_ca'),
|
||||
'prefix' => $this->oWizard->GetParameter('db_prefix'),
|
||||
],
|
||||
'url' => $this->oWizard->GetParameter('application_url'),
|
||||
'graphviz_path' => $this->oWizard->GetParameter('graphviz_path'),
|
||||
'admin_account' => [
|
||||
'user' => $this->oWizard->GetParameter('admin_user'),
|
||||
'pwd' => $this->oWizard->GetParameter('admin_pwd'),
|
||||
'language' => $this->oWizard->GetParameter('admin_language'),
|
||||
],
|
||||
'language' => $this->oWizard->GetParameter('default_language'),
|
||||
'selected_modules' => $aSelectedModules,
|
||||
'selected_extensions' => $aSelectedExtensions,
|
||||
'sample_data' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? true : false ,
|
||||
'old_addon' => $this->oWizard->GetParameter('old_addon', false), // whether or not to use the "old" userrights profile addon
|
||||
'options' => json_decode($this->oWizard->GetParameter('misc_options', '[]'), true),
|
||||
'mysql_bindir' => $this->oWizard->GetParameter('mysql_bindir'),
|
||||
];
|
||||
|
||||
if ($sBackupDestination != '') {
|
||||
$aInstallParams['preinstall']['backup'] = [
|
||||
'destination' => $sBackupDestination,
|
||||
'configuration_file' => $sPreviousConfigurationFile,
|
||||
];
|
||||
}
|
||||
|
||||
return $aInstallParams;
|
||||
}
|
||||
|
||||
}
|
||||
73
setup/wizardsteps/AbstractWizStepMiscParams.php
Normal file
73
setup/wizardsteps/AbstractWizStepMiscParams.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* @since 3.0.0 N°4092
|
||||
*/
|
||||
abstract class AbstractWizStepMiscParams extends WizardStep
|
||||
{
|
||||
/**
|
||||
* @since 3.0.0 N°4092
|
||||
*/
|
||||
final protected function AddUseSymlinksFlagOption(WebPage $oPage): void
|
||||
{
|
||||
if (MFCompiler::CanUseSymbolicLinksFlagBeUsed()) {
|
||||
$sChecked = (MFCompiler::IsUseSymbolicLinksFlagPresent()) ? ' checked' : '';
|
||||
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Dev parameters</legend>');
|
||||
$oPage->p('<input id="use-symbolic-links" type="checkbox"'.$sChecked.'><label for="use-symbolic-links"> Create symbolic links instead of creating a copy in env-production (useful for debugging extensions)');
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add_ready_script(
|
||||
<<<'JS'
|
||||
$("#use-symbolic-links").on("click", function() {
|
||||
var $this = $(this),
|
||||
bUseSymbolicLinks = $this.prop("checked");
|
||||
var sAuthent = $('#authent_token').val();
|
||||
var oAjaxParams = { operation: 'toggle_use_symbolic_links', bUseSymbolicLinks: bUseSymbolicLinks, authent: sAuthent};
|
||||
$.post(GetAbsoluteUrlAppRoot()+'setup/ajax.dataloader.php', oAjaxParams);
|
||||
});
|
||||
JS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final protected function AddForceUninstallFlagOption(WebPage $oPage): void
|
||||
{
|
||||
$sChecked = $this->oWizard->GetParameter('force-uninstall', false) ? ' checked ' : '';
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Advanced parameters</legend>');
|
||||
$oPage->p('<input id="force-uninstall" type="checkbox"'.$sChecked.' name="force-uninstall"><label for="force-uninstall"> Disable uninstallation checks for extensions');
|
||||
$oPage->add('</fieldset>');
|
||||
|
||||
$oPage->add_ready_script(
|
||||
<<<'JS'
|
||||
$("#force-uninstall").on("click", function() {
|
||||
let $this = $(this);
|
||||
let bForceUninstall = $this.prop("checked");
|
||||
if( bForceUninstall && !confirm('Beware, uninstalling extensions flagged as non uninstallable may result in data corruption and application crashes. Are you sure you want to continue ?')){
|
||||
$this.prop("checked",false);
|
||||
}
|
||||
});
|
||||
JS
|
||||
);
|
||||
}
|
||||
}
|
||||
109
setup/wizardsteps/WizStepAdminAccount.php
Normal file
109
setup/wizardsteps/WizStepAdminAccount.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Administrator Account definition screen
|
||||
*/
|
||||
class WizStepAdminAccount extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Administrator Account';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepInstallMiscParams::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$this->oWizard->SaveParameter('admin_user', '');
|
||||
$this->oWizard->SaveParameter('admin_pwd', '');
|
||||
$this->oWizard->SaveParameter('confirm_pwd', '');
|
||||
$this->oWizard->SaveParameter('admin_language', 'EN US');
|
||||
|
||||
return ['class' => WizStepInstallMiscParams::class, 'state' => ''];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$sAdminUser = $this->oWizard->GetParameter('admin_user', 'admin');
|
||||
$sAdminPwd = $this->oWizard->GetParameter('admin_pwd', '');
|
||||
$sConfirmPwd = $this->oWizard->GetParameter('confirm_pwd', '');
|
||||
$sAdminLanguage = $this->oWizard->GetParameter('admin_language', 'EN US');
|
||||
$oPage->add('<h2>Definition of the Administrator Account</h2>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Administrator Account</legend>');
|
||||
$oPage->add('<table>');
|
||||
$oPage->add('<tr><td>Login: </td><td><input id="admin_user" class="ibo-input" name="admin_user" type="text" size="25" maxlength="64" value="'.utils::EscapeHtml($sAdminUser).'"><span id="v_admin_user"/></td></tr>');
|
||||
$oPage->add('<tr><td>Password: </td><td><input id="admin_pwd" class="ibo-input" autocomplete="off" name="admin_pwd" type="password" size="25" maxlength="64" value="'.utils::EscapeHtml($sAdminPwd).'"><span id="v_admin_pwd"/></td></tr>');
|
||||
$oPage->add('<tr><td>Confirm password: </td><td><input id="confirm_pwd" class="ibo-input" autocomplete="off" name="confirm_pwd" type="password" size="25" maxlength="64" value="'.utils::EscapeHtml($sConfirmPwd).'"></td></tr>');
|
||||
$sSourceDir = APPROOT.'dictionaries/';
|
||||
$aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
|
||||
$oPage->add('<tr><td>Language: </td><td>');
|
||||
$oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'admin_language', $sAdminLanguage));
|
||||
$oPage->add('</td></tr>');
|
||||
$oPage->add('</table>');
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$('#admin_user').on('change keyup', function() { WizardUpdateButtons(); } );
|
||||
$('#admin_pwd').on('change keyup', function() { WizardUpdateButtons(); } );
|
||||
$('#confirm_pwd').on('change keyup', function() { WizardUpdateButtons(); } );
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return
|
||||
<<<EOF
|
||||
bRet = ($('#admin_user').val() != '');
|
||||
if (!bRet)
|
||||
{
|
||||
$("#v_admin_user").html('<i class="fas fa-exclamation-triangle setup-invalid-field--icon" title="This field cannot be empty"></i>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#v_admin_user").html('');
|
||||
}
|
||||
|
||||
bPasswordsMatch = ($('#admin_pwd').val() == $('#confirm_pwd').val());
|
||||
if (!bPasswordsMatch)
|
||||
{
|
||||
$('#v_admin_pwd').html('<i class="fas fa-exclamation-triangle setup-invalid-field--icon" title="Retyped password does not match"></i>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#v_admin_pwd').html('');
|
||||
}
|
||||
bRet = bPasswordsMatch && bRet;
|
||||
|
||||
return bRet;
|
||||
EOF
|
||||
;
|
||||
}
|
||||
}
|
||||
118
setup/wizardsteps/WizStepDBParams.php
Normal file
118
setup/wizardsteps/WizStepDBParams.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Database Connection parameters screen
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
class WizStepDBParams extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Database Configuration';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepAdminAccount::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$this->oWizard->SaveParameter('db_server', '');
|
||||
$this->oWizard->SaveParameter('db_user', '');
|
||||
$this->oWizard->SaveParameter('db_pwd', '');
|
||||
$this->oWizard->SaveParameter('db_name', '');
|
||||
$this->oWizard->SaveParameter('db_prefix', '');
|
||||
$this->oWizard->SaveParameter('new_db_name', '');
|
||||
$this->oWizard->SaveParameter('create_db', '');
|
||||
$this->oWizard->SaveParameter('db_new_name', '');
|
||||
$this->oWizard->SaveParameter('db_tls_enabled', false);
|
||||
$this->oWizard->SaveParameter('db_tls_ca', '');
|
||||
|
||||
return ['class' => WizStepAdminAccount::class, 'state' => ''];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->add('<h2>Configuration of the database connection:</h2>');
|
||||
$sDBServer = $this->oWizard->GetParameter('db_server', '');
|
||||
$sDBUser = $this->oWizard->GetParameter('db_user', '');
|
||||
$sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
|
||||
$sDBName = $this->oWizard->GetParameter('db_name', '');
|
||||
$sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
|
||||
$sTlsEnabled = $this->oWizard->GetParameter('db_tls_enabled', '');
|
||||
$sTlsCA = $this->oWizard->GetParameter('db_tls_ca', '');
|
||||
$sNewDBName = $this->oWizard->GetParameter('db_new_name', false);
|
||||
|
||||
$oPage->add('<table>');
|
||||
SetupUtils::DisplayDBParameters(
|
||||
$oPage,
|
||||
true,
|
||||
$sDBServer,
|
||||
$sDBUser,
|
||||
$sDBPwd,
|
||||
$sDBName,
|
||||
$sDBPrefix,
|
||||
$sTlsEnabled,
|
||||
$sTlsCA,
|
||||
$sNewDBName
|
||||
);
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
$oPage->add('</table>');
|
||||
$sCreateDB = $this->oWizard->GetParameter('create_db', 'yes');
|
||||
if ($sCreateDB == 'no') {
|
||||
$oPage->add_ready_script('$("#existing_db").prop("checked", true);');
|
||||
} else {
|
||||
$oPage->add_ready_script('$("#create_db").prop("checked", true);');
|
||||
}
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
switch ($sCode) {
|
||||
case 'check_db':
|
||||
SetupUtils::AsyncCheckDB($oPage, $aParameters);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return
|
||||
<<<EOF
|
||||
if ($("#wiz_form").data("db_connection") === "error") return false;
|
||||
|
||||
var bRet = true;
|
||||
bRet = ValidateField("db_name", true) && bRet;
|
||||
bRet = ValidateField("db_new_name", true) && bRet;
|
||||
bRet = ValidateField("db_prefix", true) && bRet;
|
||||
|
||||
return bRet;
|
||||
EOF
|
||||
;
|
||||
}
|
||||
}
|
||||
121
setup/wizardsteps/WizStepDataAudit.php
Normal file
121
setup/wizardsteps/WizStepDataAudit.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
require_once(APPROOT.'setup/sequencers/DataAuditSequencer.php');
|
||||
|
||||
/**
|
||||
* @since 3.3.0
|
||||
*/
|
||||
class WizStepDataAudit extends WizStepInstall
|
||||
{
|
||||
public const SequencerClass = DataAuditSequencer::class;
|
||||
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Checking compatibility';
|
||||
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepSummary::class];
|
||||
}
|
||||
|
||||
public function GetNextButtonLabel()
|
||||
{
|
||||
return 'Next';
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
if ($this->CheckDependencies()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
return ['class' => WizStepSummary::class, 'state' => ''];
|
||||
}
|
||||
|
||||
public function CanComeBack()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
|
||||
$aInstallParams = $this->BuildConfig();
|
||||
|
||||
$this->AddProgressBar($oPage);
|
||||
|
||||
$sJSONData = json_encode($aInstallParams);
|
||||
$oPage->add('<input type="hidden" id="installer_parameters" value="'.utils::EscapeHtml($sJSONData).'"/>');
|
||||
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
$sApplicationUrl = $this->oWizard->GetParameter('application_url').'pages/exec.php?exec_module=combodo-data-feature-removal&exec_page=index.php';
|
||||
$oPage->add('<input type="hidden" id="application_url" value="'.$sApplicationUrl.'"/>');
|
||||
|
||||
if (!$this->CheckDependencies()) {
|
||||
$oPage->error($this->sDependencyIssue);
|
||||
}
|
||||
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$("#wiz_form").data("installation_status", "not started");
|
||||
ExecuteStep("");
|
||||
JS
|
||||
);
|
||||
}
|
||||
|
||||
protected function AddProgressErrorScript($oPage, $aRes)
|
||||
{
|
||||
if (isset($aRes['error_code']) && $aRes['error_code'] === DataAuditSequencer::DATA_AUDIT_FAILED) {
|
||||
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$('.ibo-setup--wizard--buttons-container tr td:nth-child(2)').before('<td style="text-align:center;"><button class="ibo-button ibo-is-alternative ibo-is-neutral" type="submit" name="operation" value="next"><span class="ibo-button--label">Ignore and continue</span></button></td>');
|
||||
|
||||
$('.ibo-setup--wizard--buttons-container tr td:nth-child(2)').after('<td style="text-align:center;"><a href="'+$('#application_url').val()+'"><button class="default ibo-button ibo-is-regular ibo-is-primary" type="button"><span class="ibo-button--label">Go to backoffice</span></button></a></td>');
|
||||
|
||||
$("#wiz_form").data("installation_status", "cleanup_needed");
|
||||
$('#btn_next').hide();
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return 'return ["completed", "cleanup_needed"].indexOf($("#wiz_form").data("installation_status")) !== -1;';
|
||||
}
|
||||
|
||||
public function JSCanMoveBackward()
|
||||
{
|
||||
return 'return ["not started", "error", "cleanup_needed"].indexOf($("#wiz_form").data("installation_status")) !== -1;';
|
||||
}
|
||||
}
|
||||
258
setup/wizardsteps/WizStepDetectedInfo.php
Normal file
258
setup/wizardsteps/WizStepDetectedInfo.php
Normal file
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Upgrade information
|
||||
*/
|
||||
class WizStepDetectedInfo extends WizardStep
|
||||
{
|
||||
protected $bCanMoveForward;
|
||||
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Upgrade Information';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepUpgradeMiscParams::class, WizStepLicense2::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$sUpgradeType = utils::ReadParam('upgrade_type');
|
||||
|
||||
$this->oWizard->SetParameter('mode', 'upgrade');
|
||||
$this->oWizard->SetParameter('upgrade_type', $sUpgradeType);
|
||||
$bDisplayLicense = $this->oWizard->GetParameter('display_license');
|
||||
|
||||
switch ($sUpgradeType) {
|
||||
case 'keep-previous':
|
||||
$sSourceDir = utils::ReadParam('relative_source_dir', '', false, 'raw_data');
|
||||
$this->oWizard->SetParameter('source_dir', $this->oWizard->GetParameter('previous_version_dir').'/'.$sSourceDir);
|
||||
$this->oWizard->SetParameter('datamodel_version', utils::ReadParam('datamodel_previous_version', '', false, 'raw_data'));
|
||||
break;
|
||||
|
||||
case 'use-compatible':
|
||||
$sDataModelPath = utils::ReadParam('datamodel_path', '', false, 'raw_data');
|
||||
$this->oWizard->SetParameter('source_dir', $sDataModelPath);
|
||||
$this->oWizard->SaveParameter('datamodel_version', '');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Do nothing, maybe the user pressed the Back button
|
||||
}
|
||||
if ($bDisplayLicense) {
|
||||
$aRet = ['class' => WizStepLicense2::class, 'state' => ''];
|
||||
} else {
|
||||
$aRet = ['class' => WizStepUpgradeMiscParams::class, 'state' => ''];
|
||||
}
|
||||
return $aRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebPage $oPage
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->add_style(
|
||||
<<<EOF
|
||||
#changes_summary {
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
}
|
||||
#changes_summary div {
|
||||
width:100;
|
||||
margin-top:0;
|
||||
padding-top: 0.5em;
|
||||
padding-left: 0;
|
||||
}
|
||||
#changes_summary div ul {
|
||||
margin-left:0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
#changes_summary div.closed ul {
|
||||
display:none;
|
||||
}
|
||||
#changes_summary div li {
|
||||
list-style: none;
|
||||
width: 100;
|
||||
margin-left:0;
|
||||
padding-left: 0em;
|
||||
}
|
||||
.title {
|
||||
padding-left: 20px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
background: url(../images/minus.gif) 2px 2px no-repeat;
|
||||
}
|
||||
#changes_summary div.closed .title {
|
||||
background: url(../images/plus.gif) 2px 2px no-repeat;
|
||||
}
|
||||
EOF
|
||||
);
|
||||
$this->bCanMoveForward = true;
|
||||
$bDisplayLicense = true;
|
||||
$sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', '');
|
||||
$aInstalledInfo = SetupUtils::GetApplicationVersion($this->oWizard);
|
||||
|
||||
if ($aInstalledInfo === false) {
|
||||
throw(new Exception('No previous version of '.ITOP_APPLICATION.' found in the supplied database. The upgrade cannot continue.'));
|
||||
} elseif (strcasecmp($aInstalledInfo['product_name'], ITOP_APPLICATION) != 0) {
|
||||
$oPage->p("<b>Warning: The installed products seem different. Are you sure that you want to upgrade {$aInstalledInfo['product_name']} with ".ITOP_APPLICATION."?</b>");
|
||||
}
|
||||
|
||||
$sInstalledVersion = $aInstalledInfo['product_version'];
|
||||
$sInstalledDataModelVersion = $aInstalledInfo['datamodel_version'];
|
||||
|
||||
$oPage->add("<h2>Information about the upgrade from version $sInstalledVersion to ".ITOP_VERSION_FULL."</h2>");
|
||||
|
||||
if ($sInstalledVersion == ITOP_VERSION_FULL) {
|
||||
// Reinstalling the same version let's skip the license agreement...
|
||||
$bDisplayLicense = false;
|
||||
}
|
||||
$this->oWizard->SetParameter('display_license', $bDisplayLicense); // Remember for later
|
||||
|
||||
$sCompatibleDMDir = SetupUtils::GetLatestDataModelDir();
|
||||
if ($sCompatibleDMDir === false) {
|
||||
// No compatible version exists... cannot upgrade. Either it is too old, or too new (downgrade !)
|
||||
$this->bCanMoveForward = false;
|
||||
$oPage->p("No datamodel directory found.");
|
||||
} else {
|
||||
$sUpgradeDMVersion = SetupUtils::GetDataModelVersion($sCompatibleDMDir);
|
||||
$sPreviousSourceDir = isset($aInstalledInfo['source_dir']) ? $aInstalledInfo['source_dir'] : 'modules';
|
||||
$aChanges = false;
|
||||
if (is_dir($sPreviousVersionDir)) {
|
||||
// Check if the previous version is a "genuine" one or not...
|
||||
$aChanges = SetupUtils::CheckVersion($sInstalledDataModelVersion, $sPreviousVersionDir.'/'.$sPreviousSourceDir);
|
||||
}
|
||||
if (($aChanges !== false) && ((count($aChanges['added']) > 0) || (count($aChanges['removed']) > 0) || (count($aChanges['modified']) > 0))) {
|
||||
// Some changes were detected, prompt the user to keep or discard them
|
||||
$oPage->p("<img src=\"../images/error.png\"/> Some modifications were detected between the ".ITOP_APPLICATION." version in '$sPreviousVersionDir' and a genuine $sInstalledVersion version.");
|
||||
$oPage->p("What do you want to do?");
|
||||
|
||||
$aWritableDirs = ['modules', 'portal'];
|
||||
$aErrors = SetupUtils::CheckWritableDirs($aWritableDirs);
|
||||
$sChecked = ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous') ? ' checked ' : '';
|
||||
$sDisabled = (count($aErrors) > 0) ? ' disabled ' : '';
|
||||
|
||||
$oPage->p('<input id="radio_upgrade_keep" type="radio" name="upgrade_type" value="keep-previous" '.$sChecked.$sDisabled.'/><label for="radio_upgrade_keep"> Preserve the modifications of the installed version (the dashboards inside '.ITOP_APPLICATION.' may not be editable).</label>');
|
||||
$oPage->add('<input type="hidden" name="datamodel_previous_version" value="'.utils::EscapeHtml($sInstalledDataModelVersion).'">');
|
||||
|
||||
$oPage->add('<input type="hidden" name="relative_source_dir" value="'.utils::EscapeHtml($sPreviousSourceDir).'">');
|
||||
|
||||
if (count($aErrors) > 0) {
|
||||
$oPage->p("Cannot copy the installed version due to the following access rights issue(s):");
|
||||
foreach ($aErrors as $sDir => $oCheckResult) {
|
||||
$oPage->p('<img src="../images/error.png"/> '.$oCheckResult->sLabel);
|
||||
}
|
||||
}
|
||||
|
||||
$sChecked = ($this->oWizard->GetParameter('upgrade_type') == 'use-compatible') ? ' checked ' : '';
|
||||
|
||||
$oPage->p('<input id="radio_upgrade_convert" type="radio" name="upgrade_type" value="use-compatible" '.$sChecked.'/><label for="radio_upgrade_convert"> Discard the modifications, use a standard '.$sUpgradeDMVersion.' data model.</label>');
|
||||
|
||||
$oPage->add('<input type="hidden" name="datamodel_path" value="'.utils::EscapeHtml($sCompatibleDMDir).'">');
|
||||
$oPage->add('<input type="hidden" name="datamodel_version" value="'.utils::EscapeHtml($sUpgradeDMVersion).'">');
|
||||
|
||||
$oPage->add('<div id="changes_summary"><div class="closed"><span class="title">Details of the modifications</span><div>');
|
||||
if (count($aChanges['added']) > 0) {
|
||||
$oPage->add('<ul>New files added:');
|
||||
foreach ($aChanges['added'] as $sFilePath => $void) {
|
||||
$oPage->add('<li>'.$sFilePath.'</li>');
|
||||
}
|
||||
$oPage->add('</ul>');
|
||||
}
|
||||
if (count($aChanges['removed']) > 0) {
|
||||
$oPage->add('<ul>Deleted files:');
|
||||
foreach ($aChanges['removed'] as $sFilePath => $void) {
|
||||
$oPage->add('<li>'.$sFilePath.'</li>');
|
||||
}
|
||||
$oPage->add('</ul>');
|
||||
}
|
||||
if (count($aChanges['modified']) > 0) {
|
||||
$oPage->add('<ul>Modified files:');
|
||||
foreach ($aChanges['modified'] as $sFilePath => $void) {
|
||||
$oPage->add('<li>'.$sFilePath.'</li>');
|
||||
}
|
||||
$oPage->add('</ul>');
|
||||
}
|
||||
$oPage->add('</div></div></div>');
|
||||
} else {
|
||||
// No changes detected... or no way to tell because of the lack of a manifest or previous source dir
|
||||
// Use the "compatible" datamodel as-is.
|
||||
$sCompatibleDMDirToDisplay = utils::HtmlEntities($sCompatibleDMDir);
|
||||
$sUpgradeDMVersionToDisplay = utils::HtmlEntities($sUpgradeDMVersion);
|
||||
$oPage->add(
|
||||
<<<HTML
|
||||
<div class="message message-valid">The datamodel will be upgraded from version $sInstalledDataModelVersion to version $sUpgradeDMVersion.</div>
|
||||
<input type="hidden" name="upgrade_type" value="use-compatible">
|
||||
<input type="hidden" name="datamodel_path" value="$sCompatibleDMDirToDisplay">
|
||||
<input type="hidden" name="datamodel_version" value="$sUpgradeDMVersionToDisplay">
|
||||
HTML
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#changes_summary .title").on('click', function() { $(this).parent().toggleClass('closed'); } );
|
||||
$('input[name=upgrade_type]').on('click change', function() { WizardUpdateButtons(); });
|
||||
EOF
|
||||
);
|
||||
|
||||
$oMutex = new iTopMutex(
|
||||
'cron'.$this->oWizard->GetParameter('db_name', '').$this->oWizard->GetParameter('db_prefix', ''),
|
||||
$this->oWizard->GetParameter('db_server', ''),
|
||||
$this->oWizard->GetParameter('db_user', ''),
|
||||
$this->oWizard->GetParameter('db_pwd', ''),
|
||||
$this->oWizard->GetParameter('db_tls_enabled', ''),
|
||||
$this->oWizard->GetParameter('db_tls_ca', '')
|
||||
);
|
||||
if ($oMutex->IsLocked()) {
|
||||
$oPage->add('<div class="message">'.ITOP_APPLICATION.' cron process is being executed on the target database. '.ITOP_APPLICATION.' cron process will be stopped during the setup execution.</div>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return $this->bCanMoveForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return
|
||||
<<<EOF
|
||||
if ($("#radio_upgrade_keep").length == 0) return true;
|
||||
|
||||
bRet = ($('input[name=upgrade_type]:checked').length > 0);
|
||||
return bRet;
|
||||
EOF
|
||||
;
|
||||
}
|
||||
}
|
||||
169
setup/wizardsteps/WizStepDone.php
Normal file
169
setup/wizardsteps/WizStepDone.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Summary of the installation tasks
|
||||
*/
|
||||
class WizStepDone extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Done';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
return ['class' => '', 'state' => ''];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
// Check if there are some manual steps required:
|
||||
$aManualSteps = [];
|
||||
$aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
|
||||
|
||||
$sRootUrl = utils::GetAbsoluteUrlAppRoot(true);
|
||||
$aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
|
||||
foreach ($aSelectedModules as $sModuleId) {
|
||||
if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup'])) {
|
||||
$sUrl = $aAvailableModules[$sModuleId]['doc.manual_setup'];
|
||||
$sManualStepUrl = utils::IsURL($sUrl) ? $sUrl : $sRootUrl.$sUrl;
|
||||
$aManualSteps[$aAvailableModules[$sModuleId]['label']] = $sManualStepUrl;
|
||||
}
|
||||
}
|
||||
$oPage->add('<div class="ibo-is-html-content">');
|
||||
if (count($aManualSteps) > 0) {
|
||||
$oPage->add("<h2>Manual operations required</h2>");
|
||||
$oPage->p("In order to complete the installation, the following manual operations are required:");
|
||||
foreach ($aManualSteps as $sModuleLabel => $sUrl) {
|
||||
$oPage->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
|
||||
}
|
||||
$oPage->add("<h2>Congratulations for installing ".ITOP_APPLICATION."</h2>");
|
||||
} else {
|
||||
$oPage->add("<h2>Congratulations for installing ".ITOP_APPLICATION."</h2>");
|
||||
$oPage->ok("The installation completed successfully.");
|
||||
}
|
||||
|
||||
$bHasBackup = false;
|
||||
if (($this->oWizard->GetParameter('mode', '') == 'upgrade') && $this->oWizard->GetParameter('db_backup', false) && $this->oWizard->GetParameter('authent', false)) {
|
||||
$sBackupDestination = $this->oWizard->GetParameter('db_backup_path', '');
|
||||
if (file_exists($sBackupDestination.'.tar.gz')) {
|
||||
$bHasBackup = true;
|
||||
// To mitigate security risks: pass only the filename without the extension, the download will add the extension itself
|
||||
$oPage->p('Your backup is ready');
|
||||
$oPage->p('<a style="background:transparent;" href="'.utils::GetAbsoluteUrlAppRoot(true).'setup/ajax.dataloader.php?operation=async_action&step_class=WizStepDone¶ms[backup]='.urlencode($sBackupDestination).'&authent='.$this->oWizard->GetParameter('authent', '').'" target="_blank"><img src="../images/icons/icons8-archive-folder.svg" style="border:0;vertical-align:middle;"> Download '.basename($sBackupDestination).'</a>');
|
||||
} else {
|
||||
$oPage->p('<img src="../images/error.png"/> Warning: Backup creation failed !');
|
||||
}
|
||||
}
|
||||
|
||||
// Form goes here.. No back button since the job is done !
|
||||
$oPage->add('<div id="placeholder" class="setup-end-placeholder">');
|
||||
$oPage->add("<div><a class=\"ibo-svg-illustration--container\" title=\"Subscribe to Combodo Newsletter.\" href=\"https://www.combodo.com/newsletter-subscription?var_mode=recalcul\" target=\"_blank\">".file_get_contents(APPROOT.'images/illustrations/undraw_newsletter.svg')." Register now</a></div>");
|
||||
$oPage->add("<div><a class=\"ibo-svg-illustration--container\" title=\"Get Professional Support from Combodo\" href=\"https://support.combodo.com\" target=\"_blank\">".file_get_contents(APPROOT.'images/illustrations/undraw_active_support.svg')."Get professional support</a></div>");
|
||||
$oPage->add("<div><a class=\"ibo-svg-illustration--container\" title=\"Get Professional Training from Combodo\" href=\"http://www.combodo.com/training\" target=\"_blank\">".file_get_contents(APPROOT.'images/illustrations/undraw_education.svg')."Get professional training</a></div>");
|
||||
$oPage->add('</div>');
|
||||
|
||||
$oPage->add('</div>');
|
||||
|
||||
$oConfig = new Config(utils::GetConfigFilePath());
|
||||
$aParamValues = $this->oWizard->GetParamForConfigArray();
|
||||
$oConfig->UpdateFromParams($aParamValues);
|
||||
// Load the data model only, in order to load env-production/core/main.php to get the XML parameters (needed by GetModuleSettings below)
|
||||
// But main.php may also contain classes (defined without any module), and thus requiring the full data model
|
||||
// to be loaded to prevent "class not found" errors...
|
||||
$oProductionEnv = new RunTimeEnvironment('production');
|
||||
$oProductionEnv->InitDataModel($oConfig, true);
|
||||
$sIframeUrl = $oConfig->GetModuleSetting('itop-hub-connector', 'setup_url', '');
|
||||
|
||||
$sSetupTokenFile = APPROOT.'data/.setup';
|
||||
$sSetupToken = bin2hex(random_bytes(12));
|
||||
file_put_contents($sSetupTokenFile, $sSetupToken);
|
||||
$sIframeUrl .= "&setup_token=$sSetupToken";
|
||||
|
||||
if ($sIframeUrl != '') {
|
||||
$oPage->add('<iframe id="fresh_content" frameborder="0" scrolling="auto" src="'.$sIframeUrl.'"></iframe>');
|
||||
|
||||
$oPage->add_script("
|
||||
window.addEventListener('message', function(event) {
|
||||
if (event.data === 'itophub_load_completed')
|
||||
{
|
||||
$('#placeholder').hide();
|
||||
$('#fresh_content').show();
|
||||
}
|
||||
}, false);
|
||||
");
|
||||
}
|
||||
|
||||
$sForm = '<div class="ibo-setup--wizard--buttons-container" style="text-align:center"><form method="post" class="ibo-setup--enter-itop" action="'.$this->oWizard->GetParameter('application_url').'pages/UI.php">';
|
||||
$sForm .= '<input type="hidden" name="auth_user" value="'.utils::EscapeHtml($this->oWizard->GetParameter('admin_user')).'">';
|
||||
$sForm .= '<input type="hidden" name="auth_pwd" value="'.utils::EscapeHtml($this->oWizard->GetParameter('admin_pwd')).'">';
|
||||
$sForm .= "<button id=\"enter_itop\" class=\"ibo-button ibo-is-regular ibo-is-primary\" type=\"submit\">Enter ".ITOP_APPLICATION."</button></div>";
|
||||
$sForm .= '</form>';
|
||||
|
||||
$sForm = addslashes($sForm);
|
||||
$oPage->add_ready_script("$('#wiz_form').append('$sForm');");
|
||||
// avoid leaving in a dirty state
|
||||
SetupUtils::ExitMaintenanceMode(false);
|
||||
SetupUtils::ExitReadOnlyMode(false);
|
||||
|
||||
if (false === $bHasBackup) {
|
||||
SetupUtils::EraseSetupToken();
|
||||
}
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function CanMoveBackward()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this step of the wizard requires that the configuration file be writable
|
||||
* @return bool True if the wizard will possibly need to modify the configuration at some point
|
||||
*/
|
||||
public function RequiresWritableConfig()
|
||||
{
|
||||
return false; //This step executes once the config was written and secured
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
SetupUtils::EraseSetupToken();
|
||||
// For security reasons: add the extension now so that this action can be used to read *only* .tar.gz files from the disk...
|
||||
$sBackupFile = $aParameters['backup'].'.tar.gz';
|
||||
if (file_exists($sBackupFile)) {
|
||||
// Make sure there is NO output at all before our content, otherwise the document will be corrupted
|
||||
$sPreviousContent = ob_get_clean();
|
||||
$oPage->SetContentType('application/gzip');
|
||||
$oPage->SetContentDisposition('attachment', basename($sBackupFile));
|
||||
$oPage->add(file_get_contents($sBackupFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
170
setup/wizardsteps/WizStepInstall.php
Normal file
170
setup/wizardsteps/WizStepInstall.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
require_once(APPROOT.'setup/sequencers/ApplicationInstallSequencer.php');
|
||||
|
||||
class WizStepInstall extends AbstractWizStepInstall
|
||||
{
|
||||
public const SequencerClass = ApplicationInstallSequencer::class;
|
||||
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Building iTop';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepDone::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label for the " Next >> " button
|
||||
* @return string The label for the button
|
||||
*/
|
||||
public function GetNextButtonLabel()
|
||||
{
|
||||
return 'Continue';
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
if ($this->CheckDependencies()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
return ['class' => WizStepDone::class, 'state' => ''];
|
||||
}
|
||||
|
||||
protected function AddProgressBar(WebPage $oPage)
|
||||
{
|
||||
$oPage->add('<fieldset id="installation_progress"><legend>Progress of the installation</legend>');
|
||||
$oPage->add('<div id="progress_content">');
|
||||
$oPage->LinkScriptFromAppRoot('setup/jquery.progression.js');
|
||||
$oPage->add('<p class="center"><span id="setup_msg">Ready to start...</span></p><div style="display:block;margin-left: auto; margin-right:auto;" id="progress">0%</div>');
|
||||
$oPage->add('</div>'); // progress_content
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add("<div class=\"message message-error ibo-is-html-content\" style=\"display:none;\" id=\"setup_error\"></div>");
|
||||
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
|
||||
$aInstallParams = $this->BuildConfig();
|
||||
$this->AddProgressBar($oPage);
|
||||
|
||||
$sJSONData = json_encode($aInstallParams);
|
||||
$oPage->add('<input type="hidden" id="installer_parameters" value="'.utils::EscapeHtml($sJSONData).'"/>');
|
||||
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$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", "not started");
|
||||
ExecuteStep("");
|
||||
JS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
$oParameters = new PHPParameters();
|
||||
$sStep = $aParameters['installer_step'];
|
||||
$sJSONParameters = $aParameters['installer_config'];
|
||||
$oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */));
|
||||
$oInstaller = new (static::SequencerClass)($oParameters);
|
||||
$aRes = $oInstaller->ExecuteStep($sStep);
|
||||
if (($aRes['status'] != $oInstaller::ERROR) && ($aRes['next-step'] != '')) {
|
||||
// Tell the web page to move the progress bar and to launch the next step
|
||||
$sMessage = addslashes(utils::EscapeHtml($aRes['next-step-label']));
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#wiz_form").data("installation_status", "running");
|
||||
WizardUpdateButtons();
|
||||
$('#setup_msg').html('$sMessage');
|
||||
$('#progress').progression( {Current:{$aRes['percentage-completed']}, Maximum: 100} );
|
||||
|
||||
//$("#percentage").html('{$aRes['percentage-completed']} % completed<br/>{$aRes['next-step-label']}');
|
||||
ExecuteStep('{$aRes['next-step']}');
|
||||
EOF
|
||||
);
|
||||
} elseif ($aRes['status'] != $oInstaller::ERROR) {
|
||||
// Installation complete, move to the next step of the wizard
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#wiz_form").data("installation_status", "completed");
|
||||
$('#progress').progression( {Current:100, Maximum: 100} );
|
||||
WizardUpdateButtons();
|
||||
$("#btn_next").off("click.install");
|
||||
$("#btn_next").trigger('click');
|
||||
EOF
|
||||
);
|
||||
} else {
|
||||
//Error case
|
||||
$sMessage = addslashes(utils::EscapeHtml($aRes['message']));
|
||||
$sMessage = str_replace("\n", '<br>', $sMessage);
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#wiz_form").data("installation_status", "error");
|
||||
WizardUpdateButtons();
|
||||
$('#setup_error').html('$sMessage').show();
|
||||
EOF
|
||||
);
|
||||
$this->AddProgressErrorScript($oPage, $aRes);
|
||||
}
|
||||
}
|
||||
|
||||
protected function AddProgressErrorScript($oPage, $aRes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return 'return $("#wiz_form").data("installation_status") === "completed";';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveBackward()
|
||||
{
|
||||
return 'var sStatus = $("#wiz_form").data("installation_status"); return ((sStatus === "not started") || (sStatus === "error"));';
|
||||
}
|
||||
|
||||
}
|
||||
184
setup/wizardsteps/WizStepInstallMiscParams.php
Normal file
184
setup/wizardsteps/WizStepInstallMiscParams.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Miscellaneous Parameters (URL, Sample Data) when installing from scratch
|
||||
*/
|
||||
class WizStepInstallMiscParams extends AbstractWizStepMiscParams
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Miscellaneous Parameters';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepModulesChoice::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$this->oWizard->SaveParameter('default_language', '');
|
||||
$this->oWizard->SaveParameter('application_url', '');
|
||||
$this->oWizard->SaveParameter('graphviz_path', '');
|
||||
$this->oWizard->SaveParameter('sample_data', 'yes');
|
||||
return ['class' => WizStepModulesChoice::class, 'state' => 'start_install'];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$sDefaultLanguage = $this->oWizard->GetParameter('default_language', $this->oWizard->GetParameter('admin_language'));
|
||||
$sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot(true));
|
||||
$sDefaultGraphvizPath = (strtolower(substr(PHP_OS, 0, 3)) === 'win') ? 'C:\\Program Files\\Graphviz\\bin\\dot.exe' : '/usr/bin/dot';
|
||||
$sGraphvizPath = $this->oWizard->GetParameter('graphviz_path', $sDefaultGraphvizPath);
|
||||
$sSampleData = $this->oWizard->GetParameter('sample_data', 'yes');
|
||||
$oPage->add('<h2>Additional parameters</h2>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Default Language</legend>');
|
||||
$oPage->add('<table>');
|
||||
$sSourceDir = APPROOT.'dictionaries/';
|
||||
$aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
|
||||
$oPage->add('<tr><td>Default Language: </td><td>');
|
||||
$oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'default_language', $sDefaultLanguage));
|
||||
$oPage->add('</td></tr>');
|
||||
$oPage->add('</table>');
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Application URL</legend>');
|
||||
$oPage->add('<table>');
|
||||
$oPage->add('<tr><td>URL: </td><td><input id="application_url" class="ibo-input" name="application_url" type="text" size="35" maxlength="1024" value="'.utils::EscapeHtml($sApplicationURL).'" style="width: 100%;box-sizing: border-box;"><span id="v_application_url"/></td><tr>');
|
||||
$oPage->add('</table>');
|
||||
$oPage->add('<div class="message message-warning">Change the value above if the end-users will be accessing the application by another path due to a specific configuration of the web server.</div>');
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Path to Graphviz\' dot application</legend>');
|
||||
$oPage->add('<table>');
|
||||
$oPage->add('<tr><td>Path: </td><td><input id="graphviz_path" class="ibo-input" name="graphviz_path" type="text" size="35" maxlength="1024" value="'.utils::EscapeHtml($sGraphvizPath).'" style="width: 100%;box-sizing: border-box;"><span id="v_graphviz_path"/></td>');
|
||||
$oPage->add('<td><i class="fas fa-question-circle setup-input--hint--icon" data-tooltip-content="Graphviz is required to display the impact analysis graph (i.e. impacts / depends on)."></i></td><tr>');
|
||||
$oPage->add('</table>');
|
||||
$oPage->add('<span id="graphviz_status"></span>');
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Sample Data</legend>');
|
||||
$sChecked = ($sSampleData == 'yes') ? 'checked ' : '';
|
||||
$oPage->p('<input id="sample_data_yes" name="sample_data" type="radio" value="yes" '.$sChecked.'><label for="sample_data_yes"> I am installing a <b>demo or test</b> instance, populate the database with some demo data.');
|
||||
$sChecked = ($sSampleData == 'no') ? 'checked ' : '';
|
||||
$oPage->p('<input id="sample_data_no" name="sample_data" type="radio" value="no" '.$sChecked.'><label for="sample_data_no"> I am installing a <b>production</b> instance, create an empty database to start from.');
|
||||
$oPage->add('</fieldset>');
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$('#application_url').on('change keyup', function() { WizardUpdateButtons(); } );
|
||||
$('#graphviz_path').on('change keyup init', function() { WizardUpdateButtons(); WizardAsyncAction('check_graphviz', { graphviz_path: $('#graphviz_path').val(), authent: $('#authent_token').val()}); } ).trigger('init');
|
||||
$('#btn_next').on('click', function() {
|
||||
bRet = true;
|
||||
if ($(this).attr('data-graphviz') != 'ok')
|
||||
{
|
||||
bRet = confirm('The impact analysis will not be displayed properly. Are you sure you want to continue?');
|
||||
}
|
||||
return bRet;
|
||||
});
|
||||
EOF
|
||||
);
|
||||
|
||||
$this->AddUseSymlinksFlagOption($oPage);
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
switch ($sCode) {
|
||||
case 'check_graphviz':
|
||||
$sGraphvizPath = $aParameters['graphviz_path'];
|
||||
$aCheck = SetupUtils::CheckGraphviz($sGraphvizPath);
|
||||
|
||||
// N°2214 logging TRACE results
|
||||
$aTraceCheck = CheckResult::FilterCheckResultArray($aCheck, [CheckResult::TRACE]);
|
||||
foreach ($aTraceCheck as $oTraceCheck) {
|
||||
SetupLog::Ok($oTraceCheck->sLabel);
|
||||
}
|
||||
|
||||
$aNonTraceCheck = array_diff($aCheck, $aTraceCheck);
|
||||
foreach ($aNonTraceCheck as $oCheck) {
|
||||
switch ($oCheck->iSeverity) {
|
||||
case CheckResult::INFO:
|
||||
$sStatus = 'ok';
|
||||
$sInfoExplanation = $oCheck->sLabel;
|
||||
$sMessage = json_encode('<div class="message message-valid">'.$sInfoExplanation.'</div>');
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
case CheckResult::ERROR:
|
||||
case CheckResult::WARNING:
|
||||
$sStatus = 'ko';
|
||||
$sErrorExplanation = $oCheck->sLabel;
|
||||
$sMessage = json_encode('<div class="message message-error">'.$sErrorExplanation.'</div>');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($oCheck->iSeverity !== CheckResult::TRACE) {
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$("#graphviz_status").html($sMessage);
|
||||
$('#btn_next').attr('data-graphviz', '$sStatus');
|
||||
JS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return
|
||||
<<<EOF
|
||||
bRet = ($('#application_url').val() != '');
|
||||
if (!bRet)
|
||||
{
|
||||
$("#v_application_url").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#v_application_url").html('');
|
||||
}
|
||||
bGraphviz = ($('#graphviz_path').val() != '');
|
||||
if (!bGraphviz)
|
||||
{
|
||||
// Does not prevent to move forward
|
||||
$("#v_graphviz_path").html('<img src="../images/validation_error.png" title="Impact analysis will not display properly"/>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#v_graphviz_path").html('');
|
||||
}
|
||||
return bRet;
|
||||
EOF
|
||||
;
|
||||
}
|
||||
}
|
||||
217
setup/wizardsteps/WizStepInstallOrUpgrade.php
Normal file
217
setup/wizardsteps/WizStepInstallOrUpgrade.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Second step of the iTop Installation Wizard: Install or Upgrade
|
||||
*/
|
||||
class WizStepInstallOrUpgrade extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Install or Upgrade choice';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepDetectedInfo::class, WizStepLicense::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$sNextStep = '';
|
||||
$sInstallMode = utils::ReadParam('install_mode');
|
||||
|
||||
$this->oWizard->SaveParameter('previous_version_dir', '');
|
||||
$this->oWizard->SaveParameter('db_server', '');
|
||||
$this->oWizard->SaveParameter('db_user', '');
|
||||
$this->oWizard->SaveParameter('db_pwd', '');
|
||||
$this->oWizard->SaveParameter('db_name', '');
|
||||
$this->oWizard->SaveParameter('db_prefix', '');
|
||||
$this->oWizard->SaveParameter('db_tls_enabled', false);
|
||||
$this->oWizard->SaveParameter('db_tls_ca', '');
|
||||
|
||||
if ($sInstallMode == 'install') {
|
||||
$this->oWizard->SetParameter('install_mode', 'install');
|
||||
$sFullSourceDir = SetupUtils::GetLatestDataModelDir();
|
||||
$this->oWizard->SetParameter('source_dir', $sFullSourceDir);
|
||||
$this->oWizard->SetParameter('datamodel_version', SetupUtils::GetDataModelVersion($sFullSourceDir));
|
||||
$sNextStep = WizStepLicense::class;
|
||||
} else {
|
||||
$this->oWizard->SetParameter('install_mode', 'upgrade');
|
||||
$sNextStep = WizStepDetectedInfo::class;
|
||||
|
||||
}
|
||||
return ['class' => $sNextStep, 'state' => ''];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$sInstallMode = $this->oWizard->GetParameter('install_mode', '');
|
||||
$sDBServer = $this->oWizard->GetParameter('db_server', '');
|
||||
$sDBUser = $this->oWizard->GetParameter('db_user', '');
|
||||
$sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
|
||||
$sDBName = $this->oWizard->GetParameter('db_name', '');
|
||||
$sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
|
||||
$sTlsEnabled = $this->oWizard->GetParameter('db_tls_enabled', false);
|
||||
$sTlsCA = $this->oWizard->GetParameter('db_tls_ca', '');
|
||||
$sPreviousVersionDir = '';
|
||||
if ($sInstallMode == '') {
|
||||
$aPreviousInstance = SetupUtils::GetPreviousInstance(APPROOT);
|
||||
if ($aPreviousInstance['found']) {
|
||||
$sInstallMode = 'upgrade';
|
||||
$sDBServer = $aPreviousInstance['db_server'];
|
||||
$sDBUser = $aPreviousInstance['db_user'];
|
||||
$sDBPwd = $aPreviousInstance['db_pwd'];
|
||||
$sDBName = $aPreviousInstance['db_name'];
|
||||
$sDBPrefix = $aPreviousInstance['db_prefix'];
|
||||
$sTlsEnabled = $aPreviousInstance['db_tls_enabled'];
|
||||
$sTlsCA = $aPreviousInstance['db_tls_ca'];
|
||||
$this->oWizard->SaveParameter('graphviz_path', $aPreviousInstance['graphviz_path']);
|
||||
$sPreviousVersionDir = APPROOT;
|
||||
} else {
|
||||
$sInstallMode = 'install';
|
||||
}
|
||||
}
|
||||
$sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', $sPreviousVersionDir);
|
||||
|
||||
$sUpgradeInfoStyle = '';
|
||||
if ($sInstallMode == 'install') {
|
||||
$sUpgradeInfoStyle = ' style="display: none;" ';
|
||||
}
|
||||
$oPage->add('<div class="setup-content-title">What do you want to do?</div>');
|
||||
$sChecked = ($sInstallMode == 'install') ? ' checked ' : '';
|
||||
$oPage->p('<input id="radio_install" type="radio" name="install_mode" value="install" '.$sChecked.'/><label for="radio_install"> Install a new '.ITOP_APPLICATION.'</label>');
|
||||
$sChecked = ($sInstallMode == 'upgrade') ? ' checked ' : '';
|
||||
$sDisabled = (($sInstallMode == 'install') && (empty($sPreviousVersionDir))) ? ' disabled' : '';
|
||||
$oPage->p('<input id="radio_update" type="radio" name="install_mode" value="upgrade" '.$sChecked.$sDisabled.'/><label for="radio_update"> Upgrade an existing '.ITOP_APPLICATION.' instance</label>');
|
||||
|
||||
$sUpgradeDir = utils::HtmlEntities($sPreviousVersionDir);
|
||||
$oPage->add(
|
||||
<<<HTML
|
||||
<div id="upgrade_info"'.$sUpgradeInfoStyle.'>
|
||||
<div class="setup-disk-location--input--container">Location on the disk:<input id="previous_version_dir_display" type="text" value="$sUpgradeDir" class="ibo-input" disabled>
|
||||
<input type="hidden" name="previous_version_dir" value="$sUpgradeDir"></div>
|
||||
HTML
|
||||
);
|
||||
|
||||
SetupUtils::DisplayDBParameters(
|
||||
$oPage,
|
||||
false,
|
||||
$sDBServer,
|
||||
$sDBUser,
|
||||
$sDBPwd,
|
||||
$sDBName,
|
||||
$sDBPrefix,
|
||||
$sTlsEnabled,
|
||||
$sTlsCA,
|
||||
null
|
||||
);
|
||||
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
//$oPage->add('</fieldset>');
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$("#radio_update").on('change', function() { if (this.checked ) { $('#upgrade_info').show(); WizardUpdateButtons(); } else { $('#upgrade_info').hide(); } });
|
||||
$("#radio_install").on('change', function() { if (this.checked ) { $('#upgrade_info').hide(); WizardUpdateButtons(); } else { $('#upgrade_info').show(); } });
|
||||
JS
|
||||
);
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
switch ($sCode) {
|
||||
case 'check_path':
|
||||
$sPreviousVersionDir = $aParameters['previous_version_dir'];
|
||||
$aPreviousInstance = SetupUtils::GetPreviousInstance($sPreviousVersionDir);
|
||||
if ($aPreviousInstance['found']) {
|
||||
$sDBServer = utils::EscapeHtml($aPreviousInstance['db_server']);
|
||||
$sDBUser = utils::EscapeHtml($aPreviousInstance['db_user']);
|
||||
$sDBPwd = utils::EscapeHtml($aPreviousInstance['db_pwd']);
|
||||
$sDBName = utils::EscapeHtml($aPreviousInstance['db_name']);
|
||||
$sDBPrefix = utils::EscapeHtml($aPreviousInstance['db_prefix']);
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#db_server").val('$sDBServer');
|
||||
$("#db_user").val('$sDBUser');
|
||||
$("#db_pwd").val('$sDBPwd');
|
||||
$("#db_name").val('$sDBName');
|
||||
$("#db_prefix").val('$sDBPrefix');
|
||||
$("#db_pwd").trigger('change'); // Forces check of the DB connection
|
||||
EOF
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'check_db':
|
||||
SetupUtils::AsyncCheckDB($oPage, $aParameters);
|
||||
break;
|
||||
|
||||
case 'check_backup':
|
||||
$sDBBackupPath = $aParameters['db_backup_path'];
|
||||
$fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
|
||||
if ($fFreeSpace !== false) {
|
||||
$sMessage = utils::EscapeHtml(SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath));
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#backup_info").html('$sMessage');
|
||||
EOF
|
||||
);
|
||||
} else {
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#backup_info").html('');
|
||||
EOF
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return
|
||||
<<<EOF
|
||||
if ($("#radio_install").prop("checked"))
|
||||
{
|
||||
ValidateField("db_name", false);
|
||||
ValidateField("db_new_name", false);
|
||||
ValidateField("db_prefix", false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var bRet = ($("#wiz_form").data("db_connection") !== "error");
|
||||
bRet = ValidateField("db_name", true) && bRet;
|
||||
bRet = ValidateField("db_new_name", true) && bRet;
|
||||
bRet = ValidateField("db_prefix", true) && bRet;
|
||||
|
||||
return bRet;
|
||||
}
|
||||
EOF
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
133
setup/wizardsteps/WizStepLicense.php
Normal file
133
setup/wizardsteps/WizStepLicense.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* License acceptation screen
|
||||
*/
|
||||
class WizStepLicense extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'License Agreement';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepDBParams::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$this->oWizard->SaveParameter('accept_license', 'no');
|
||||
return ['class' => WizStepDBParams::class, 'state' => ''];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool true if we need to display a GDPR confirmation
|
||||
* @throws \Exception
|
||||
* @since 2.7.7 3.0.2 3.1.0 N°5037 method creation
|
||||
* @since 2.7.8 3.0.3 3.1.0 N°5758 rename from NeedsRgpdConsent to NeedsGdprConsent
|
||||
*/
|
||||
private function NeedsGdprConsent()
|
||||
{
|
||||
$sMode = $this->oWizard->GetParameter('install_mode');
|
||||
|
||||
if ($sMode !== 'install') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$aModules = SetupUtils::AnalyzeInstallation($this->oWizard);
|
||||
return SetupUtils::IsConnectableToITopHub($aModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebPage $oPage
|
||||
*/
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$aLicenses = SetupUtils::GetLicenses();
|
||||
$oPage->add_style(
|
||||
<<<CSS
|
||||
fieldset ul {
|
||||
max-height: min(30em, 40vh); /* Allow usage of the UI up to 150% zoom */
|
||||
overflow: auto;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$oPage->add('<h2>Licenses agreements for the components of '.ITOP_APPLICATION.'</h2>');
|
||||
$oPage->add_style('div a.no-arrow { background:transparent; padding-left:0;}');
|
||||
$oPage->add_style('.toggle { cursor:pointer; text-decoration:underline; color:#1C94C4; }');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Components of '.ITOP_APPLICATION.'</legend>');
|
||||
$oPage->add('<ul id="ibo-setup-licenses--components-list">');
|
||||
$index = 0;
|
||||
foreach ($aLicenses as $oLicense) {
|
||||
$oPage->add('<li><b>'.$oLicense->product.'</b>, © '.$oLicense->author.' is licensed under the <b>'.$oLicense->license_type.' license</b>. (<span class="toggle" id="toggle_'.$index.'">Details</span>)');
|
||||
$oPage->add('<div id="license_'.$index.'" class="license_text ibo-is-html-content" style="display:none;overflow:auto;max-height:10em;font-size:12px;border:1px #696969 solid;margin-bottom:1em; margin-top:0.5em;padding:0.5em;"><pre>'.$oLicense->text.'</pre></div>');
|
||||
$oPage->add_ready_script('$(".license_text a").attr("target", "_blank").addClass("no-arrow");');
|
||||
$oPage->add_ready_script('$("#toggle_'.$index.'").on("click", function() { $("#license_'.$index.'").toggle(); } );');
|
||||
$index++;
|
||||
}
|
||||
$oPage->add('</ul>');
|
||||
$oPage->add('</fieldset>');
|
||||
$sChecked = ($this->oWizard->GetParameter('accept_license', 'no') == 'yes') ? ' checked ' : '';
|
||||
$oPage->add('<div class="setup-accept-licenses"><input class="check_select" type="checkbox" name="accept_license" id="accept" value="yes" '.$sChecked.'><label for="accept">I accept the terms of the licenses of the '.count($aLicenses).' components mentioned above.</label></div>');
|
||||
if ($this->NeedsGdprConsent()) {
|
||||
$oPage->add('<br>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>European General Data Protection Regulation</legend>');
|
||||
$oPage->add('<div class="ibo-setup-licenses--components-list">'.ITOP_APPLICATION.' software is compliant with the processing of personal data according to the European General Data Protection Regulation (GDPR).<p></p>
|
||||
By installing '.ITOP_APPLICATION.' you agree that some information will be collected by Combodo to help you manage your instances and for statistical purposes.
|
||||
This data remains anonymous until it is associated to a user account on iTop Hub.</p>
|
||||
<p>List of collected data available in our <a target="_blank" href="https://www.itophub.io/page/data-privacy">Data privacy section.</a></p><br></div>');
|
||||
$oPage->add('<input type="checkbox" class="check_select" id="rgpd_consent">');
|
||||
$oPage->add('<label for="rgpd_consent"> I accept the processing of my personal data</label>');
|
||||
$oPage->add('</fieldset>');
|
||||
}
|
||||
$oPage->add_ready_script('$(".check_select").on("click change", function() { WizardUpdateButtons(); });');
|
||||
|
||||
$oPage->add_script(
|
||||
<<<JS
|
||||
function isRgpdConsentOk(){
|
||||
let eRgpdConsent = $("#rgpd_consent");
|
||||
if(eRgpdConsent.length){
|
||||
if(!eRgpdConsent[0].checked){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
JS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return 'return ($("#accept").prop("checked") && isRgpdConsentOk());';
|
||||
}
|
||||
|
||||
}
|
||||
35
setup/wizardsteps/WizStepLicense2.php
Normal file
35
setup/wizardsteps/WizStepLicense2.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* License acceptation screen (when upgrading)
|
||||
*/
|
||||
class WizStepLicense2 extends WizStepLicense
|
||||
{
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepUpgradeMiscParams::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
return ['class' => WizStepUpgradeMiscParams::class, 'state' => ''];
|
||||
}
|
||||
}
|
||||
845
setup/wizardsteps/WizStepModulesChoice.php
Normal file
845
setup/wizardsteps/WizStepModulesChoice.php
Normal file
@@ -0,0 +1,845 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
use Combodo\iTop\PhpParser\Evaluation\PhpExpressionEvaluator;
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReaderException;
|
||||
|
||||
/**
|
||||
* Choice of the modules to be installed
|
||||
*/
|
||||
class WizStepModulesChoice extends WizardStep
|
||||
{
|
||||
protected static string $SEP = '_';
|
||||
protected bool $bUpgrade = false;
|
||||
protected bool $bCanMoveForward = true;
|
||||
protected ?Config $oConfig = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var iTopExtensionsMap
|
||||
*/
|
||||
protected iTopExtensionsMap $oExtensionsMap;
|
||||
|
||||
private ?array $aSteps = null;
|
||||
|
||||
protected PhpExpressionEvaluator $oPhpExpressionEvaluator;
|
||||
|
||||
/**
|
||||
* Whether we were able to load the choices from the database or not
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $bChoicesFromDatabase;
|
||||
|
||||
private array $aAnalyzeInstallationModules;
|
||||
private ?MissingDependencyException $oMissingDependencyException = null;
|
||||
|
||||
public function __construct(WizardController $oWizard, $sCurrentState)
|
||||
{
|
||||
parent::__construct($oWizard, $sCurrentState);
|
||||
$this->bChoicesFromDatabase = false;
|
||||
$this->oExtensionsMap = new iTopExtensionsMap();
|
||||
$sPreviousSourceDir = $this->oWizard->GetParameter('previous_version_dir', '');
|
||||
$sConfigPath = null;
|
||||
if (($sPreviousSourceDir !== '') && is_readable($sPreviousSourceDir.'/conf/production/config-itop.php')) {
|
||||
$sConfigPath = $sPreviousSourceDir.'/conf/production/config-itop.php';
|
||||
} elseif (is_readable(utils::GetConfigFilePath('production'))) {
|
||||
$sConfigPath = utils::GetConfigFilePath('production');
|
||||
}
|
||||
|
||||
// only called if the config file exists : we are updating a previous installation !
|
||||
// WARNING : we can't load this config directly, as it might be from another directory with a different approot_url (N°2684)
|
||||
if ($sConfigPath !== null) {
|
||||
$this->oConfig = new Config($sConfigPath);
|
||||
|
||||
$aParamValues = $oWizard->GetParamForConfigArray();
|
||||
$this->oConfig->UpdateFromParams($aParamValues);
|
||||
|
||||
$this->oExtensionsMap->LoadChoicesFromDatabase($this->oConfig);
|
||||
$this->bChoicesFromDatabase = true;
|
||||
}
|
||||
|
||||
// Sanity check (not stopper, to let developers go further...)
|
||||
try {
|
||||
$this->aAnalyzeInstallationModules = SetupUtils::AnalyzeInstallation($this->oWizard, true);
|
||||
} catch (MissingDependencyException $e) {
|
||||
$this->oMissingDependencyException = $e;
|
||||
$this->aAnalyzeInstallationModules = SetupUtils::AnalyzeInstallation($this->oWizard);
|
||||
}
|
||||
}
|
||||
|
||||
public function GetTitle(): string
|
||||
{
|
||||
$aStepInfo = $this->GetStepInfo();
|
||||
|
||||
return $aStepInfo['title'] ?? 'Modules selection';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepModulesChoice::class, WizStepDataAudit::class, WizStepSummary::class];
|
||||
}
|
||||
|
||||
public function GetAddedAndRemovedExtensions($aSelectedExtensions)
|
||||
{
|
||||
$aExtensionsAdded = [];
|
||||
$aExtensionsRemoved = [];
|
||||
$aExtensionsNotUninstallable = [];
|
||||
foreach ($this->oExtensionsMap->GetAllExtensionsWithPreviouslyInstalled() as $oExtension) {
|
||||
/* @var \iTopExtension $oExtension */
|
||||
$bSelected = in_array($oExtension->sCode, $aSelectedExtensions);
|
||||
if ($oExtension->bInstalled && !$bSelected) {
|
||||
$aExtensionsRemoved[$oExtension->sCode] = $oExtension->sLabel;
|
||||
if (!$oExtension->CanBeUninstalled()) {
|
||||
$aExtensionsNotUninstallable[$oExtension->sCode] = true;
|
||||
}
|
||||
} elseif (!$oExtension->bInstalled && $bSelected) {
|
||||
$aExtensionsAdded[$oExtension->sCode] = $oExtension->sLabel;
|
||||
}
|
||||
}
|
||||
|
||||
return [$aExtensionsAdded, $aExtensionsRemoved, $aExtensionsNotUninstallable];
|
||||
}
|
||||
|
||||
public function IsDataAuditEnabled(): bool
|
||||
{
|
||||
$sPath = APPROOT.'env-production';
|
||||
if (!is_dir($sPath)) {
|
||||
SetupLog::Info("Reinstallation of an iTop from a backup (No env-production found). Setup data audit disabled");
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
// Accumulates the selected modules:
|
||||
$index = $this->GetStepIndex();
|
||||
|
||||
// use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
|
||||
$aSelectedChoices = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
|
||||
$aSelected = utils::ReadParam('choice', []);
|
||||
$aSelectedChoices[$index] = $aSelected;
|
||||
$this->oWizard->SetParameter('selected_components', json_encode($aSelectedChoices));
|
||||
|
||||
if ($this->GetStepInfo($index) == null) {
|
||||
throw new Exception('Internal error: invalid step "'.$index.'" for the choice of modules.');
|
||||
} elseif ($bMoveForward) {
|
||||
if ($this->GetStepInfo(1 + $index) != null) {
|
||||
return ['class' => WizStepModulesChoice::class, 'state' => (1 + $index)];
|
||||
} else {
|
||||
// Exiting this step of the wizard, let's convert the selection into a list of modules
|
||||
$aModules = [];
|
||||
$aExtensions = [];
|
||||
$sDisplayChoices = '<ul>';
|
||||
for ($i = 0; $i <= $index; $i++) {
|
||||
$aStepInfo = $this->GetStepInfo($i);
|
||||
$sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules, '', '', $aExtensions);
|
||||
}
|
||||
$sDisplayChoices .= '</ul>';
|
||||
if (class_exists('CreateITILProfilesInstaller')) {
|
||||
$this->oWizard->SetParameter('old_addon', true);
|
||||
}
|
||||
|
||||
[$aExtensionsAdded, $aExtensionsRemoved, $aExtensionsNotUninstallable] = $this->GetAddedAndRemovedExtensions($aExtensions);
|
||||
$this->oWizard->SetParameter('selected_modules', json_encode(array_keys($aModules)));
|
||||
$this->oWizard->SetParameter('selected_extensions', json_encode($aExtensions));
|
||||
$this->oWizard->SetParameter('display_choices', $sDisplayChoices);
|
||||
$this->oWizard->SetParameter('extensions_added', json_encode($aExtensionsAdded));
|
||||
$this->oWizard->SetParameter('removed_extensions', json_encode($aExtensionsRemoved));
|
||||
$this->oWizard->SetParameter('extensions_not_uninstallable', json_encode(array_keys($aExtensionsNotUninstallable)));
|
||||
$sMode = $this->oWizard->GetParameter('mode', 'install');
|
||||
if ($sMode == 'install' || !$this->IsDataAuditEnabled()) {
|
||||
return ['class' => WizStepSummary::class, 'state' => ''];
|
||||
} else {
|
||||
return ['class' => WizStepDataAudit::class, 'state' => ''];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$this->DisplayStep($oPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \SetupPage $oPage
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function DisplayStep($oPage)
|
||||
{
|
||||
// Sanity check (not stopper, to let developers go further...)
|
||||
if (! is_null($this->oMissingDependencyException)) {
|
||||
$oPage->warning($this->oMissingDependencyException->getHtmlDesc(), $this->oMissingDependencyException->getMessage());
|
||||
}
|
||||
|
||||
$this->bUpgrade = ($this->oWizard->GetParameter('install_mode') != 'install');
|
||||
$aStepInfo = $this->GetStepInfo();
|
||||
$oPage->add_style("div.choice { margin: 0.5em;}");
|
||||
$oPage->add_style("div.choice a { text-decoration:none; font-weight: bold; color: #1C94C4 }");
|
||||
$oPage->add_style("div.description { margin-left: 2em; }");
|
||||
$oPage->add_style(".choice-disabled { color: #999; }");
|
||||
$oPage->add_style("input.unremovable { accent-color: orangered;}");
|
||||
|
||||
$sManualInstallError = SetupUtils::CheckManualInstallDirEmpty(
|
||||
$this->aAnalyzeInstallationModules,
|
||||
$this->oWizard->GetParameter('extensions_dir', 'extensions')
|
||||
);
|
||||
if ($sManualInstallError !== '') {
|
||||
$oPage->warning($sManualInstallError);
|
||||
}
|
||||
|
||||
$oPage->add('<div class="module-selection-banner">');
|
||||
$sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : '';
|
||||
if (!empty($sBannerPath)) {
|
||||
if (substr($sBannerPath, 0, 1) == '/') {
|
||||
// absolute path, means relative to APPROOT
|
||||
$sBannerUrl = utils::GetDefaultUrlAppRoot(true).$sBannerPath;
|
||||
} else {
|
||||
// relative path: i.e. relative to the directory containing the XML file
|
||||
$sFullPath = dirname($this->GetSourceFilePath()).'/'.$sBannerPath;
|
||||
$sRealPath = realpath($sFullPath);
|
||||
$sBannerUrl = utils::GetDefaultUrlAppRoot(true).str_replace(realpath(APPROOT), '', $sRealPath);
|
||||
}
|
||||
$oPage->add('<img src="'.$sBannerUrl.'"/>');
|
||||
}
|
||||
$sDescription = $aStepInfo['description'] ?? '';
|
||||
$oPage->add('<span>'.$sDescription.'</span>');
|
||||
$oPage->add('</div>');
|
||||
|
||||
// Build the default choices
|
||||
$aDefaults = $this->GetDefaults($aStepInfo, $this->aAnalyzeInstallationModules);
|
||||
$index = $this->GetStepIndex();
|
||||
|
||||
// retrieve the saved selection
|
||||
// use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
|
||||
$aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
|
||||
if (!isset($aParameters[$index])) {
|
||||
$aParameters[$index] = $aDefaults;
|
||||
}
|
||||
$aSelectedComponents = $aParameters[$index];
|
||||
|
||||
$oPage->add('<div class="module-selection-body">');
|
||||
$this->DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults);
|
||||
$oPage->add('</div>');
|
||||
|
||||
$oPage->add_script(
|
||||
<<<EOF
|
||||
function CheckChoice(sChoiceId)
|
||||
{
|
||||
var oElement = $('#'+sChoiceId);
|
||||
var bChecked = oElement.prop('checked');
|
||||
var sId = sChoiceId.replace('choice', '');
|
||||
if ((oElement.attr('type') == 'radio') && bChecked)
|
||||
{
|
||||
// Only the radio that is clicked is notified, let's warn the other radio buttons
|
||||
sName = oElement.attr('name');
|
||||
$('input[name="'+sName+'"]').each(function() {
|
||||
var sRadioId = $(this).attr('id');
|
||||
if ((sRadioId != sChoiceId) && (sRadioId != undefined))
|
||||
{
|
||||
CheckChoice(sRadioId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#sub_choices'+sId).each(function() {
|
||||
if (!bChecked)
|
||||
{
|
||||
$(this).addClass('choice-disabled');
|
||||
}
|
||||
else
|
||||
{
|
||||
$(this).removeClass('choice-disabled');
|
||||
}
|
||||
|
||||
$('input', this).each(function() {
|
||||
if (bChecked)
|
||||
{
|
||||
if ($(this).attr('data-disabled') != 'disabled')
|
||||
{
|
||||
// Only non-mandatory fields can be enabled
|
||||
$(this).prop('disabled', false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$(this).prop('disabled', true);
|
||||
$(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
EOF
|
||||
);
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$('.wiz-choice').on('change', function() { CheckChoice($(this).attr('id')); } );
|
||||
$('.wiz-choice').trigger('change');
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
protected function GetDefaults($aInfo, $aModules, $sParentId = '')
|
||||
{
|
||||
$aDefaults = [];
|
||||
if (!$this->bChoicesFromDatabase) {
|
||||
$this->GuessDefaultsFromModules($aInfo, $aDefaults, $aModules, $sParentId);
|
||||
} else {
|
||||
$this->GetDefaultsFromDatabase($aInfo, $aDefaults, $sParentId);
|
||||
}
|
||||
return $aDefaults;
|
||||
}
|
||||
|
||||
protected function GetDefaultsFromDatabase($aInfo, &$aDefaults, $sParentId)
|
||||
{
|
||||
$aOptions = isset($aInfo['options']) ? $aInfo['options'] : [];
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
if ($this->bUpgrade) {
|
||||
if ($this->oExtensionsMap->IsMarkedAsChosen($aChoice['extension_code'])) {
|
||||
$aDefaults[$sChoiceId] = $sChoiceId;
|
||||
}
|
||||
} elseif (isset($aChoice['default']) && $aChoice['default']) {
|
||||
$aDefaults[$sChoiceId] = $sChoiceId;
|
||||
}
|
||||
// Recurse for sub_options (if any)
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
$this->GetDefaultsFromDatabase($aChoice['sub_options'], $aDefaults, $sChoiceId);
|
||||
}
|
||||
}
|
||||
|
||||
$aAlternatives = $aInfo['alternatives'] ?? [];
|
||||
$sChoiceName = null;
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
if ($sChoiceName == null) {
|
||||
$sChoiceName = $sChoiceId; // All radios share the same name
|
||||
}
|
||||
if ($this->bUpgrade) {
|
||||
if ($this->oExtensionsMap->IsMarkedAsChosen($aChoice['extension_code'])) {
|
||||
$aDefaults[$sChoiceName] = $sChoiceId;
|
||||
}
|
||||
} elseif (isset($aChoice['default']) && $aChoice['default']) {
|
||||
$aDefaults[$sChoiceName] = $sChoiceId;
|
||||
}
|
||||
// Recurse for sub_options (if any)
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
$this->GetDefaultsFromDatabase($aChoice['sub_options'], $aDefaults, $sChoiceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to guess the user choices based on the current list of installed modules...
|
||||
* @param array $aInfo
|
||||
* @param array $aDefaults
|
||||
* @param array $aModules
|
||||
* @param string $sParentId
|
||||
* @return array
|
||||
*/
|
||||
protected function GuessDefaultsFromModules($aInfo, &$aDefaults, $aModules, $sParentId = '')
|
||||
{
|
||||
$aRetScore = [];
|
||||
$aScores = [];
|
||||
|
||||
$aOptions = isset($aInfo['options']) ? $aInfo['options'] : [];
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$aScores[$sChoiceId] = [];
|
||||
if (!$this->bUpgrade && isset($aChoice['default']) && $aChoice['default']) {
|
||||
$aDefaults[$sChoiceId] = $sChoiceId;
|
||||
}
|
||||
if ($this->bUpgrade) {
|
||||
// In upgrade mode, the defaults are the installed modules
|
||||
foreach ($aChoice['modules'] as $sModuleId) {
|
||||
if ($aModules[$sModuleId]['installed_version'] != '') {
|
||||
// A module corresponding to this choice is installed
|
||||
$aScores[$sChoiceId][$sModuleId] = true;
|
||||
}
|
||||
}
|
||||
// Used for migration from 1.3.x or before
|
||||
// Accept that the new version can have one new module than the previous version
|
||||
// The option is still selected
|
||||
$iSelected = count($aScores[$sChoiceId]);
|
||||
$iNeeded = count($aChoice['modules']);
|
||||
if (($iSelected > 0) && (($iNeeded - $iSelected) < 2)) {
|
||||
// All the modules are installed, this choice is selected
|
||||
$aDefaults[$sChoiceId] = $sChoiceId;
|
||||
}
|
||||
$aRetScore = array_merge($aRetScore, $aScores[$sChoiceId]);
|
||||
}
|
||||
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
$aScores[$sChoiceId] = array_merge($aScores[$sChoiceId], $this->GuessDefaultsFromModules($aChoice['sub_options'], $aDefaults, $sChoiceId));
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
$aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : [];
|
||||
$sChoiceName = null;
|
||||
$sChoiceIdNone = null;
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$aScores[$sChoiceId] = [];
|
||||
if ($sChoiceName == null) {
|
||||
$sChoiceName = $sChoiceId;
|
||||
}
|
||||
if (!$this->bUpgrade && isset($aChoice['default']) && $aChoice['default']) {
|
||||
$aDefaults[$sChoiceName] = $sChoiceId;
|
||||
}
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
// By default (i.e. install-mode), sub options can only be checked if the parent option is checked by default
|
||||
if ($this->bUpgrade || (isset($aChoice['default']) && $aChoice['default'])) {
|
||||
$aScores[$sChoiceId] = $this->GuessDefaultsFromModules($aChoice['sub_options'], $aDefaults, $aModules, $sChoiceId);
|
||||
}
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
$iMaxScore = 0;
|
||||
if ($this->bUpgrade && (count($aAlternatives) > 0)) {
|
||||
// The installed choices have precedence over the 'default' choices
|
||||
// In case several choices share the same base modules, let's weight the alternative choices
|
||||
// based on their number of installed modules
|
||||
$sChoiceName = null;
|
||||
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
if ($sChoiceName == null) {
|
||||
$sChoiceName = $sChoiceId;
|
||||
}
|
||||
if (array_key_exists('modules', $aChoice)) {
|
||||
foreach ($aChoice['modules'] as $sModuleId) {
|
||||
if ($aModules[$sModuleId]['installed_version'] != '') {
|
||||
// A module corresponding to this choice is installed, increase the score of this choice
|
||||
if (!isset($aScores[$sChoiceId])) {
|
||||
$aScores[$sChoiceId] = [];
|
||||
}
|
||||
$aScores[$sChoiceId][$sModuleId] = true;
|
||||
$iMaxScore = max($iMaxScore, count($aScores[$sChoiceId]));
|
||||
}
|
||||
}
|
||||
//if (count($aScores[$sChoiceId]) == count($aChoice['modules']))
|
||||
//{
|
||||
// $iScore += 100; // Bonus for the parent when a choice is complete
|
||||
//}
|
||||
$aRetScore = array_merge($aRetScore, $aScores[$sChoiceId]);
|
||||
}
|
||||
$iMaxScore = max($iMaxScore, isset($aScores[$sChoiceId]) ? count($aScores[$sChoiceId]) : 0);
|
||||
}
|
||||
}
|
||||
if ($iMaxScore > 0) {
|
||||
$aNumericScores = [];
|
||||
foreach ($aScores as $sChoiceId => $aModules) {
|
||||
$aNumericScores[$sChoiceId] = count($aModules);
|
||||
}
|
||||
// The choice with the bigger score wins !
|
||||
asort($aNumericScores, SORT_NUMERIC);
|
||||
$aKeys = array_keys($aNumericScores);
|
||||
$sBetterChoiceId = array_pop($aKeys);
|
||||
$aDefaults[$sChoiceName] = $sBetterChoiceId;
|
||||
}
|
||||
// echo "Scores: <pre>".print_r($aScores, true)."</pre><br/>";
|
||||
// echo "Defaults: <pre>".print_r($aDefaults, true)."</pre><br/>";
|
||||
return $aRetScore;
|
||||
}
|
||||
|
||||
private function GetPhpExpressionEvaluator(): PhpExpressionEvaluator
|
||||
{
|
||||
if (!isset($this->oPhpExpressionEvaluator)) {
|
||||
$this->oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
|
||||
}
|
||||
|
||||
return $this->oPhpExpressionEvaluator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the list of selected "choices" into a list of "modules": take into account the selected and the mandatory modules
|
||||
*
|
||||
* @param array $aInfo Info about the "choice" array('options' => array(...), 'alternatives' => array(...))
|
||||
* @param array $aSelectedChoices List of selected choices array('name' => 'selected_value_id')
|
||||
* @param array $aModules Return parameter: List of selected modules array('module_id' => true)
|
||||
* @param string $sParentId Used for recursion
|
||||
*
|
||||
* @return string A text representation of what will be installed
|
||||
*/
|
||||
protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '', $sDisplayChoices = '', &$aSelectedExtensions = null)
|
||||
{
|
||||
if ($sParentId == '') {
|
||||
// Check once (before recursing) that the hidden modules are selected
|
||||
foreach ($this->aAnalyzeInstallationModules as $sModuleId => $aModule) {
|
||||
if (($sModuleId != ROOT_MODULE) && !isset($aModules[$sModuleId])) {
|
||||
if (($aModule['category'] == 'authentication') || (!$aModule['visible'] && !isset($aModule['auto_select']))) {
|
||||
$aModules[$sModuleId] = true;
|
||||
$sDisplayChoices .= '<li><i>'.$aModule['label'].' (hidden)</i></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$aOptions = isset($aInfo['options']) ? $aInfo['options'] : [];
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$aModuleInfo = [];
|
||||
// Get the extension corresponding to the choice
|
||||
foreach ($this->oExtensionsMap->GetAllExtensions() as $sExtensionVersion => $oExtension) {
|
||||
if (utils::StartsWith($sExtensionVersion, $aChoice['extension_code'].'/')) {
|
||||
$aModuleInfo = $oExtension->aModuleInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
|
||||
(isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId))) {
|
||||
$sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
|
||||
if (isset($aChoice['modules'])) {
|
||||
foreach ($aChoice['modules'] as $sModuleId) {
|
||||
$bSelected = true;
|
||||
if (isset($aModuleInfo[$sModuleId])) {
|
||||
// Test if module has 'auto_select'
|
||||
$aInfo = $aModuleInfo[$sModuleId];
|
||||
if (isset($aInfo['auto_select'])) {
|
||||
// Check the module selection
|
||||
try {
|
||||
SetupInfo::SetSelectedModules($aModules);
|
||||
$bSelected = $this->GetPhpExpressionEvaluator()->ParseAndEvaluateBooleanExpression($aInfo['auto_select']);
|
||||
} catch (ModuleFileReaderException $e) {
|
||||
//logged already
|
||||
$bSelected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($bSelected) {
|
||||
$aModules[$sModuleId] = true; // store the Id of the selected module
|
||||
SetupInfo::SetSelectedModules($aModules);
|
||||
}
|
||||
}
|
||||
}
|
||||
$sChoiceType = isset($aChoice['type']) ? $aChoice['type'] : 'wizard_option';
|
||||
if ($aSelectedExtensions !== null) {
|
||||
$aSelectedExtensions[] = $aChoice['extension_code'];
|
||||
}
|
||||
// Recurse only for selected choices
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
$sDisplayChoices .= '<ul>';
|
||||
$sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices, $aSelectedExtensions);
|
||||
$sDisplayChoices .= '</ul>';
|
||||
}
|
||||
$sDisplayChoices .= '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
$aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : [];
|
||||
$sChoiceName = null;
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
if ($sChoiceName == null) {
|
||||
$sChoiceName = $sChoiceId;
|
||||
}
|
||||
if ((isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
|
||||
(isset($aSelectedChoices[$sChoiceName]) && ($aSelectedChoices[$sChoiceName] == $sChoiceId))) {
|
||||
$sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
|
||||
if ($aSelectedExtensions !== null) {
|
||||
$aSelectedExtensions[] = $aChoice['extension_code'];
|
||||
}
|
||||
if (isset($aChoice['modules'])) {
|
||||
foreach ($aChoice['modules'] as $sModuleId) {
|
||||
$aModules[$sModuleId] = true; // store the Id of the selected module
|
||||
}
|
||||
}
|
||||
// Recurse only for selected choices
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
$sDisplayChoices .= '<ul>';
|
||||
$sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices, $aSelectedExtensions);
|
||||
$sDisplayChoices .= '</ul>';
|
||||
}
|
||||
$sDisplayChoices .= '</li>';
|
||||
}
|
||||
}
|
||||
if ($sParentId == '') {
|
||||
// Last pass (after all the user's choices are turned into "selected" modules):
|
||||
// Process 'auto_select' modules for modules that are not already selected
|
||||
do {
|
||||
// Loop while new modules are added...
|
||||
$bModuleAdded = false;
|
||||
foreach ($this->aAnalyzeInstallationModules as $sModuleId => $aModule) {
|
||||
if (($sModuleId != ROOT_MODULE) && !array_key_exists($sModuleId, $aModules) && isset($aModule['auto_select'])) {
|
||||
try {
|
||||
SetupInfo::SetSelectedModules($aModules);
|
||||
$bSelected = $this->GetPhpExpressionEvaluator()->ParseAndEvaluateBooleanExpression($aModule['auto_select']);
|
||||
if ($bSelected) {
|
||||
$aModules[$sModuleId] = true; // store the Id of the selected module
|
||||
$sDisplayChoices .= '<li>'.$aModule['label'].' (auto_select)</li>';
|
||||
$bModuleAdded = true;
|
||||
}
|
||||
} catch (ModuleFileReaderException $e) {
|
||||
//logged already
|
||||
$sDisplayChoices .= '<li><b>Warning: auto_select failed with exception ('.$e->getMessage().') for module "'.$sModuleId.'"</b></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
} while ($bModuleAdded);
|
||||
}
|
||||
|
||||
return $sDisplayChoices;
|
||||
}
|
||||
|
||||
protected function GetStepIndex()
|
||||
{
|
||||
switch ($this->sCurrentState) {
|
||||
case 'start_install':
|
||||
case 'start_upgrade':
|
||||
$index = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
$index = (int)$this->sCurrentState;
|
||||
}
|
||||
return $index;
|
||||
}
|
||||
|
||||
protected function GetStepInfo($idx = null)
|
||||
{
|
||||
$index = $idx ?? $this->GetStepIndex();
|
||||
|
||||
if (is_null($this->aSteps)) {
|
||||
$this->oWizard->SetParameter('additional_extensions_modules', json_encode([])); // Default value, no additional extensions
|
||||
|
||||
if (@file_exists($this->GetSourceFilePath())) {
|
||||
// Found an "installation.xml" file, let's use this definition for the wizard
|
||||
$aParams = new XMLParameters($this->GetSourceFilePath());
|
||||
$this->aSteps = $aParams->Get('steps', []);
|
||||
|
||||
if ($index + 1 >= count($this->aSteps)) {
|
||||
//make sure we also cache next step as well
|
||||
$aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo();
|
||||
|
||||
// Display this step of the wizard only if there is something to display
|
||||
if (count($aOptions) > 0) {
|
||||
$this->aSteps[] = [
|
||||
'title' => 'Extensions',
|
||||
'description' => '<h2>Select additional extensions to install. You can launch the installation again to install new extensions or remove installed ones.</h2>',
|
||||
'banner' => '/images/icons/icons8-puzzle.svg',
|
||||
'options' => $aOptions,
|
||||
];
|
||||
$this->oWizard->SetParameter('additional_extensions_modules', json_encode($aOptions));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$aOptions = $this->oExtensionsMap->GetAllExtensionsOptionInfo();
|
||||
|
||||
// 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 = [
|
||||
[
|
||||
'title' => 'Modules Selection',
|
||||
'description' => '<h2>Select the modules to install. You can launch the installation again to install new modules, but you cannot remove already installed modules.</h2>',
|
||||
'banner' => '/images/icons/icons8-apps-tab.svg',
|
||||
'options' => $aOptions,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->aSteps[$index] ?? null;
|
||||
}
|
||||
|
||||
public function ComputeChoiceFlags(array $aChoice, string $sChoiceId, array $aSelectedComponents, bool $bAllDisabled, bool $bDisableUninstallCheck, bool $bUpgradeMode)
|
||||
{
|
||||
$oITopExtension = $this->oExtensionsMap->GetFromExtensionCode($aChoice['extension_code']);
|
||||
$bCanBeUninstalled = isset($aChoice['uninstallable']) ? $aChoice['uninstallable'] === true || $aChoice['uninstallable'] === 'yes' : $oITopExtension->CanBeUninstalled();
|
||||
$bSelected = isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId);
|
||||
$bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || $bUpgradeMode && $oITopExtension->bInstalled && !$bCanBeUninstalled && !$bDisableUninstallCheck;
|
||||
|
||||
$bMissingFromDisk = isset($aChoice['missing']) && $aChoice['missing'] === true;
|
||||
$bInstalled = $bMissingFromDisk || $oITopExtension->bInstalled;
|
||||
$bDisabled = $bMandatory || $bAllDisabled || $bMissingFromDisk;
|
||||
$bChecked = $bMandatory || $bSelected;
|
||||
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
$aOptions = $aChoice['sub_options']['options'] ?? [];
|
||||
foreach ($aOptions as $index => $aSubChoice) {
|
||||
$sSubChoiceId = $sChoiceId.self::$SEP.$index;
|
||||
$aSubFlags = $this->ComputeChoiceFlags($aSubChoice, $sSubChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck, $bUpgradeMode);
|
||||
if ($aSubFlags['checked']) {
|
||||
$bChecked = true;
|
||||
if ($aSubFlags['disabled']) {
|
||||
//If some sub options are enabled and cannot be disabled, this choice should also cannot be disabled since it would disable all its sub options
|
||||
$bDisabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'uninstallable' => $bCanBeUninstalled,
|
||||
'missing' => $bMissingFromDisk,
|
||||
'installed' => $bInstalled,
|
||||
'disabled' => $bDisabled,
|
||||
'checked' => $bChecked,
|
||||
];
|
||||
}
|
||||
|
||||
protected function DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults, $sParentId = '', $bAllDisabled = false)
|
||||
{
|
||||
$aOptions = $aStepInfo['options'] ?? [];
|
||||
$aAlternatives = $aStepInfo['alternatives'] ?? [];
|
||||
|
||||
$bDisableUninstallCheck = (bool)$this->oWizard->GetParameter('force-uninstall', false);
|
||||
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$sDataId = 'data-id="'.utils::EscapeHtml($aChoice['extension_code']).'"';
|
||||
$sId = utils::EscapeHtml($aChoice['extension_code']);
|
||||
$aFlags = $this->ComputeChoiceFlags($aChoice, $sChoiceId, $aSelectedComponents, $bAllDisabled, $bDisableUninstallCheck, $this->bUpgrade);
|
||||
|
||||
$sTooltip = '';
|
||||
$sUnremovable = '';
|
||||
if ($aFlags['missing']) {
|
||||
$sTooltip .= '<div class="setup-extension-tag removed">source removed</div>';
|
||||
}
|
||||
if ($aFlags['installed']) {
|
||||
$sTooltip .= '<div class="setup-extension-tag checked installed">installed</div>';
|
||||
$sTooltip .= '<div class="setup-extension-tag unchecked tobeuninstalled">to be uninstalled</div>';
|
||||
} else {
|
||||
$sTooltip .= '<div class="setup-extension-tag checked tobeinstalled">to be installed</div>';
|
||||
$sTooltip .= '<div class="setup-extension-tag unchecked notinstalled">not installed</div>';
|
||||
}
|
||||
if (!$aFlags['uninstallable']) {
|
||||
$sTooltip .= '<div class="setup-extension-tag notuninstallable">cannot be uninstalled</div>';
|
||||
}
|
||||
if ($aFlags['disabled'] && !$aFlags['checked'] && !$aFlags['uninstallable'] && !$bDisableUninstallCheck) {
|
||||
$this->bCanMoveForward = false;//Disable "Next"
|
||||
}
|
||||
$sChecked = $aFlags['checked'] ? ' checked ' : '';
|
||||
$sDisabled = $aFlags['disabled'] ? ' disabled data-disabled="disabled" ' : '';
|
||||
$sMissingModule = $aFlags['missing'] ? 'setup-extension--missing' : '';
|
||||
|
||||
$sHiddenInput = $aFlags['disabled'] && $aFlags['checked'] ? '<input type="hidden" name="choice['.$sChoiceId.']" value="'.$sChoiceId.'"/>' : '';
|
||||
$oPage->add('<div class="choice '.$sMissingModule.'" '.$sDataId.'><input class="wiz-choice '.$sUnremovable.'" id="'.$sId.'" name="choice['.$sChoiceId.']" type="checkbox" value="'.$sChoiceId.'" '.$sDisabled.$sChecked.'/>'.$sHiddenInput.' ');
|
||||
$this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId, $aFlags['disabled'], $sTooltip);
|
||||
$oPage->add('</div>');
|
||||
}
|
||||
$sChoiceName = null;
|
||||
$sDisabled = '';
|
||||
$bDisabled = false;
|
||||
$sChoiceIdNone = null;
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
if ($sChoiceName == null) {
|
||||
$sChoiceName = $sChoiceId; // All radios share the same name
|
||||
}
|
||||
$bIsDefault = array_key_exists($sChoiceName, $aDefaults) && ($aDefaults[$sChoiceName] == $sChoiceId);
|
||||
$bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
|
||||
if ($bMandatory || $bAllDisabled) {
|
||||
// One choice is mandatory, all alternatives are disabled
|
||||
$sDisabled = ' disabled data-disabled="disabled"';
|
||||
$bDisabled = true;
|
||||
}
|
||||
if ((!isset($aChoice['sub_options']) || (count($aChoice['sub_options']) == 0)) && (!isset($aChoice['modules']) || (count($aChoice['modules']) == 0))) {
|
||||
$sChoiceIdNone = $sChoiceId; // the "None" / empty choice
|
||||
}
|
||||
}
|
||||
|
||||
if (!array_key_exists($sChoiceName, $aDefaults) || ($aDefaults[$sChoiceName] == $sChoiceIdNone)) {
|
||||
// The "none" choice does not disable the selection !!
|
||||
$sDisabled = '';
|
||||
$bDisabled = false;
|
||||
}
|
||||
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sAttributes = '';
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$sDataId = 'data-id="'.utils::EscapeHtml($aChoice['extension_code']).'"';
|
||||
$sId = utils::EscapeHtml($aChoice['extension_code']);
|
||||
if ($sChoiceName == null) {
|
||||
$sChoiceName = $sChoiceId; // All radios share the same name
|
||||
}
|
||||
$bIsDefault = array_key_exists($sChoiceName, $aDefaults) && ($aDefaults[$sChoiceName] == $sChoiceId);
|
||||
$bSelected = isset($aSelectedComponents[$sChoiceName]) && ($aSelectedComponents[$sChoiceName] == $sChoiceId);
|
||||
if (!isset($aSelectedComponents[$sChoiceName]) && ($sChoiceIdNone != null)) {
|
||||
// No choice selected, select the "None" option
|
||||
$bSelected = ($sChoiceId == $sChoiceIdNone);
|
||||
}
|
||||
$bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
|
||||
|
||||
if ($bSelected) {
|
||||
$sAttributes = ' checked ';
|
||||
}
|
||||
$sHidden = '';
|
||||
if ($bMandatory && $bDisabled) {
|
||||
$sAttributes = ' checked ';
|
||||
$sHidden = '<input type="hidden" name="choice['.$sChoiceName.']" value="'.$sChoiceId.'"/>';
|
||||
}
|
||||
$oPage->add('<div class="choice" '.$sDataId.'><input class="wiz-choice" id="'.$sId.'" name="choice['.$sChoiceName.']" type="radio"'.$sAttributes.' value="'.$sChoiceId.'"'.$sDisabled.'/>'.$sHidden.' ');
|
||||
$this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId, $bDisabled && !$bSelected);
|
||||
$oPage->add('</div>');
|
||||
}
|
||||
}
|
||||
|
||||
protected function DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId, $bDisabled = false, $sTooltip = '')
|
||||
{
|
||||
$sMoreInfo = (isset($aChoice['more_info']) && ($aChoice['more_info'] != '')) ? '<a class="setup--wizard-choice--more-info" target="_blank" href="'.$aChoice['more_info'].'">More information</a>' : '';
|
||||
$sSourceLabel = $aChoice['source_label'] ?? '';
|
||||
$sId = utils::EscapeHtml($aChoice['extension_code']);
|
||||
|
||||
$oPage->add('<label class="setup--wizard-choice--label" for="'.$sId.'">'.$sSourceLabel.'<b>'.utils::EscapeHtml($aChoice['title']).'</b>'.' '.$sTooltip.'</label> '.$sMoreInfo.'');
|
||||
$sDescription = isset($aChoice['description']) ? utils::EscapeHtml($aChoice['description']) : '';
|
||||
$oPage->add('<div class="setup--wizard-choice--description description">'.$sDescription.'<span id="sub_choices'.$sId.'">');
|
||||
if (isset($aChoice['sub_options'])) {
|
||||
$this->DisplayOptions($oPage, $aChoice['sub_options'], $aSelectedComponents, $aDefaults, $sChoiceId, $bDisabled);
|
||||
}
|
||||
$oPage->add('</span></div>');
|
||||
}
|
||||
|
||||
protected function GetSourceFilePath()
|
||||
{
|
||||
$sSourceDir = $this->oWizard->GetParameter('source_dir');
|
||||
return $sSourceDir.'/installation.xml';
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
|
||||
return $this->bCanMoveForward ? 'return true;' : 'return false;';
|
||||
}
|
||||
|
||||
public function GetNextButtonLabel()
|
||||
{
|
||||
if (!$this->bCanMoveForward) {
|
||||
return 'Non-uninstallable extension missing';
|
||||
}
|
||||
|
||||
if ($this->GetStepInfo(1 + $this->GetStepIndex()) === null && $this->IsDataAuditEnabled()) {
|
||||
return 'Check compatibility';
|
||||
}
|
||||
|
||||
return 'Next';
|
||||
}
|
||||
|
||||
}
|
||||
263
setup/wizardsteps/WizStepSummary.php
Normal file
263
setup/wizardsteps/WizStepSummary.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Summary of the installation tasks
|
||||
*/
|
||||
class WizStepSummary extends AbstractWizStepInstall
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
$sMode = $this->oWizard->GetParameter('mode', 'install');
|
||||
if ($sMode == 'install') {
|
||||
return 'Ready to install';
|
||||
|
||||
} else {
|
||||
return 'Ready to upgrade';
|
||||
}
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepInstall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label for the " Next >> " button
|
||||
* @return string The label for the button
|
||||
*/
|
||||
public function GetNextButtonLabel()
|
||||
{
|
||||
return 'Install';
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
if ($this->CheckDependencies()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$this->oWizard->SaveParameter('db_backup', false);
|
||||
$this->oWizard->SaveParameter('db_backup_path', '');
|
||||
return ['class' => WizStepInstall::class, 'state' => ''];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
|
||||
$aInstallParams = $this->BuildConfig();
|
||||
|
||||
$sMode = $aInstallParams['mode'];
|
||||
|
||||
$sDestination = ITOP_APPLICATION.(($sMode == 'install') ? ' version '.ITOP_VERSION.' is about to be installed ' : ' is about to be upgraded ');
|
||||
$sDBDescription = ' <b>existing</b> database <b>'.$aInstallParams['database']['name'].'</b>';
|
||||
if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes')) {
|
||||
$sDBDescription = ' <b>new</b> database <b>'.$aInstallParams['database']['name'].'</b>';
|
||||
}
|
||||
$sDestination .= 'into the '.$sDBDescription.' on the server <b>'.$aInstallParams['database']['server'].'</b>.';
|
||||
$oPage->add('<h2>'.$sDestination.'</h2>');
|
||||
|
||||
$oPage->add('<fieldset id="summary"><legend>Installation Parameters</legend>');
|
||||
$oPage->add('<div id="params_summary">');
|
||||
|
||||
$oPage->add('<div class="closed"><span class="title ibo-setup-summary-title">Extensions to be installed</span>');
|
||||
$aExtensionsAdded = json_decode($this->oWizard->GetParameter('extensions_added'), true);
|
||||
|
||||
if (count($aExtensionsAdded) > 0) {
|
||||
$sExtensionsAdded = '<ul>';
|
||||
foreach ($aExtensionsAdded as $sExtensionCode => $sLabel) {
|
||||
$sExtensionsAdded .= '<li>'.$sLabel.'</li>';
|
||||
}
|
||||
$sExtensionsAdded .= '</ul>';
|
||||
} else {
|
||||
$sExtensionsAdded = '<ul><li>No extension added.</li></ul>';
|
||||
}
|
||||
$oPage->add($sExtensionsAdded);
|
||||
$oPage->add('</div>');
|
||||
$oPage->add('<div class="closed"><span class="title ibo-setup-summary-title">Extensions to be uninstalled</span>');
|
||||
|
||||
$aExtensionsRemoved = json_decode($this->oWizard->GetParameter('removed_extensions'), true) ?? [];
|
||||
$aExtensionsNotUninstallable = json_decode($this->oWizard->GetParameter('extensions_not_uninstallable'));
|
||||
if (count($aExtensionsRemoved) > 0) {
|
||||
$sExtensionsRemoved = '<ul>';
|
||||
foreach ($aExtensionsRemoved as $sExtensionCode => $sLabel) {
|
||||
if (in_array($sExtensionCode, $aExtensionsNotUninstallable)) {
|
||||
$sExtensionsRemoved .= '<li>'.$sLabel.' (forced uninstallation)</li>';
|
||||
} else {
|
||||
$sExtensionsRemoved .= '<li>'.$sLabel.'</li>';
|
||||
}
|
||||
}
|
||||
$sExtensionsRemoved .= '</ul>';
|
||||
} else {
|
||||
$sExtensionsRemoved = '<ul><li>No extension removed.</li></ul>';
|
||||
}
|
||||
$oPage->add($sExtensionsRemoved);
|
||||
$oPage->add('</div>');
|
||||
|
||||
$oPage->add('<div class="closed"><span class="title ibo-setup-summary-title">Database Parameters</span><ul>');
|
||||
$oPage->add('<li>Server Name: '.$aInstallParams['database']['server'].'</li>');
|
||||
$oPage->add('<li>DB User Name: '.$aInstallParams['database']['user'].'</li>');
|
||||
$oPage->add('<li>DB user password: ***</li>');
|
||||
if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes')) {
|
||||
$oPage->add('<li>Database Name: '.$aInstallParams['database']['name'].' (will be created)</li>');
|
||||
} else {
|
||||
$oPage->add('<li>Database Name: '.$aInstallParams['database']['name'].'</li>');
|
||||
}
|
||||
if ($aInstallParams['database']['prefix'] != '') {
|
||||
$oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: '.$aInstallParams['database']['prefix'].'</li>');
|
||||
} else {
|
||||
$oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: none</li>');
|
||||
}
|
||||
$oPage->add('</ul></div>');
|
||||
|
||||
$oPage->add('<div class="closed"><span class="title ibo-setup-summary-title">Data Model Configuration</span>');
|
||||
$oPage->add($this->oWizard->GetParameter('display_choices'));
|
||||
$oPage->add('</div>');
|
||||
|
||||
$oPage->add('<div class="closed"><span class="title ibo-setup-summary-title">Other Parameters</span><ul>');
|
||||
if ($sMode == 'install') {
|
||||
$oPage->add('<li>Default language: '.$aInstallParams['language'].'</li>');
|
||||
}
|
||||
|
||||
$oPage->add('<li>URL to access the application: '.$aInstallParams['url'].'</li>');
|
||||
$oPage->add('<li>Graphviz\' dot path: '.$aInstallParams['graphviz_path'].'</li>');
|
||||
if ($aInstallParams['sample_data'] == 'yes') {
|
||||
$oPage->add('<li>Sample data will be loaded into the database.</li>');
|
||||
}
|
||||
if ($aInstallParams['old_addon']) {
|
||||
$oPage->add('<li>Compatibility mode: Using the version 1.2 of the UserRightsProfiles add-on.</li>');
|
||||
}
|
||||
$oPage->add('</ul></div>');
|
||||
|
||||
if ($sMode == 'install') {
|
||||
$oPage->add('<div class="closed"><span class="title ibo-setup-summary-title">Administrator Account</span><ul>');
|
||||
$oPage->add('<li>Login: '.$aInstallParams['admin_account']['user'].'</li>');
|
||||
$oPage->add('<li>Password: '.$aInstallParams['admin_account']['pwd'].'</li>');
|
||||
$oPage->add('<li>Language: '.$aInstallParams['admin_account']['language'].'</li>');
|
||||
$oPage->add('</ul></div>');
|
||||
}
|
||||
|
||||
$aMiscOptions = $aInstallParams['options'];
|
||||
if (count($aMiscOptions) > 0) {
|
||||
$oPage->add('<div class="closed"><span class="title">Miscellaneous Options</span><ul>');
|
||||
foreach ($aMiscOptions as $sKey => $sValue) {
|
||||
$oPage->add('<li>'.$sKey.': '.$sValue.'</li>');
|
||||
}
|
||||
$oPage->add('</ul></div>');
|
||||
|
||||
}
|
||||
|
||||
if (isset($aMiscOptions['generate_config'])) {
|
||||
$oDoc = new DOMDocument('1.0', 'UTF-8');
|
||||
$oDoc->preserveWhiteSpace = false;
|
||||
$oDoc->formatOutput = true;
|
||||
$oParams = new PHPParameters();
|
||||
$oParams->LoadFromHash($aInstallParams);
|
||||
$oParams->ToXML($oDoc, null, 'installation');
|
||||
$sXML = $oDoc->saveXML();
|
||||
$oPage->add('<div class="closed"><span class="title">XML Config file</span><ul><pre>');
|
||||
$oPage->add(utils::EscapeHtml($sXML));
|
||||
$oPage->add('</pre></ul></div>');
|
||||
}
|
||||
|
||||
$oPage->add('</div>'); // params_summary
|
||||
$oPage->add('</fieldset>');
|
||||
|
||||
if (!$this->CheckDependencies()) {
|
||||
$oPage->error($this->sDependencyIssue);
|
||||
}
|
||||
|
||||
$bDBBackup = $this->oWizard->GetParameter('db_backup', false);
|
||||
$sDBBackupPath = $this->oWizard->GetParameter('db_backup_path', '');
|
||||
$sMySQLBinDir = $this->oWizard->GetParameter('mysql_bindir', null);
|
||||
if ($sMode != 'install') {
|
||||
$sDBBackupPath = utils::GetDataPath().'backups/manual/setup-'.date('Y-m-d_H_i');
|
||||
$aPreviousInstance = SetupUtils::GetPreviousInstance(APPROOT);
|
||||
if ($aPreviousInstance['found']) {
|
||||
$sMySQLBinDir = $aPreviousInstance['mysql_bindir'];
|
||||
$this->oWizard->SaveParameter('mysql_bindir', $aPreviousInstance['mysql_bindir']);
|
||||
}
|
||||
}
|
||||
|
||||
$aBackupChecks = SetupUtils::CheckBackupPrerequisites($sDBBackupPath, $sMySQLBinDir);
|
||||
$bCanBackup = true;
|
||||
$sMySQLDumpMessage = '';
|
||||
foreach ($aBackupChecks as $oCheck) {
|
||||
switch ($oCheck->iSeverity) {
|
||||
case CheckResult::ERROR:
|
||||
$bCanBackup = false;
|
||||
$sMySQLDumpMessage .= '<div class="message message-error"><span class="message-title">Error:</span>'.$oCheck->sLabel.'</div>';
|
||||
break;
|
||||
case CheckResult::TRACE:
|
||||
SetupLog::Ok($oCheck->sLabel);
|
||||
break;
|
||||
default:
|
||||
$sMySQLDumpMessage .= '<div class="message message-valid"><span class="message-title">Success:</span>'.$oCheck->sLabel.'</div>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$sChecked = ($bCanBackup && $bDBBackup) ? ' checked ' : '';
|
||||
$sDisabled = $bCanBackup ? '' : ' disabled ';
|
||||
$oPage->add('<br/>');
|
||||
$oPage->add('<input id="db_backup" type="checkbox" name="db_backup" '.$sChecked.$sDisabled.' value="1"/><label for="db_backup">Backup the '.ITOP_APPLICATION.' database before upgrading</label>');
|
||||
$oPage->add('<div class="setup-backup--input--container">Save the backup to:<input id="db_backup_path" class="ibo-input" type="text" name="db_backup_path" '.$sDisabled.'value="'.utils::EscapeHtml($sDBBackupPath).'"/></div>');
|
||||
$fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
|
||||
$sMessage = '';
|
||||
if ($fFreeSpace !== false) {
|
||||
$sMessage .= SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath);
|
||||
}
|
||||
$oPage->add($sMySQLDumpMessage.'<span id="backup_info" style="font-size:small;color:#696969;">'.$sMessage.'</span>');
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$("#db_backup_path").on('change keyup', function() { WizardAsyncAction('check_backup', { db_backup_path: $('#db_backup_path').val() }); });
|
||||
$("#params_summary div").addClass('closed');
|
||||
$("#params_summary .title").on('click', function() { $(this).parent().toggleClass('closed'); } );
|
||||
JS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return 'return true;';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveBackward()
|
||||
{
|
||||
return 'return true;';
|
||||
}
|
||||
|
||||
}
|
||||
159
setup/wizardsteps/WizStepUpgradeMiscParams.php
Normal file
159
setup/wizardsteps/WizStepUpgradeMiscParams.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Miscellaneous Parameters (URL...) in case of upgrade
|
||||
*/
|
||||
class WizStepUpgradeMiscParams extends AbstractWizStepMiscParams
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Miscellaneous Parameters';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepModulesChoice::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$this->oWizard->SaveParameter('application_url', '');
|
||||
$this->oWizard->SaveParameter('graphviz_path', '');
|
||||
$this->oWizard->SaveParameter('force-uninstall', false);
|
||||
return ['class' => WizStepModulesChoice::class, 'state' => 'start_upgrade'];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetAbsoluteUrlAppRoot(true)); //Preserve existing configuration (except for the str_replace based joker $SERVER_NAME$ which is lost)
|
||||
$sDefaultGraphvizPath = (strtolower(substr(PHP_OS, 0, 3)) === 'win') ? 'C:\\Program Files\\Graphviz\\bin\\dot.exe' : '/usr/bin/dot';
|
||||
$sGraphvizPath = $this->oWizard->GetParameter('graphviz_path', $sDefaultGraphvizPath);
|
||||
$oPage->add('<h2>Additional parameters</h2>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Application URL</legend>');
|
||||
$oPage->add('<table>');
|
||||
$oPage->add('<tr><td>URL: </td><td><input id="application_url" class="ibo-input" name="application_url" type="text" size="35" maxlength="1024" value="'.utils::EscapeHtml($sApplicationURL).'" style="width: 100%;box-sizing: border-box;"><span id="v_application_url"/></td><tr>');
|
||||
$oPage->add('</table>');
|
||||
$oPage->add('<div class="message message-warning">Change the value above if the end-users will be accessing the application by another path due to a specific configuration of the web server.</div>');
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add('<fieldset>');
|
||||
$oPage->add('<legend>Path to Graphviz\' dot application</legend>');
|
||||
$oPage->add('<table>');
|
||||
$oPage->add('<tr><td>Path: </td><td><input id="graphviz_path" class="ibo-input" name="graphviz_path" type="text" size="35" maxlength="1024" value="'.utils::EscapeHtml($sGraphvizPath).'" style="width: 100%;box-sizing: border-box;"><span id="v_graphviz_path"/></td>');
|
||||
$oPage->add('<td><i class="fas fa-question-circle setup-input--hint--icon" data-tooltip-content="Graphviz is required to display the impact analysis graph (i.e. impacts / depends on)."></i></td><tr>');
|
||||
$oPage->add('</table>');
|
||||
$oPage->add('<span id="graphviz_status"></span>');
|
||||
$oPage->add('</fieldset>');
|
||||
$sAuthentToken = $this->oWizard->GetParameter('authent', '');
|
||||
$oPage->add('<input type="hidden" id="authent_token" value="'.$sAuthentToken.'"/>');
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$('#application_url').on('change keyup', function() { WizardUpdateButtons(); } );
|
||||
$('#graphviz_path').on('change keyup init', function() { WizardUpdateButtons(); WizardAsyncAction('check_graphviz', { graphviz_path: $('#graphviz_path').val(), authent: $('#authent_token').val() }); } ).trigger('init');
|
||||
$('#btn_next').on('click', function() {
|
||||
bRet = true;
|
||||
if ($(this).attr('data-graphviz') != 'ok')
|
||||
{
|
||||
bRet = confirm('The impact analysis will not be displayed properly. Are you sure you want to continue?');
|
||||
}
|
||||
return bRet;
|
||||
});
|
||||
EOF
|
||||
);
|
||||
|
||||
$this->AddUseSymlinksFlagOption($oPage);
|
||||
$this->AddForceUninstallFlagOption($oPage);
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
switch ($sCode) {
|
||||
case 'check_graphviz':
|
||||
$sGraphvizPath = $aParameters['graphviz_path'];
|
||||
$aCheck = SetupUtils::CheckGraphviz($sGraphvizPath);
|
||||
|
||||
// N°2214 logging TRACE results
|
||||
$aTraceCheck = CheckResult::FilterCheckResultArray($aCheck, [CheckResult::TRACE]);
|
||||
foreach ($aTraceCheck as $oTraceCheck) {
|
||||
SetupLog::Ok($oTraceCheck->sLabel);
|
||||
}
|
||||
|
||||
$aNonTraceCheck = array_diff($aCheck, $aTraceCheck);
|
||||
foreach ($aNonTraceCheck as $oCheck) {
|
||||
switch ($oCheck->iSeverity) {
|
||||
case CheckResult::INFO:
|
||||
$sStatus = 'ok';
|
||||
$sInfoExplanation = $oCheck->sLabel;
|
||||
$sMessage = json_encode('<div class="message message-valid">'.$sInfoExplanation.'</div>');
|
||||
break;
|
||||
|
||||
default:
|
||||
case CheckResult::ERROR:
|
||||
case CheckResult::WARNING:
|
||||
$sStatus = 'ko';
|
||||
$sErrorExplanation = $oCheck->sLabel;
|
||||
$sMessage = json_encode('<div class="message message-error">'.$sErrorExplanation.'</div>');
|
||||
break;
|
||||
}
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$("#graphviz_status").html($sMessage);
|
||||
$('#btn_next').attr('data-graphviz', '$sStatus');
|
||||
JS
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return
|
||||
<<<EOF
|
||||
bRet = ($('#application_url').val() != '');
|
||||
if (!bRet)
|
||||
{
|
||||
$("#v_application_url").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#v_application_url").html('');
|
||||
}
|
||||
bGraphviz = ($('#graphviz_path').val() != '');
|
||||
if (!bGraphviz)
|
||||
{
|
||||
// Does not prevent to move forward
|
||||
$("#v_graphviz_path").html('<img src="../images/validation_error.png" title="Impact analysis will not display properly"/>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#v_graphviz_path").html('');
|
||||
}
|
||||
return bRet;
|
||||
EOF
|
||||
;
|
||||
}
|
||||
}
|
||||
138
setup/wizardsteps/WizStepWelcome.php
Normal file
138
setup/wizardsteps/WizStepWelcome.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* First step of the iTop Installation Wizard: Welcome screen, requirements
|
||||
*/
|
||||
class WizStepWelcome extends WizardStep
|
||||
{
|
||||
protected $bCanMoveForward;
|
||||
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Welcome to '.ITOP_APPLICATION.' version '.ITOP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label for the " Next >> " button
|
||||
* @return string The label for the button
|
||||
*/
|
||||
public function GetNextButtonLabel()
|
||||
{
|
||||
return 'Continue';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return [WizStepInstallOrUpgrade::class];
|
||||
}
|
||||
|
||||
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
|
||||
{
|
||||
$sUID = SetupUtils::CreateSetupToken();
|
||||
$this->oWizard->SetParameter('authent', $sUID);
|
||||
return ['class' => WizStepInstallOrUpgrade::class, 'state' => ''];
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
// Store the misc_options for the future...
|
||||
$aMiscOptions = utils::ReadParam('option', [], false, 'raw_data');
|
||||
$sMiscOptions = $this->oWizard->GetParameter('misc_options', json_encode($aMiscOptions));
|
||||
$this->oWizard->SetParameter('misc_options', $sMiscOptions);
|
||||
|
||||
$oPage->add("<!--[if lt IE 11]><div id=\"old_ie\"></div><![endif]-->");
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
if ($('#old_ie').length > 0)
|
||||
{
|
||||
alert("Internet Explorer version 10 or older is NOT supported! (Check that IE is not running in compatibility mode)");
|
||||
}
|
||||
EOF
|
||||
);
|
||||
$oPage->add('<h1>'.ITOP_APPLICATION.' Installation Wizard</h1>');
|
||||
$aResults = SetupUtils::CheckPhpAndExtensions();
|
||||
$this->bCanMoveForward = true;
|
||||
$aInfo = [];
|
||||
$aWarnings = [];
|
||||
$aErrors = [];
|
||||
foreach ($aResults as $oCheckResult) {
|
||||
switch ($oCheckResult->iSeverity) {
|
||||
case CheckResult::ERROR:
|
||||
$aErrors[] = $oCheckResult->sLabel;
|
||||
$this->bCanMoveForward = false;
|
||||
break;
|
||||
|
||||
case CheckResult::WARNING:
|
||||
$aWarnings[] = $oCheckResult->sLabel;
|
||||
break;
|
||||
|
||||
case CheckResult::INFO:
|
||||
$aInfo[] = $oCheckResult->sLabel;
|
||||
break;
|
||||
|
||||
case CheckResult::TRACE:
|
||||
SetupLog::Ok($oCheckResult->sLabel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$sStyle = 'style="display:none;overflow:auto;"';
|
||||
$sToggleButtons = '<button type="button" id="show_details" class="ibo-button ibo-is-alternative ibo-is-neutral" onclick="$(\'#details\').toggle(); $(this).toggle(); $(\'#hide_details\').toggle();"><span class="ibo-button--icon fa fa-caret-down"></span><span class="ibo-button--label">Show details</span></button><button type="button" id="hide_details" class="ibo-button ibo-is-alternative ibo-is-neutral" style="display:none;" onclick="$(\'#details\').toggle(); $(this).toggle(); $(\'#show_details\').toggle();"><span class="ibo-button--icon fa fa-caret-up"></span><span class="ibo-button--label">Hide details</span></button>';
|
||||
if (count($aErrors) > 0) {
|
||||
$sStyle = 'overflow:auto;"';
|
||||
$sTitle = count($aErrors).' Error(s), '.count($aWarnings).' Warning(s).';
|
||||
$sH2Class = 'text-error';
|
||||
} elseif (count($aWarnings) > 0) {
|
||||
$sTitle = count($aWarnings).' Warning(s) '.$sToggleButtons;
|
||||
$sH2Class = 'text-warning';
|
||||
} else {
|
||||
$sTitle = 'Ok. '.$sToggleButtons;
|
||||
$sH2Class = 'text-valid';
|
||||
}
|
||||
$oPage->add(
|
||||
<<<HTML
|
||||
<h2 class="message">Prerequisites validation: <span class="$sH2Class">$sTitle</span></h2>
|
||||
<div id="details" $sStyle>
|
||||
HTML
|
||||
);
|
||||
foreach ($aErrors as $sText) {
|
||||
$oPage->error($sText);
|
||||
}
|
||||
foreach ($aWarnings as $sText) {
|
||||
$oPage->warning($sText);
|
||||
}
|
||||
foreach ($aInfo as $sText) {
|
||||
$oPage->ok($sText);
|
||||
}
|
||||
$oPage->add('</div>');
|
||||
if (!$this->bCanMoveForward) {
|
||||
$oPage->p('Sorry, the installation cannot continue. Please fix the errors and reload this page to launch the installation again.');
|
||||
$oPage->p('<button type="button" onclick="window.location.reload()">Reload</button>');
|
||||
}
|
||||
$oPage->add_ready_script('CheckDirectoryConfFilesPermissions("'.utils::GetItopVersionWikiSyntax().'")');
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return $this->bCanMoveForward;
|
||||
}
|
||||
}
|
||||
379
setup/wizardsteps/WizardStep.php
Normal file
379
setup/wizardsteps/WizardStep.php
Normal file
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2026 Combodo SAS
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* All the steps of the iTop installation wizard
|
||||
*
|
||||
* Steps order (can be retrieved using \WizardController::DumpStructure) :
|
||||
*
|
||||
* WizStepWelcome
|
||||
* WizStepInstallOrUpgrade
|
||||
* + +
|
||||
* | |
|
||||
* v +----->
|
||||
* WizStepLicense WizStepDetectedInfo
|
||||
* WizStepDBParams + +
|
||||
* WizStepAdminAccount | |
|
||||
* WizStepInstallMiscParams v +------>
|
||||
* + WizStepLicense2 +--> WizStepUpgradeMiscParams
|
||||
* | +
|
||||
* +---> <-----------------------------------+
|
||||
* WizStepModulesChoice
|
||||
* WizStepSummary
|
||||
* WizStepDone
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
/**
|
||||
* Abstract class to build "steps" for the wizard controller
|
||||
* If a step needs to maintain an internal "state" (for complex steps)
|
||||
* then it's up to the derived class to implement the behavior based on
|
||||
* the internal 'sCurrentState' variable.
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
abstract class WizardStep
|
||||
{
|
||||
/**
|
||||
* A reference to the WizardController
|
||||
* @var WizardController
|
||||
*/
|
||||
protected $oWizard;
|
||||
/**
|
||||
* Current 'state' of the wizard step. Simple 'steps' can ignore it
|
||||
* @var string
|
||||
*/
|
||||
protected $sCurrentState;
|
||||
|
||||
protected $bDependencyCheck = null;
|
||||
protected $sDependencyIssue = null;
|
||||
|
||||
protected function CheckDependencies()
|
||||
{
|
||||
if (is_null($this->bDependencyCheck)) {
|
||||
$aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
|
||||
$this->bDependencyCheck = true;
|
||||
try {
|
||||
SetupUtils::AnalyzeInstallation($this->oWizard, true, $aSelectedModules);
|
||||
} catch (MissingDependencyException $e) {
|
||||
$this->bDependencyCheck = false;
|
||||
$this->sDependencyIssue = $e->getHtmlDesc();
|
||||
}
|
||||
}
|
||||
return $this->bDependencyCheck;
|
||||
}
|
||||
|
||||
public function __construct(WizardController $oWizard, $sCurrentState)
|
||||
{
|
||||
$this->oWizard = $oWizard;
|
||||
$this->sCurrentState = $sCurrentState;
|
||||
}
|
||||
|
||||
public function GetState()
|
||||
{
|
||||
return $this->sCurrentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the wizard page for the current class/state
|
||||
* The page can contain any number of "<input/>" fields, but no "<form>...</form>" tag
|
||||
* The name of the input fields (and their id if one is supplied) MUST NOT start with "_"
|
||||
* (this is reserved for the wizard's own parameters)
|
||||
* @return void
|
||||
*/
|
||||
abstract public function Display(WebPage $oPage);
|
||||
|
||||
/**
|
||||
* Processes the page's parameters and (if moving forward) returns the next step/state to be displayed
|
||||
* @param bool $bMoveForward True if the wizard is moving forward 'Next >>' button pressed, false otherwise
|
||||
* @return hash array('class' => $sNextClass, 'state' => $sNextState)
|
||||
*/
|
||||
abstract public function UpdateWizardStateAndGetNextStep($bMoveForward = true);
|
||||
|
||||
/**
|
||||
* Returns the list of possible steps from this step forward
|
||||
* @return array Array of strings (step classes)
|
||||
*/
|
||||
abstract public function GetPossibleSteps();
|
||||
|
||||
/**
|
||||
* Returns title of the current step
|
||||
* @return string The title of the wizard page for the current step
|
||||
*/
|
||||
abstract public function GetTitle();
|
||||
|
||||
/**
|
||||
* Tells whether the parameters are Ok to move forward
|
||||
* @return boolean True to move forward, false to stey on the same step
|
||||
*/
|
||||
public function ValidateParams()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this step/state is the last one of the wizard (dead-end)
|
||||
* @return boolean True if the 'Next >>' button should be displayed
|
||||
*/
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the user will come back to this step/state if he click on "Back"
|
||||
* @return boolean True if the 'Back' button should display this step
|
||||
*/
|
||||
public function CanComeBack()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Next" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveForward()
|
||||
{
|
||||
return 'return true;';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label for the " Next >> " button
|
||||
* @return string The label for the button
|
||||
*/
|
||||
public function GetNextButtonLabel()
|
||||
{
|
||||
return 'Next';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this step/state allows to go back or not
|
||||
* @return boolean True if the '<< Back' button should be displayed
|
||||
*/
|
||||
public function CanMoveBackward()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the "Back" button should be enabled interactively
|
||||
* @return string A piece of javascript code returning either true or false
|
||||
*/
|
||||
public function JSCanMoveBackward()
|
||||
{
|
||||
return 'return true;';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this step of the wizard requires that the configuration file be writable
|
||||
* @return bool True if the wizard will possibly need to modify the configuration at some point
|
||||
*/
|
||||
public function RequiresWritableConfig()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload this function to implement asynchronous action(s) (AJAX)
|
||||
* @param string $sCode The code of the action (if several actions need to be distinguished)
|
||||
* @param hash $aParameters The action's parameters name => value
|
||||
*/
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Example of a simple Setup Wizard with some parameters to store
|
||||
* the installation mode (install | upgrade) and a simple asynchronous
|
||||
* (AJAX) action.
|
||||
*
|
||||
* The setup wizard is executed by the following code:
|
||||
*
|
||||
* $oWizard = new WizardController('Step1');
|
||||
* $oWizard->Run();
|
||||
*
|
||||
class Step1 extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Welcome';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array(Step2::class, Step2bis::class);
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
$sNextStep = '';
|
||||
$sInstallMode = utils::ReadParam('install_mode');
|
||||
if ($sInstallMode == 'install')
|
||||
{
|
||||
$this->oWizard->SetParameter('install_mode', 'install');
|
||||
$sNextStep = Step2::class;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->oWizard->SetParameter('install_mode', 'upgrade');
|
||||
$sNextStep = Step2bis::class;
|
||||
|
||||
}
|
||||
return array('class' => $sNextStep, 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 1!');
|
||||
$sInstallMode = $this->oWizard->GetParameter('install_mode', 'install');
|
||||
$sChecked = ($sInstallMode == 'install') ? ' checked ' : '';
|
||||
$oPage->p('<input type="radio" name="install_mode" value="install"'.$sChecked.'/> Install');
|
||||
$sChecked = ($sInstallMode == 'upgrade') ? ' checked ' : '';
|
||||
$oPage->p('<input type="radio" name="install_mode" value="upgrade"'.$sChecked.'/> Upgrade');
|
||||
}
|
||||
}
|
||||
|
||||
class Step2 extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Installation Parameters';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array(Step3::class);
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
return array('class' => Step3::class, 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 2! (Installation)');
|
||||
}
|
||||
}
|
||||
|
||||
class Step2bis extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Upgrade Parameters';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array(Step2ter::class);
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
$sUpgradeInfo = utils::ReadParam('upgrade_info');
|
||||
$this->oWizard->SetParameter('upgrade_info', $sUpgradeInfo);
|
||||
$sAdditionalUpgradeInfo = utils::ReadParam('additional_upgrade_info');
|
||||
$this->oWizard->SetParameter('additional_upgrade_info', $sAdditionalUpgradeInfo);
|
||||
return array('class' => Step2ter::class, 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 2bis! (Upgrade)');
|
||||
$sUpgradeInfo = $this->oWizard->GetParameter('upgrade_info', '');
|
||||
$oPage->p('Type your name here: <input type="text" id="upgrade_info" name="upgrade_info" value="'.$sUpgradeInfo.'" size="20"/><span id="v_upgrade_info"></span>');
|
||||
$sAdditionalUpgradeInfo = $this->oWizard->GetParameter('additional_upgrade_info', '');
|
||||
$oPage->p('The installer replies: <input type="text" name="additional_upgrade_info" value="'.$sAdditionalUpgradeInfo.'" size="20"/>');
|
||||
|
||||
$oPage->add_ready_script("$('#upgrade_info').change(function() {
|
||||
$('#v_upgrade_info').html('<img src=\"../images/indicator.gif\"/>');
|
||||
WizardAsyncAction('', { upgrade_info: $('#upgrade_info').val() }); });");
|
||||
}
|
||||
|
||||
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
|
||||
{
|
||||
usleep(300000); // 300 ms
|
||||
$sName = $aParameters['upgrade_info'];
|
||||
$sReply = addslashes("Hello ".$sName);
|
||||
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$("#v_upgrade_info").html('');
|
||||
$("input[name=additional_upgrade_info]").val("$sReply");
|
||||
EOF
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Step2ter extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Additional Upgrade Info';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array(Step3::class);
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
return array('class' => Step3::class, 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is Step 2ter! (Upgrade)');
|
||||
}
|
||||
}
|
||||
|
||||
class Step3 extends WizardStep
|
||||
{
|
||||
public function GetTitle()
|
||||
{
|
||||
return 'Installation Complete';
|
||||
}
|
||||
|
||||
public function GetPossibleSteps()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function ProcessParams($bMoveForward = true)
|
||||
{
|
||||
return array('class' => '', 'state' => '');
|
||||
}
|
||||
|
||||
public function Display(WebPage $oPage)
|
||||
{
|
||||
$oPage->p('This is the FINAL Step');
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
End of the example */
|
||||
@@ -230,6 +230,7 @@ class XMLDataLoader
|
||||
} else {
|
||||
$iDstObj = (int)($oSubNode);
|
||||
// Attempt to find the object in the list of loaded objects
|
||||
/** @var \Combodo\iTop\Core\AttributeDefinition\AttributeExternalKey $oAttDef */
|
||||
$iExtKey = $this->GetObjectKey($oAttDef->GetTargetClass(), $iDstObj);
|
||||
if ($iExtKey == 0) {
|
||||
$iExtKey = -$iDstObj; // Convention: Unresolved keys are stored as negative !
|
||||
@@ -353,8 +354,10 @@ class XMLDataLoader
|
||||
foreach ($oObjList as $oTargetObj) {
|
||||
$bChanged = false;
|
||||
$sClass = get_class($oTargetObj);
|
||||
$iExtKey = -1;
|
||||
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
|
||||
if (($oAttDef->IsExternalKey()) && ($oTargetObj->Get($sAttCode) < 0)) { // Convention unresolved key = negative
|
||||
/** @var \Combodo\iTop\Core\AttributeDefinition\AttributeExternalKey $oAttDef */
|
||||
$sTargetClass = $oAttDef->GetTargetClass();
|
||||
$iTempKey = $oTargetObj->Get($sAttCode);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ class JsonPage extends WebPage
|
||||
* This can be useful when feeding response to a third party lib that doesn't understand the structured format.
|
||||
*/
|
||||
protected $bOutputDataOnly = false;
|
||||
protected $bOutputHeaders = true;
|
||||
|
||||
/**
|
||||
* JsonPage constructor.
|
||||
@@ -82,6 +83,19 @@ class JsonPage extends WebPage
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$bOutputHeaders
|
||||
* @param bool $bFlag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetOutputHeaders(bool $bFlag)
|
||||
{
|
||||
$this->bOutputHeaders = $bFlag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the headers
|
||||
*
|
||||
@@ -119,7 +133,10 @@ class JsonPage extends WebPage
|
||||
public function output()
|
||||
{
|
||||
$oKpi = new ExecutionKPI();
|
||||
$this->OutputHeaders();
|
||||
if ($this->bOutputHeaders) {
|
||||
$this->OutputHeaders();
|
||||
}
|
||||
|
||||
$sContent = $this->ComputeContent();
|
||||
$oKpi->ComputeAndReport(get_class($this).' output');
|
||||
|
||||
|
||||
@@ -178,12 +178,19 @@ class InterfaceDiscovery
|
||||
continue;
|
||||
}
|
||||
$aTmpClassMap = include $sAutoloadFile;
|
||||
if (! is_array($aTmpClassMap)) {
|
||||
//can happen when setup compilation broken in the middle
|
||||
//ex: $sAutoloadFile could be empty and $aTmpClassMap is a int
|
||||
$aAutoloaderErrors[] = $sAutoloadFile;
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @noinspection SlowArrayOperationsInLoopInspection we are getting an associative array so the documented workarounds cannot be used */
|
||||
$aClassMap = array_merge($aClassMap, $aTmpClassMap);
|
||||
}
|
||||
if (count($aAutoloaderErrors) > 0) {
|
||||
IssueLog::Debug(
|
||||
__METHOD__." cannot load some of the autoloader files",
|
||||
__METHOD__." cannot load some of the autoloader files: missing or corrupted",
|
||||
LogChannels::CORE,
|
||||
['autoloader_errors' => $aAutoloaderErrors]
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
includes:
|
||||
- php-includes/set-php-version-from-process.php # Workaround to set PHP version to the on running the CLI
|
||||
# for an explanation of the baseline concept, see: https://phpstan.org/user-guide/baseline
|
||||
#baseline HERE DO NOT REMOVE FOR CI
|
||||
#baseline HERE DO NOT REMOVE FOR CI
|
||||
|
||||
parameters:
|
||||
level: 0
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\HubConnector;
|
||||
|
||||
use Combodo\iTop\DBTools\Service\DBToolsUtils;
|
||||
use Combodo\iTop\HubConnector\Controller\HubController;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use DOMFormatException;
|
||||
use JsonPage;
|
||||
use MFCompiler;
|
||||
use SetupLog;
|
||||
use SetupUtils;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runClassInSeparateProcess
|
||||
*/
|
||||
class HubControllerTest extends ItopDataTestCase
|
||||
{
|
||||
public const USE_TRANSACTION = false;
|
||||
public const AUTHENTICATION_TOKEN = '14b5da9d092f84044187421419a0347e7317bc8cd2b486fdda631be06b959269';
|
||||
public const AUTHENTICATION_PASSWORD = "tagada-Secret,007";
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->SkipIfModuleNotPresent('itop-hub-connector');
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('env-production/itop-hub-connector/src/Controller/HubController.php');
|
||||
}
|
||||
|
||||
public function testLaunchCompile(): void
|
||||
{
|
||||
$this->PrepareCompileAuthent();
|
||||
|
||||
$this->CopyProductionModulesIntoHubExtensionDir();
|
||||
|
||||
HubController::GetInstance()->SetOutputHeaders(false);
|
||||
|
||||
HubController::GetInstance()->LaunchCompile();
|
||||
|
||||
$this->CheckReport('{"code":0,"message":"Ok","fields":[]}');
|
||||
}
|
||||
|
||||
public function testLaunchDeploy(): void
|
||||
{
|
||||
$this->testLaunchCompile();
|
||||
HubController::GetInstance()->LaunchDeploy();
|
||||
$this->CheckReport('{"code":0,"message":"Compilation successful.","fields":[]}');
|
||||
$this->AssertPreviousAndCurrentInstallationAreEquivalent();
|
||||
}
|
||||
|
||||
private function CheckReport($sExpected)
|
||||
{
|
||||
$oJsonPage = HubController::GetInstance()->GetLastJsonPage();
|
||||
$this->assertEquals($sExpected, $this->InvokeNonPublicMethod(JsonPage::class, 'ComputeContent', $oJsonPage, []));
|
||||
|
||||
//keep line below to avoid: Test code or tested code did not (only) close its own output buffers
|
||||
$this->InvokeNonPublicMethod(JsonPage::class, 'RenderContent', $oJsonPage, []);
|
||||
}
|
||||
|
||||
private function PrepareCompileAuthent()
|
||||
{
|
||||
$sUUID = 'hub_'.uniqid();
|
||||
$_REQUEST['authent'] = $sUUID;
|
||||
$sPath = utils::GetDataPath().'hub/compile_authent';
|
||||
file_put_contents($sPath, $sUUID);
|
||||
$this->aFileToClean[] = $sPath;
|
||||
}
|
||||
|
||||
private function CopyProductionModulesIntoHubExtensionDir()
|
||||
{
|
||||
$sProdModules = APPROOT.'/data/production-modules';
|
||||
$sExtensionDir = APPROOT.'/data/downloaded-extensions/';
|
||||
$this->aFileToClean[] = $sExtensionDir;
|
||||
|
||||
SetupUtils::rrmdir($sExtensionDir);
|
||||
@mkdir($sExtensionDir);
|
||||
SetupUtils::copydir($sExtensionDir, $sProdModules);
|
||||
}
|
||||
}
|
||||
@@ -188,6 +188,9 @@ abstract class ItopCustomDatamodelTestCase extends ItopDataTestCase
|
||||
CMDBSource::DropTable("priv_module_install");
|
||||
CMDBSource::Query("CREATE TABLE $sNewDB.priv_module_install SELECT * FROM $sPreviousDB.priv_module_install");
|
||||
|
||||
CMDBSource::DropTable("priv_extension_install");
|
||||
CMDBSource::Query("CREATE TABLE $sNewDB.priv_extension_install SELECT * FROM $sPreviousDB.priv_extension_install");
|
||||
|
||||
$this->debug("Custom environment '$sTestEnv' is ready!");
|
||||
} else {
|
||||
$this->debug("Custom environment '$sTestEnv' READY BUILT:");
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Combodo\iTop\Test\UnitTest;
|
||||
use ArchivedObjectException;
|
||||
use CMDBObject;
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\DBTools\Service\DBToolsUtils;
|
||||
use Combodo\iTop\Service\Events\EventService;
|
||||
use Config;
|
||||
use Contact;
|
||||
@@ -34,6 +35,7 @@ use lnkContactToTicket;
|
||||
use lnkFunctionalCIToTicket;
|
||||
use MetaModel;
|
||||
use MissingQueryArgument;
|
||||
use ModuleInstallationRepository;
|
||||
use MySQLException;
|
||||
use MySQLHasGoneAwayException;
|
||||
use Person;
|
||||
@@ -1556,4 +1558,31 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
@chmod($sConfigPath, 0440);
|
||||
@unlink($this->sConfigTmpBackupFile);
|
||||
}
|
||||
|
||||
public function AssertPreviousAndCurrentInstallationAreEquivalent()
|
||||
{
|
||||
$aPreviousInstallations = ModuleInstallationRepository::GetInstance()->GetPreviousModuleInstallationsByOffset(1);
|
||||
$aInstallations = ModuleInstallationRepository::GetInstance()->GetPreviousModuleInstallationsByOffset();
|
||||
$this->assertEquals($this->GetCanonicalComparableModuleInstallationArray($aPreviousInstallations), $this->GetCanonicalComparableModuleInstallationArray($aInstallations));
|
||||
}
|
||||
|
||||
protected function GetCanonicalComparableModuleInstallationArray($aInstallations): array
|
||||
{
|
||||
$aRes = [];
|
||||
$aIgnoredFields = ['id', 'parent_id', 'installed', 'comment'];
|
||||
foreach ($aInstallations as $aData) {
|
||||
$aNewData = [];
|
||||
foreach ($aData as $sKey => $val) {
|
||||
if (in_array($sKey, $aIgnoredFields)) {
|
||||
continue;
|
||||
}
|
||||
$aNewData[$sKey] = $val;
|
||||
}
|
||||
$sName = $aNewData['name'];
|
||||
$aRes[$sName] = $aNewData;
|
||||
}
|
||||
|
||||
asort($aRes);
|
||||
return $aRes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,4 +698,17 @@ abstract class ItopTestCase extends KernelTestCase
|
||||
|
||||
return $this->CallUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a temporary file path. that will be cleaned up by tearDown()
|
||||
*
|
||||
* @return string: temporary file path: file prefix include phpunit test method name
|
||||
*/
|
||||
public function GetTemporaryFilePath(): string
|
||||
{
|
||||
$sPrefix = $this->getName(false);
|
||||
$sPath = tempnam(sys_get_temp_dir(), $sPrefix);
|
||||
$this->aFileToClean[] = $sPath;
|
||||
return $sPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
namespace Combodo\iTop\Test\UnitTest\Service;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopCustomDatamodelTestCase;
|
||||
use DOMFormatException;
|
||||
use MFCoreModule;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use ReflectionClass;
|
||||
use RunTimeEnvironment;
|
||||
use SetupLog;
|
||||
use SetupUtils;
|
||||
use utils;
|
||||
|
||||
@@ -64,7 +66,13 @@ class UnitTestRunTimeEnvironment extends RunTimeEnvironment
|
||||
}
|
||||
}
|
||||
|
||||
parent::CompileFrom($sSourceEnv, $bUseSymLinks);
|
||||
try {
|
||||
parent::CompileFrom($sSourceEnv, $bUseSymLinks);
|
||||
} catch (DOMFormatException $e) {
|
||||
$sFileName = $sSourceEnv.'.delta.xml';
|
||||
SetupLog::Error(__METHOD__, null, [$sFileName => @file_get_contents(APPROOT.'data/'.$sFileName)]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function IsUpToDate()
|
||||
|
||||
@@ -498,6 +498,34 @@ class MetaModelTest extends ItopDataTestCase
|
||||
'Purge 10 items with a max_chunk_size of 1000 (default value) should be perfomed in 1 step' => [1000, 3],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetCreatedIn_UnknownClass()
|
||||
{
|
||||
$this->expectExceptionMessage("Cannot find class module");
|
||||
$this->expectException(CoreException::class);
|
||||
|
||||
MetaModel::GetModuleName('GABUZOMEU');
|
||||
}
|
||||
|
||||
public function testGetCreatedIn_ClassComingFromCorePhpFile()
|
||||
{
|
||||
$this->assertEquals('core', MetaModel::GetModuleName('BackgroundTask'));
|
||||
}
|
||||
|
||||
public function testGetCreatedIn_ClassComingFromCorePhpFile2()
|
||||
{
|
||||
$this->assertEquals('core', MetaModel::GetModuleName('lnkActionNotificationToContact'));
|
||||
}
|
||||
|
||||
public function testGetCreatedIn_ClassComingFromModulePhpFile()
|
||||
{
|
||||
$this->assertEquals('itop-attachments', MetaModel::GetModuleName('CMDBChangeOpAttachmentAdded'));
|
||||
}
|
||||
|
||||
public function testGetCreatedIn_ClassComingFromXmlDataModelFile()
|
||||
{
|
||||
$this->assertEquals('authent-ldap', MetaModel::GetModuleName('UserLDAP'));
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Wizzard
|
||||
|
||||
@@ -7,30 +7,26 @@
|
||||
*
|
||||
*
|
||||
*/
|
||||
$MySettings = array(
|
||||
|
||||
|
||||
$MySettings = [
|
||||
|
||||
// app_root_url: Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server's name)
|
||||
// default: ''
|
||||
'app_root_url' => 'http://%server(SERVER_NAME)?:localhost%/itop/iTop/',
|
||||
|
||||
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* Modules specific settings
|
||||
*
|
||||
*/
|
||||
$MyModuleSettings = array(
|
||||
);
|
||||
$MyModuleSettings = [
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* Data model modules to be loaded. Names are specified as relative paths
|
||||
*
|
||||
*/
|
||||
$MyModules = array(
|
||||
);
|
||||
?>
|
||||
$MyModules = [
|
||||
];
|
||||
|
||||
@@ -7,30 +7,26 @@
|
||||
*
|
||||
*
|
||||
*/
|
||||
$MySettings = array(
|
||||
|
||||
|
||||
$MySettings = [
|
||||
|
||||
// app_root_url: Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server's name)
|
||||
// default: ''
|
||||
'app_root_url' => 'http://' . (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost') . '/itop/iTop/',
|
||||
'app_root_url' => 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/itop/iTop/',
|
||||
|
||||
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* Modules specific settings
|
||||
*
|
||||
*/
|
||||
$MyModuleSettings = array(
|
||||
);
|
||||
$MyModuleSettings = [
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* Data model modules to be loaded. Names are specified as relative paths
|
||||
*
|
||||
*/
|
||||
$MyModules = array(
|
||||
);
|
||||
?>
|
||||
$MyModules = [
|
||||
];
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
|
||||
class ModuleDiscoveryTest extends ItopTestCase
|
||||
{
|
||||
public function GetModuleNameProvider()
|
||||
{
|
||||
return [
|
||||
'nominal' => [
|
||||
'sModuleId' => 'a/1.2.3',
|
||||
'name' => 'a',
|
||||
'version' => '1.2.3',
|
||||
],
|
||||
'develop' => [
|
||||
'sModuleId' => 'a/1.2.3-dev',
|
||||
'name' => 'a',
|
||||
'version' => '1.2.3-dev',
|
||||
],
|
||||
'missing version => 1.0.0' => [
|
||||
'sModuleId' => 'a/',
|
||||
'name' => 'a',
|
||||
'version' => '1.0.0',
|
||||
],
|
||||
'missing everything except name' => [
|
||||
'sModuleId' => 'a',
|
||||
'name' => 'a',
|
||||
'version' => '1.0.0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->RequireOnceItopFile('setup/modulediscovery.class.inc.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetModuleNameProvider
|
||||
*/
|
||||
public function testGetModuleName($sModuleId, $expectedName, $expectedVersion)
|
||||
{
|
||||
$this->assertEquals([$expectedName, $expectedVersion], \ModuleDiscovery::GetModuleName($sModuleId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup;
|
||||
|
||||
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReader;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use iTopExtension;
|
||||
use MissingDependencyException;
|
||||
use ModuleDiscovery;
|
||||
|
||||
@@ -15,6 +17,12 @@ class ModuleDiscoveryTest extends ItopTestCase
|
||||
$this->RequireOnceItopFile('setup/modulediscovery.class.inc.php');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
ModuleDiscovery::DeclareRemovedExtensions([]);
|
||||
}
|
||||
|
||||
public function testOrderModulesByDependencies_RealExample()
|
||||
{
|
||||
$aModules = json_decode(file_get_contents(__DIR__.'/ressources/reallife_discovered_modules.json'), true);
|
||||
@@ -77,4 +85,126 @@ TXT;
|
||||
|
||||
ModuleDiscovery::OrderModulesByDependencies($aModules, true, $aChoices);
|
||||
}
|
||||
|
||||
public function testOrderModulesByDependencies_FailWhenChoosenModuleDependsOnRemovedExtensionModule()
|
||||
{
|
||||
$aChoices = ['id1', 'id2'];
|
||||
|
||||
$sModuleFilePath = $this->GetTemporaryFilePath();
|
||||
$sModuleFilePath2 = $this->GetTemporaryFilePath();
|
||||
|
||||
$aModules = [
|
||||
"id1/1" => [
|
||||
'dependencies' => [ 'id2/2'],
|
||||
'label' => 'label1',
|
||||
ModuleFileReader::MODULE_FILE_PATH => $sModuleFilePath,
|
||||
],
|
||||
"id2/2" => [
|
||||
'dependencies' => [],
|
||||
'label' => 'label2',
|
||||
ModuleFileReader::MODULE_FILE_PATH => $sModuleFilePath2,
|
||||
],
|
||||
];
|
||||
|
||||
$oExtension = $this->GivenExtensionWithModule('id2', '2', $sModuleFilePath2);
|
||||
ModuleDiscovery::DeclareRemovedExtensions([$oExtension]);
|
||||
|
||||
$sExpectedMessage = <<<TXT
|
||||
The following modules have unmet dependencies:
|
||||
label1 (id: id1/1) depends on: ❌ id2/2
|
||||
TXT;
|
||||
$this->expectException(MissingDependencyException::class);
|
||||
$this->expectExceptionMessage($sExpectedMessage);
|
||||
|
||||
ModuleDiscovery::OrderModulesByDependencies($aModules, true, $aChoices);
|
||||
}
|
||||
|
||||
public function GetModuleNameProvider()
|
||||
{
|
||||
return [
|
||||
'nominal' => [
|
||||
'sModuleId' => 'a/1.2.3',
|
||||
'name' => 'a',
|
||||
'version' => '1.2.3',
|
||||
],
|
||||
'develop' => [
|
||||
'sModuleId' => 'a/1.2.3-dev',
|
||||
'name' => 'a',
|
||||
'version' => '1.2.3-dev',
|
||||
],
|
||||
'missing version => 1.0.0' => [
|
||||
'sModuleId' => 'a/',
|
||||
'name' => 'a',
|
||||
'version' => '1.0.0',
|
||||
],
|
||||
'missing everything except name' => [
|
||||
'sModuleId' => 'a',
|
||||
'name' => 'a',
|
||||
'version' => '1.0.0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetModuleNameProvider
|
||||
*/
|
||||
public function testGetModuleName($sModuleId, $expectedName, $expectedVersion)
|
||||
{
|
||||
$this->assertEquals([$expectedName, $expectedVersion], ModuleDiscovery::GetModuleName($sModuleId));
|
||||
}
|
||||
|
||||
public function testIsModuleInExtensionList_NoRemovedExtension()
|
||||
{
|
||||
$this->assertFalse($this->InvokeNonPublicStaticMethod(ModuleDiscovery::class, "IsModuleInExtensionList", [[], 'module_name', '123', []]));
|
||||
}
|
||||
|
||||
public function testIsModuleInExtensionList_ModuleWithAnotherVersionIncludedInRemoveExtension()
|
||||
{
|
||||
$sModuleFilePath = $this->GetTemporaryFilePath();
|
||||
$aExtensionList = [$this->GivenExtensionWithModule('module_name', '456', $sModuleFilePath)];
|
||||
$this->AssertModuleIsPartOfRemovedExtension($aExtensionList, 'module_name', '123', $sModuleFilePath, false);
|
||||
}
|
||||
|
||||
public function testIsModuleInExtensionList_AnotherModuleWithSameVersionIncludedInRemoveExtension()
|
||||
{
|
||||
$sModuleFilePath = $this->GetTemporaryFilePath();
|
||||
$aExtensionList = [$this->GivenExtensionWithModule('module_name', '456', $sModuleFilePath)];
|
||||
$this->AssertModuleIsPartOfRemovedExtension($aExtensionList, 'another_module_name', '456', $sModuleFilePath, false);
|
||||
}
|
||||
|
||||
public function testIsModuleInExtensionList_SameExtensionComingFromAnotherLocation()
|
||||
{
|
||||
$sModuleFilePath = $this->GetTemporaryFilePath();
|
||||
$sModuleFilePath2 = $this->GetTemporaryFilePath();
|
||||
$aExtensionList = [$this->GivenExtensionWithModule('module_name', '456', $sModuleFilePath2)];
|
||||
$this->AssertModuleIsPartOfRemovedExtension($aExtensionList, 'module_name', '456', $sModuleFilePath, false);
|
||||
}
|
||||
|
||||
public function testIsModuleInExtensionList_ModuleShouldBeExcluded()
|
||||
{
|
||||
$sModuleFilePath = $this->GetTemporaryFilePath();
|
||||
$aExtensionList = [$this->GivenExtensionWithModule('module_name', '456', $sModuleFilePath)];
|
||||
$this->AssertModuleIsPartOfRemovedExtension($aExtensionList, 'module_name', '456', $sModuleFilePath, true);
|
||||
}
|
||||
|
||||
public function AssertModuleIsPartOfRemovedExtension($aExtensionList, $sModuleName, $sModuleVersion, $sModuleFilePath, $bExpected)
|
||||
{
|
||||
$aCurrentModuleInfo = [
|
||||
ModuleFileReader::MODULE_FILE_PATH => $sModuleFilePath,
|
||||
];
|
||||
$this->assertEquals(
|
||||
$bExpected,
|
||||
$this->InvokeNonPublicStaticMethod(ModuleDiscovery::class, "IsModuleInExtensionList", [$aExtensionList, $sModuleName, $sModuleVersion, $aCurrentModuleInfo])
|
||||
);
|
||||
}
|
||||
|
||||
private function GivenExtensionWithModule(string $sModuleName, string $sVersion, bool|string $sModuleFilePath): iTopExtension
|
||||
{
|
||||
$oExt = new iTopExtension();
|
||||
$oExt->aModuleVersion[$sModuleName] = $sVersion;
|
||||
$oExt->aModuleInfo[$sModuleName] = [
|
||||
ModuleFileReader::MODULE_FILE_PATH => $sModuleFilePath,
|
||||
];
|
||||
return $oExt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ class WizStepModulesChoiceFake extends WizStepModulesChoice
|
||||
{
|
||||
public function __construct(WizardController $oWizard, $sCurrentState)
|
||||
{
|
||||
|
||||
$this->oWizard = $oWizard;
|
||||
$this->sCurrentState = $sCurrentState;
|
||||
}
|
||||
|
||||
public function setExtensionMap(iTopExtensionsMap $oMap)
|
||||
|
||||
@@ -3,13 +3,16 @@
|
||||
namespace Combodo\iTop\Test\UnitTest\Integration;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use ItopExtensionsMap;
|
||||
use iTopExtensionsMap;
|
||||
use iTopExtensionsMapFake;
|
||||
use ModuleDiscovery;
|
||||
use WizardController;
|
||||
use WizStepModulesChoiceFake;
|
||||
use XMLParameters;
|
||||
|
||||
class WizStepModulesChoiceTest extends ItopTestCase
|
||||
{
|
||||
private WizStepModulesChoiceFake $oStep;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -17,28 +20,45 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
require_once __DIR__.'/iTopExtensionsMapFake.php';
|
||||
require_once __DIR__.'/WizStepModulesChoiceFake.php';
|
||||
|
||||
$this->oStep = new \WizStepModulesChoiceFake(new WizardController('', ''), '');
|
||||
$this->oStep = new WizStepModulesChoiceFake(new WizardController('', ''), '');
|
||||
ModuleDiscovery::ResetCache();
|
||||
}
|
||||
|
||||
public function ProviderComputeChoiceFlags()
|
||||
{
|
||||
return [
|
||||
'selected but not installed extension' => [
|
||||
'aExtensions' => [
|
||||
'A not selected, not installed extension should not be checked and be enabled' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => false,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
],
|
||||
'aSelected' => ['_0' => '_0'],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
'installed' => false,
|
||||
'disabled' => false,
|
||||
'checked' => false,
|
||||
],
|
||||
],
|
||||
'A selected but not installed extension should be checked and enabled' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
],
|
||||
'bCurrentSelected' => true,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
@@ -47,44 +67,18 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'checked' => true,
|
||||
],
|
||||
],
|
||||
'not selected, not installed extension' => [
|
||||
'aExtensions' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => true,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
],
|
||||
'aSelected' => [],
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
'installed' => false,
|
||||
'disabled' => false,
|
||||
'checked' => false,
|
||||
],
|
||||
],
|
||||
'installed extension' => [
|
||||
'aExtensions' => [
|
||||
'An installed but not selected extension should not be checked and be enabled' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => true,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => true,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
],
|
||||
'aSelected' => [],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
@@ -93,21 +87,18 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'checked' => false,
|
||||
],
|
||||
],
|
||||
'installed non uninstallable extension' => [
|
||||
'aExtensions' => [
|
||||
'An installed non uninstallable extension should be checked and disabled' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => true,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => true,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => false,
|
||||
],
|
||||
'aSelected' => [],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => false,
|
||||
'missing' => false,
|
||||
@@ -116,21 +107,18 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'checked' => true,
|
||||
],
|
||||
],
|
||||
'mandatory extension' => [
|
||||
'aExtensions' => [
|
||||
'A mandatory extension should be checked and disabled' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => true,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => true,
|
||||
'uninstallable' => true,
|
||||
],
|
||||
'aSelected' => [],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
@@ -139,8 +127,8 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'checked' => true,
|
||||
],
|
||||
],
|
||||
'optional sub extension' => [
|
||||
'aExtensions' => [
|
||||
'An optional sub extension should not force its parent flags' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
@@ -148,10 +136,7 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => true,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
@@ -165,7 +150,7 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
],
|
||||
],
|
||||
],
|
||||
'aSelected' => [],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
@@ -174,8 +159,8 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'checked' => false,
|
||||
],
|
||||
],
|
||||
'mandatory sub extension' => [
|
||||
'aExtensions' => [
|
||||
'A mandatory sub extension should force its parent to be checked and disabled' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
@@ -183,10 +168,7 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => true,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
@@ -200,7 +182,7 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
],
|
||||
],
|
||||
],
|
||||
'aSelected' => [],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
@@ -209,8 +191,8 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'checked' => true,
|
||||
],
|
||||
],
|
||||
'non uninstallable sub extension' => [
|
||||
'aExtensions' => [
|
||||
'An installed non uninstallable sub extension should force its parent to be checked and disabled' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => true,
|
||||
],
|
||||
@@ -218,10 +200,7 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'installed' => true,
|
||||
],
|
||||
],
|
||||
'bUpgrade' => true,
|
||||
'bDisableUninstallCheck' => false,
|
||||
'sChoiceId' => '_0',
|
||||
'aStepInfo' => [
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
@@ -235,7 +214,7 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
],
|
||||
],
|
||||
],
|
||||
'aSelected' => [],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
@@ -244,17 +223,286 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
'checked' => true,
|
||||
],
|
||||
],
|
||||
'A non installed non uninstallable sub extension should not force its parent flags' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => true,
|
||||
],
|
||||
'itop-ext1-1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'aWizardStepDefinition' => [
|
||||
'extension_code' => 'itop-ext1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => true,
|
||||
'sub_options' => [
|
||||
'options' => [
|
||||
[
|
||||
'extension_code' => 'itop-ext1-1',
|
||||
'mandatory' => false,
|
||||
'uninstallable' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'bCurrentSelected' => false,
|
||||
'aExpectedFlags' => [
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
'installed' => true,
|
||||
'disabled' => false,
|
||||
'checked' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ProviderComputeChoiceFlags
|
||||
*/
|
||||
public function testComputeChoiceFlags($aExtensions, $bUpgrade, $bDisableUninstallCheck, $sChoiceId, $aStepInfo, $aSelected, $aExpectedFlags)
|
||||
public function testComputeChoiceFlags($aExtensionsOnDiskOrDb, $aWizardStepDefinition, $bIsCurrentSelected, $aExpectedFlags)
|
||||
{
|
||||
$this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensions));
|
||||
$aFlags = $this->oStep->ComputeChoiceFlags($aStepInfo, $sChoiceId, $aSelected, false, $bDisableUninstallCheck, $bUpgrade);
|
||||
$this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsOnDiskOrDb));
|
||||
$aFlags = $this->oStep->ComputeChoiceFlags($aWizardStepDefinition, '_0', $bIsCurrentSelected ? ['_0' => '_0'] : [], false, false, true);
|
||||
$this->assertEquals($aExpectedFlags, $aFlags);
|
||||
}
|
||||
|
||||
public function ProviderGetAddedAndRemovedExtensions()
|
||||
{
|
||||
return [
|
||||
'no extensions' => [
|
||||
'aExtensionsOnDiskOrDb' => [],
|
||||
|
||||
'aSelected' => [],
|
||||
'aExpectedAddedList' => [],
|
||||
'aExpectedRemovedList' => [],
|
||||
],
|
||||
'no extensions added nor removed' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'aSelected' => [],
|
||||
'aExpectedAddedList' => [],
|
||||
'aExpectedRemovedList' => [],
|
||||
],
|
||||
'One added extension' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
],
|
||||
'aSelected' => ['itop-ext1'],
|
||||
'aExpectedAddedList' => ['itop-ext1' => 'itop-ext1'],
|
||||
'aExpectedRemovedList' => [],
|
||||
],
|
||||
'One removed extension' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => true,
|
||||
],
|
||||
],
|
||||
'aSelected' => [],
|
||||
'aExpectedAddedList' => [],
|
||||
'aExpectedRemovedList' => ['itop-ext1' => 'itop-ext1'],
|
||||
],
|
||||
'Forced removed extension' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext1' => [
|
||||
'installed' => true,
|
||||
'uninstallable' => false,
|
||||
],
|
||||
],
|
||||
'aSelected' => [],
|
||||
'aExpectedAddedList' => [],
|
||||
'aExpectedRemovedList' => ['itop-ext1' => 'itop-ext1'],
|
||||
],
|
||||
'added and removed extensions' => [
|
||||
'aExtensionsOnDiskOrDb' => [
|
||||
'itop-ext-added1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
'itop-ext-added2' => [
|
||||
'installed' => false,
|
||||
],
|
||||
'itop-ext-removed1' => [
|
||||
'installed' => true,
|
||||
],
|
||||
'itop-ext-removed2' => [
|
||||
'installed' => true,
|
||||
],
|
||||
],
|
||||
'aSelected' => ['itop-ext-added1', 'itop-ext-added2'],
|
||||
'aExpectedAddedList' => ['itop-ext-added1' => 'itop-ext-added1', 'itop-ext-added2' => 'itop-ext-added2'],
|
||||
'aExpectedRemovedList' => ['itop-ext-removed1' => 'itop-ext-removed1', 'itop-ext-removed2' => 'itop-ext-removed2'],
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ProviderGetAddedAndRemovedExtensions
|
||||
*/
|
||||
public function testGetAddedAndRemovedExtensions($aExtensionsOnDiskOrDb, $aSelectedExtensions, $aExpectedAddedList, $aExpectedRemovedList)
|
||||
{
|
||||
$this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsOnDiskOrDb));
|
||||
[$aAddedList, $aRemovedList, $aNotUninstallableList] = $this->oStep->GetAddedAndRemovedExtensions($aSelectedExtensions);
|
||||
$this->assertEquals($aExpectedAddedList, $aAddedList);
|
||||
$this->assertEquals($aExpectedRemovedList, $aRemovedList);
|
||||
}
|
||||
|
||||
public function testGetStepInfo_PackageWithoutInstallationXML()
|
||||
{
|
||||
|
||||
$aExtensionsOnDiskOrDb = self::GivenExtensionsOnDisk();
|
||||
$oWizStepModulesChoice = $this->GivenWizStepModulesChoiceWithoutXmlInstallation($aExtensionsOnDiskOrDb);
|
||||
|
||||
$expected = [
|
||||
'title' => 'Modules Selection',
|
||||
'description' => '<h2>Select the modules to install. You can launch the installation again to install new modules, but you cannot remove already installed modules.</h2>',
|
||||
'banner' => '/images/icons/icons8-apps-tab.svg',
|
||||
'options' => $aExtensionsOnDiskOrDb,
|
||||
];
|
||||
|
||||
$this->CallAndCheckTwice($oWizStepModulesChoice, null, $expected);
|
||||
$this->CallAndCheckTwice($oWizStepModulesChoice, 1, null);
|
||||
}
|
||||
|
||||
private function GivenWizStepModulesChoiceWithoutXmlInstallation(array $aExtensionsOnDiskOrDb): WizStepModulesChoiceFake
|
||||
{
|
||||
$oExtensionsMap = $this->createMock(iTopExtensionsMap::class);
|
||||
$oExtensionsMap->expects($this->once())
|
||||
->method('GetAllExtensionsOptionInfo')
|
||||
->willReturn($aExtensionsOnDiskOrDb);
|
||||
|
||||
$oWizard = new WizardController('', '');
|
||||
$oWizStepModulesChoice = new WizStepModulesChoiceFake($oWizard, '');
|
||||
$oWizStepModulesChoice->setExtensionMap($oExtensionsMap);
|
||||
|
||||
return $oWizStepModulesChoice;
|
||||
}
|
||||
|
||||
public static function PackageWithInstallationXMLProvider()
|
||||
{
|
||||
require_once __DIR__.'/../../../../approot.inc.php';
|
||||
require_once APPROOT.'setup/parameters.class.inc.php';
|
||||
|
||||
$aUsecases = [];
|
||||
|
||||
$aUsecases["[no step] with extensions"] = [
|
||||
'iGetStepInfoIdxArg' => null,
|
||||
'expected' => self::GetStep(0),
|
||||
];
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$aUsecases["[step $i] with extensions"] = [
|
||||
'iGetStepInfoIdxArg' => $i,
|
||||
'expected' => self::GetStep($i),
|
||||
];
|
||||
}
|
||||
|
||||
$aUsecases["[step 6] with extensions => NO STEP ANYMORE"] = [
|
||||
'iGetStepInfoIdxArg' => 6,
|
||||
'expected' => null,
|
||||
'iGetAllExtensionsOptionInfoCallCount' => 1,
|
||||
];
|
||||
|
||||
return $aUsecases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider PackageWithInstallationXMLProvider
|
||||
*/
|
||||
public function testGetStepInfo_PackageWithInstallationXMLWithExtensions($iGetStepInfoIdxArg, $expected, $iGetAllExtensionsOptionInfoCallCount = 0)
|
||||
{
|
||||
$aExtensionsOnDiskOrDb = self::GivenExtensionsOnDisk();
|
||||
$oWizStepModulesChoice = $this->GivenWizStepModulesChoiceWithXmlInstallation($aExtensionsOnDiskOrDb, $iGetAllExtensionsOptionInfoCallCount);
|
||||
|
||||
$this->CallAndCheckTwice($oWizStepModulesChoice, $iGetStepInfoIdxArg, $expected);
|
||||
}
|
||||
|
||||
public function testGetStepInfo_PackageWithInstallationXML_AfterLastStepWithExtensions()
|
||||
{
|
||||
$expected = [
|
||||
'title' => 'Extensions',
|
||||
'description' => '<h2>Select additional extensions to install. You can launch the installation again to install new extensions or remove installed ones.</h2>',
|
||||
'banner' => '/images/icons/icons8-puzzle.svg',
|
||||
'options' => self::GivenExtensionsOnDisk(),
|
||||
];
|
||||
|
||||
$aExtensionsOnDiskOrDb = self::GivenExtensionsOnDisk();
|
||||
$oWizStepModulesChoice = $this->GivenWizStepModulesChoiceWithXmlInstallation($aExtensionsOnDiskOrDb, 1);
|
||||
|
||||
$this->CallAndCheckTwice($oWizStepModulesChoice, 5, $expected);
|
||||
}
|
||||
|
||||
public function testGetStepInfo_PackageWithInstallationXMLAfterLastStepWithoutExtensions()
|
||||
{
|
||||
$oWizStepModulesChoice = $this->GivenWizStepModulesChoiceWithXmlInstallation([], 1);
|
||||
|
||||
$this->CallAndCheckTwice($oWizStepModulesChoice, 5, null);
|
||||
}
|
||||
|
||||
public function testGetStepInfo_PackageWithInstallationXML_MakeSureNextStepIsAlsoCached()
|
||||
{
|
||||
$aExtensionsOnDiskOrDb = self::GivenExtensionsOnDisk();
|
||||
$oWizStepModulesChoice = $this->GivenWizStepModulesChoiceWithXmlInstallation($aExtensionsOnDiskOrDb, 1);
|
||||
|
||||
$this->CallAndCheckTwice($oWizStepModulesChoice, 4, self::GetStep(4));
|
||||
|
||||
$expected = [
|
||||
'title' => 'Extensions',
|
||||
'description' => '<h2>Select additional extensions to install. You can launch the installation again to install new extensions or remove installed ones.</h2>',
|
||||
'banner' => '/images/icons/icons8-puzzle.svg',
|
||||
'options' => $aExtensionsOnDiskOrDb,
|
||||
];
|
||||
$this->CallAndCheckTwice($oWizStepModulesChoice, 5, $expected);
|
||||
}
|
||||
|
||||
private static function GivenExtensionsOnDisk(): array
|
||||
{
|
||||
return [
|
||||
'itop-ext-added1' => [
|
||||
'installed' => false,
|
||||
],
|
||||
'itop-ext-added2' => [
|
||||
'installed' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function GivenWizStepModulesChoiceWithXmlInstallation(array $aExtensionsOnDiskOrDb, $iGetAllExtensionsOptionInfoCallCount): WizStepModulesChoiceFake
|
||||
{
|
||||
$oExtensionsMap = $this->createMock(iTopExtensionsMap::class);
|
||||
$oExtensionsMap->expects($this->exactly($iGetAllExtensionsOptionInfoCallCount))
|
||||
->method('GetAllExtensionsOptionInfo')
|
||||
->willReturn($aExtensionsOnDiskOrDb);
|
||||
|
||||
$oWizard = new WizardController('', '');
|
||||
//needed to find installation.xml
|
||||
$oWizard->SetParameter('source_dir', __DIR__.'/ressources');
|
||||
$oWizStepModulesChoice = new WizStepModulesChoiceFake($oWizard, '');
|
||||
$oWizStepModulesChoice->setExtensionMap($oExtensionsMap);
|
||||
|
||||
return $oWizStepModulesChoice;
|
||||
}
|
||||
|
||||
private function CallAndCheckTwice($oStep, $iGetStepInfoIdxArg, $expected)
|
||||
{
|
||||
$aRes = $this->InvokeNonPublicMethod(WizStepModulesChoiceFake::class, 'GetStepInfo', $oStep, [$iGetStepInfoIdxArg]);
|
||||
$this->assertEquals($expected, $aRes, "step:".$iGetStepInfoIdxArg);
|
||||
|
||||
$aRes = $this->InvokeNonPublicMethod(WizStepModulesChoiceFake::class, 'GetStepInfo', $oStep, [$iGetStepInfoIdxArg]);
|
||||
$this->assertEquals($expected, $aRes, "(2nd call) step:".$iGetStepInfoIdxArg);
|
||||
}
|
||||
|
||||
private static function GetStep($index)
|
||||
{
|
||||
$aParams = new XMLParameters(__DIR__.'/ressources/installation.xml');
|
||||
$aSteps = $aParams->Get('steps', []);
|
||||
|
||||
return $aSteps[$index] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup\FeatureRemoval;
|
||||
|
||||
use Combodo\iTop\Setup\FeatureRemoval\DryRemovalRuntimeEnvironment;
|
||||
use Combodo\iTop\Setup\FeatureRemoval\InplaceSetupAudit;
|
||||
use Combodo\iTop\Setup\FeatureRemoval\ModelReflectionSerializer;
|
||||
use Combodo\iTop\Setup\FeatureRemoval\SetupAudit;
|
||||
use Combodo\iTop\Test\UnitTest\ItopCustomDatamodelTestCase;
|
||||
use Combodo\iTop\Test\UnitTest\Service\UnitTestRunTimeEnvironment;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
class SetupAuditTest extends ItopCustomDatamodelTestCase
|
||||
{
|
||||
@@ -38,6 +40,7 @@ class SetupAuditTest extends ItopCustomDatamodelTestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->RequireOnceItopFile('/setup/feature_removal/SetupAudit.php');
|
||||
$this->RequireOnceItopFile('/setup/feature_removal/InplaceSetupAudit.php');
|
||||
$this->RequireOnceItopFile('/setup/feature_removal/DryRemovalRuntimeEnvironment.php');
|
||||
}
|
||||
|
||||
@@ -52,7 +55,7 @@ class SetupAuditTest extends ItopCustomDatamodelTestCase
|
||||
$oDryRemovalRuntimeEnvt->Prepare($this->GetTestEnvironment(), ['nominal_ext1', 'finalclass_ext2']);
|
||||
$oDryRemovalRuntimeEnvt->CompileFrom($this->GetTestEnvironment());
|
||||
|
||||
$oSetupAudit = new SetupAudit(\MetaModel::GetEnvironment());
|
||||
$oSetupAudit = new SetupAudit(MetaModel::GetEnvironment(), DryRemovalRuntimeEnvironment::DRY_REMOVAL_AUDIT_ENV);
|
||||
|
||||
$expected = [
|
||||
"Feature1Module1MyClass",
|
||||
@@ -67,13 +70,25 @@ class SetupAuditTest extends ItopCustomDatamodelTestCase
|
||||
$this->assertEqualsCanonicalizing($expected, $oSetupAudit->GetIssues());
|
||||
}
|
||||
|
||||
public function testGetRemovedClassesFromSetupWizard()
|
||||
{
|
||||
$sEnv = MetaModel::GetEnvironment();
|
||||
|
||||
$aClassesBeforeRemoval = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($sEnv);
|
||||
$aClassesBeforeRemoval[] = "GabuZomeu";
|
||||
|
||||
$oSetupAudit = new InplaceSetupAudit($aClassesBeforeRemoval, $sEnv);
|
||||
$oSetupAudit->ComputeClasses();
|
||||
$this->assertEquals(["GabuZomeu"], $oSetupAudit->GetRemovedClasses());
|
||||
}
|
||||
|
||||
public function testGetIssues()
|
||||
{
|
||||
$sUID = "AuditExtensionsCleanupRules_".uniqid();
|
||||
$oOrg = $this->CreateOrganization($sUID);
|
||||
$this->createObject('FinalClassFeature1Module1MyFinalClassFromLocation', ['org_id' => $oOrg->GetKey(), 'name' => $sUID, 'name2' => uniqid()]);
|
||||
|
||||
$oSetupAudit = new SetupAudit(\MetaModel::GetEnvironment());
|
||||
$oSetupAudit = new SetupAudit(MetaModel::GetEnvironment(), DryRemovalRuntimeEnvironment::DRY_REMOVAL_AUDIT_ENV);
|
||||
$aRemovedClasses = [
|
||||
"Feature1Module1MyClass",
|
||||
"FinalClassFeature1Module1MyClass",
|
||||
@@ -99,7 +114,7 @@ class SetupAuditTest extends ItopCustomDatamodelTestCase
|
||||
$this->createObject('FinalClassFeature1Module1MyFinalClassFromLocation', ['org_id' => $oOrg->GetKey(), 'name' => $sUID, 'name2' => uniqid()]);
|
||||
$this->createObject('FinalClassFeature2Module1MyFinalClassFromLocation', ['org_id' => $oOrg->GetKey(), 'name' => $sUID, 'name2' => uniqid()]);
|
||||
|
||||
$oSetupAudit = new SetupAudit(\MetaModel::GetEnvironment());
|
||||
$oSetupAudit = new SetupAudit(MetaModel::GetEnvironment(), DryRemovalRuntimeEnvironment::DRY_REMOVAL_AUDIT_ENV);
|
||||
$aRemovedClasses = [
|
||||
"Feature1Module1MyClass",
|
||||
"FinalClassFeature1Module1MyClass",
|
||||
@@ -111,8 +126,9 @@ class SetupAuditTest extends ItopCustomDatamodelTestCase
|
||||
//avoid setup dry computation
|
||||
$this->SetNonPublicProperty($oSetupAudit, 'aRemovedClasses', $aRemovedClasses);
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage('FinalClassFeature1Module1MyFinalClassFromLocation');
|
||||
$oSetupAudit->GetIssues(true);
|
||||
$expected = [
|
||||
"FinalClassFeature1Module1MyFinalClassFromLocation" => 1,
|
||||
];
|
||||
$this->assertEqualsCanonicalizing($expected, $oSetupAudit->GetIssues(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
|
||||
class iTopExtensionTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('/setup/unattended-install/InstallationFileService.php');
|
||||
ModuleDiscovery::ResetCache();
|
||||
}
|
||||
|
||||
public function testCanBeUninstalledDefaultValueIsTrue()
|
||||
{
|
||||
$oExtension = new iTopExtension();
|
||||
$this->assertTrue($oExtension->CanBeUninstalled(), 'An extension should be uninstallable by default.');
|
||||
}
|
||||
|
||||
public function testCanBeUninstalledReturnTrueWhenAllModulesCanBeUninstalled()
|
||||
{
|
||||
$oExtension = new iTopExtension();
|
||||
$oExtension->aModuleInfo['combodo-test-yes1'] = [
|
||||
'uninstallable' => 'yes',
|
||||
];
|
||||
$oExtension->aModuleInfo['combodo-test-yes2'] = [
|
||||
'uninstallable' => 'yes',
|
||||
];
|
||||
$this->assertTrue($oExtension->CanBeUninstalled(), 'An extension should be considered uninstallable if all of its modules are uninstallable.');
|
||||
}
|
||||
|
||||
public function testCanBeUninstalledReturnFalseWhenAtLeastOneModuleCannotBeUninstalled()
|
||||
{
|
||||
$oExtension = new iTopExtension();
|
||||
$oExtension->aModuleInfo['combodo-test-yes'] = [
|
||||
'uninstallable' => 'yes',
|
||||
];
|
||||
$oExtension->aModuleInfo['combodo-test-no'] = [
|
||||
'uninstallable' => 'no',
|
||||
];
|
||||
$this->assertFalse($oExtension->CanBeUninstalled(), 'An extension should be considered non-uninstallable if at least one of its modules is not uninstallable.');
|
||||
}
|
||||
|
||||
public function testCanBeUninstalledAnyValueDifferentThanYesIsConsideredFalse()
|
||||
{
|
||||
$oExtension = new iTopExtension();
|
||||
$oExtension->aModuleInfo['combodo-test-maybe'] = [
|
||||
'uninstallable' => 'maybe',
|
||||
];
|
||||
$this->assertFalse($oExtension->CanBeUninstalled(), 'Any value in the uninstallable flag different than yes should be considered false.');
|
||||
}
|
||||
|
||||
public function testCanBeUninstalledExtensionValueOverwriteModulesValue()
|
||||
{
|
||||
$oExtension = new iTopExtension();
|
||||
$oExtension->bCanBeUninstalled = true;
|
||||
$oExtension->aModuleInfo['combodo-test-no'] = [
|
||||
'uninstallable' => 'no',
|
||||
];
|
||||
$this->assertTrue($oExtension->CanBeUninstalled(), 'The uninstallable flag provided in the extension should prevail over those defined in the modules.');
|
||||
|
||||
$oExtension = new iTopExtension();
|
||||
$oExtension->bCanBeUninstalled = false;
|
||||
$oExtension->aModuleInfo['combodo-test-yes'] = [
|
||||
'uninstallable' => 'yes',
|
||||
];
|
||||
$this->assertFalse($oExtension->CanBeUninstalled(), 'The uninstallable flag provided in the extension should prevail over those defined in the modules.');
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,11 @@ class iTopExtensionsMapFake extends iTopExtensionsMap
|
||||
public static function createFromArray($aExtensions)
|
||||
{
|
||||
$oMap = new static();
|
||||
|
||||
foreach ($aExtensions as $sCode => $aExtension) {
|
||||
$oExtension = new iTopExtension();
|
||||
$oExtension->sCode = $sCode;
|
||||
$oExtension->sLabel = $sCode;
|
||||
$oExtension->bInstalled = $aExtension['installed'];
|
||||
$oExtension->aModules = $aExtension['modules'] ?? [];
|
||||
$oExtension->bCanBeUninstalled = $aExtension['uninstallable'] ?? null;
|
||||
|
||||
@@ -4,15 +4,13 @@ namespace Combodo\iTop\Test\UnitTest\Setup;
|
||||
|
||||
use AnalyzeInstallation;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use ModuleInstallationService;
|
||||
use ModuleInstallationRepository;
|
||||
|
||||
class AnalyzeInstallationTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('setup/AnalyzeInstallation.php');
|
||||
$this->RequireOnceItopFile('setup/ModuleInstallationService.php');
|
||||
$this->RequireOnceItopFile('setup/modulediscovery.class.inc.php');
|
||||
$this->RequireOnceItopFile('setup/runtimeenv.class.inc.php');
|
||||
}
|
||||
@@ -151,7 +149,7 @@ class AnalyzeInstallationTest extends ItopTestCase
|
||||
|
||||
$this->SetNonPublicProperty(AnalyzeInstallation::GetInstance(), "aAvailableModules", $aAvailableModules);
|
||||
//$aModules = json_decode(file_get_contents(__DIR__.'/ressources/priv_modules2.json'), true);
|
||||
$this->SetNonPublicProperty(ModuleInstallationService::GetInstance(), "aSelectInstall", $aInstalledModules);
|
||||
$this->SetNonPublicProperty(ModuleInstallationRepository::GetInstance(), "aSelectInstall", $aInstalledModules);
|
||||
|
||||
$oConfig = $this->createMock(\Config::class);
|
||||
|
||||
@@ -0,0 +1,430 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
class InstallationChoicesToModuleConverterTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->RequireOnceItopFile('/setup/moduleinstallation/InstallationChoicesToModuleConverter.php');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
ModuleDiscovery::ResetCache();
|
||||
}
|
||||
|
||||
//integration test
|
||||
public function testGetModulesWithXmlInstallationFile_UsualCustomerPackagesWithNonITIL()
|
||||
{
|
||||
$aSearchDirs = $this->GivenModuleDiscoveryInit();
|
||||
|
||||
$aInstalledModules = InstallationChoicesToModuleConverter::GetInstance()->GetModules(
|
||||
$this->GivenNonItilChoices(),
|
||||
$aSearchDirs,
|
||||
__DIR__.'/ressources/installation.xml'
|
||||
);
|
||||
|
||||
$aExpected = [
|
||||
'authent-cas/3.3.0',
|
||||
'authent-external/3.3.0',
|
||||
'authent-ldap/3.3.0',
|
||||
'authent-local/3.3.0',
|
||||
'combodo-backoffice-darkmoon-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme/3.3.0',
|
||||
'itop-attachments/3.3.0',
|
||||
'itop-backup/3.3.0',
|
||||
'itop-config/3.3.0',
|
||||
'itop-files-information/3.3.0',
|
||||
'itop-portal-base/3.3.0',
|
||||
'itop-portal/3.3.0',
|
||||
'itop-profiles-itil/3.3.0',
|
||||
'itop-sla-computation/3.3.0',
|
||||
'itop-structure/3.3.0',
|
||||
'itop-themes-compat/3.3.0',
|
||||
'itop-tickets/3.3.0',
|
||||
'itop-welcome-itil/3.3.0',
|
||||
'combodo-db-tools/3.3.0',
|
||||
'itop-config-mgmt/3.3.0',
|
||||
'itop-core-update/3.3.0',
|
||||
'itop-datacenter-mgmt/3.3.0',
|
||||
'itop-endusers-devices/3.3.0',
|
||||
'itop-faq-light/3.3.0',
|
||||
'itop-hub-connector/3.3.0',
|
||||
'itop-knownerror-mgmt/3.3.0',
|
||||
'itop-oauth-client/3.3.0',
|
||||
'itop-request-mgmt/3.3.0',
|
||||
'itop-service-mgmt/3.3.0',
|
||||
'itop-storage-mgmt/3.3.0',
|
||||
'itop-virtualization-mgmt/3.3.0',
|
||||
'itop-bridge-cmdb-services/3.3.0',
|
||||
'itop-bridge-cmdb-ticket/3.3.0',
|
||||
'itop-bridge-datacenter-mgmt-services/3.3.0',
|
||||
'itop-bridge-endusers-devices-services/3.3.0',
|
||||
'itop-bridge-storage-mgmt-services/3.3.0',
|
||||
'itop-bridge-virtualization-mgmt-services/3.3.0',
|
||||
'itop-bridge-virtualization-storage/3.3.0',
|
||||
'itop-change-mgmt/3.3.0',
|
||||
];
|
||||
$this->assertEquals($aExpected, $aInstalledModules);
|
||||
}
|
||||
|
||||
//integration test
|
||||
public function testGetModulesWithXmlInstallationFile_UsualCustomerPackagesWithITIL()
|
||||
{
|
||||
$aSearchDirs = $this->GivenModuleDiscoveryInit();
|
||||
|
||||
$aInstalledModules = InstallationChoicesToModuleConverter::GetInstance()->GetModules(
|
||||
$this->GivenItilChoices(),
|
||||
$aSearchDirs,
|
||||
__DIR__.'/ressources/installation.xml'
|
||||
);
|
||||
|
||||
$aExpected = [
|
||||
'authent-cas/3.3.0',
|
||||
'authent-external/3.3.0',
|
||||
'authent-ldap/3.3.0',
|
||||
'authent-local/3.3.0',
|
||||
'combodo-backoffice-darkmoon-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme/3.3.0',
|
||||
'itop-attachments/3.3.0',
|
||||
'itop-backup/3.3.0',
|
||||
'itop-config/3.3.0',
|
||||
'itop-files-information/3.3.0',
|
||||
'itop-portal-base/3.3.0',
|
||||
'itop-portal/3.3.0',
|
||||
'itop-profiles-itil/3.3.0',
|
||||
'itop-sla-computation/3.3.0',
|
||||
'itop-structure/3.3.0',
|
||||
'itop-themes-compat/3.3.0',
|
||||
'itop-tickets/3.3.0',
|
||||
'itop-welcome-itil/3.3.0',
|
||||
'combodo-db-tools/3.3.0',
|
||||
'itop-config-mgmt/3.3.0',
|
||||
'itop-core-update/3.3.0',
|
||||
'itop-datacenter-mgmt/3.3.0',
|
||||
'itop-endusers-devices/3.3.0',
|
||||
'itop-hub-connector/3.3.0',
|
||||
'itop-incident-mgmt-itil/3.3.0',
|
||||
'itop-oauth-client/3.3.0',
|
||||
'itop-request-mgmt-itil/3.3.0',
|
||||
'itop-service-mgmt/3.3.0',
|
||||
'itop-storage-mgmt/3.3.0',
|
||||
'itop-virtualization-mgmt/3.3.0',
|
||||
'itop-bridge-cmdb-services/3.3.0',
|
||||
'itop-bridge-cmdb-ticket/3.3.0',
|
||||
'itop-bridge-datacenter-mgmt-services/3.3.0',
|
||||
'itop-bridge-endusers-devices-services/3.3.0',
|
||||
'itop-bridge-storage-mgmt-services/3.3.0',
|
||||
'itop-bridge-virtualization-mgmt-services/3.3.0',
|
||||
'itop-bridge-virtualization-storage/3.3.0',
|
||||
'itop-change-mgmt-itil/3.3.0',
|
||||
'itop-full-itil/3.3.0',
|
||||
];
|
||||
$this->assertEquals($aExpected, $aInstalledModules);
|
||||
}
|
||||
|
||||
//integration test
|
||||
public function testGetModulesWithXmlInstallationFile_LegacyPackages()
|
||||
{
|
||||
$aSearchDirs = $this->GivenModuleDiscoveryInit();
|
||||
|
||||
//no choices means all default ones...
|
||||
$aNoInstallationChoices = [];
|
||||
|
||||
$aInstalledModules = InstallationChoicesToModuleConverter::GetInstance()->GetModules(
|
||||
$aNoInstallationChoices,
|
||||
$aSearchDirs
|
||||
);
|
||||
|
||||
$aExpected = [
|
||||
'authent-cas/3.3.0',
|
||||
'authent-external/3.3.0',
|
||||
'authent-ldap/3.3.0',
|
||||
'authent-local/3.3.0',
|
||||
'combodo-backoffice-darkmoon-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme/3.3.0',
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme/3.3.0',
|
||||
'itop-backup/3.3.0',
|
||||
'itop-config/3.3.0',
|
||||
'itop-files-information/3.3.0',
|
||||
'itop-portal-base/3.3.0',
|
||||
'itop-profiles-itil/3.3.0',
|
||||
'itop-sla-computation/3.3.0',
|
||||
'itop-structure/3.3.0',
|
||||
'itop-welcome-itil/3.3.0',
|
||||
];
|
||||
$this->assertEquals($aExpected, $aInstalledModules);
|
||||
}
|
||||
|
||||
public function testIsDefaultModule_RootModuleShouldNeverBeDefault()
|
||||
{
|
||||
$sModuleId = ROOT_MODULE;
|
||||
$aModuleInfo = ['category' => 'authentication', 'visible' => false];
|
||||
$this->assertFalse($this->CallIsDefault($sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
public function testIsDefaultModule_AutoselectShouldNeverBeDefault()
|
||||
{
|
||||
$sModuleId = 'autoselect_module';
|
||||
$aModuleInfo = ['category' => 'authentication', 'visible' => false, 'auto_select' => true];
|
||||
$this->assertFalse($this->CallIsDefault($sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
public function testIsDefaultModule_AuthenticationModuleShouldBeDefault()
|
||||
{
|
||||
$sModuleId = 'authentication_module';
|
||||
$aModuleInfo = ['category' => 'authentication', 'visible' => true];
|
||||
$this->assertTrue($this->CallIsDefault($sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
public function testIsDefaultModule_HiddenModuleShouldBeDefault()
|
||||
{
|
||||
$sModuleId = 'hidden_module';
|
||||
$aModuleInfo = ['category' => 'business', 'visible' => false];
|
||||
$this->assertTrue($this->CallIsDefault($sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
public function testIsDefaultModule_NonModuleDefaultCase()
|
||||
{
|
||||
$sModuleId = 'any_module';
|
||||
$aModuleInfo = ['category' => 'business', 'visible' => true];
|
||||
$this->assertFalse($this->CallIsDefault($sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
private function CallIsDefault($sModuleId, $aModuleInfo): bool
|
||||
{
|
||||
return $this->InvokeNonPublicMethod(InstallationChoicesToModuleConverter::class, 'IsDefaultModule', InstallationChoicesToModuleConverter::GetInstance(), [$sModuleId, $aModuleInfo]);
|
||||
}
|
||||
|
||||
public function testIsAutoSelectedModule_RootModuleShouldNeverBeAutoSelect()
|
||||
{
|
||||
$sModuleId = ROOT_MODULE;
|
||||
$aModuleInfo = ['auto_select' => true];
|
||||
$this->assertFalse($this->CallIsAutoSelectedModule([], $sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
public function testIsAutoSelectedModule_NoAutoselectByDefault()
|
||||
{
|
||||
$sModuleId = 'autoselect_module';
|
||||
$aModuleInfo = [];
|
||||
$this->assertFalse($this->CallIsAutoSelectedModule([], $sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* cf DependencyExpression dedicated tests
|
||||
*/
|
||||
public function testIsAutoSelectedModule_UseInstalledModulesForComputation()
|
||||
{
|
||||
$sModuleId = "any_module";
|
||||
$aModuleInfo = ['auto_select' => 'SetupInfo::ModuleIsSelected("a") && SetupInfo::ModuleIsSelected("b")'];
|
||||
$aInstalledModules = ['a' => true, 'b' => true];
|
||||
$this->assertTrue($this->CallIsAutoSelectedModule($aInstalledModules, $sModuleId, $aModuleInfo));
|
||||
}
|
||||
|
||||
private function CallIsAutoSelectedModule($aInstalledModules, $sModuleId, $aModuleInfo): bool
|
||||
{
|
||||
return $this->InvokeNonPublicMethod(InstallationChoicesToModuleConverter::class, 'IsAutoSelectedModule', InstallationChoicesToModuleConverter::GetInstance(), [$aInstalledModules, $sModuleId, $aModuleInfo]);
|
||||
}
|
||||
|
||||
public function testProcessInstallationChoices_Default()
|
||||
{
|
||||
$aRes = [];
|
||||
$aInstallationDescription = $this->GivenInstallationChoiceDescription();
|
||||
|
||||
$this->CallGetModuleNamesFromInstallationChoices([], $aInstallationDescription, $aRes);
|
||||
|
||||
$aExpected = [
|
||||
'combodo-backoffice-darkmoon-theme' => true,
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme' => true,
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme' => true,
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme' => true,
|
||||
'itop-attachments' => true,
|
||||
'itop-backup' => true,
|
||||
'itop-config' => true,
|
||||
'itop-files-information' => true,
|
||||
'itop-profiles-itil' => true,
|
||||
'itop-structure' => true,
|
||||
'itop-themes-compat' => true,
|
||||
'itop-tickets' => true,
|
||||
'itop-welcome-itil' => true,
|
||||
'combodo-db-tools' => true,
|
||||
'itop-config-mgmt' => true,
|
||||
'itop-core-update' => true,
|
||||
'itop-hub-connector' => true,
|
||||
'itop-oauth-client' => true,
|
||||
'combodo-password-expiration' => true,
|
||||
'combodo-webhook-integration' => true,
|
||||
'combodo-my-account-user-info' => true,
|
||||
'authent-token' => true,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testProcessInstallationChoices_NonItilChoices()
|
||||
{
|
||||
$aRes = [];
|
||||
$aInstallationDescription = $this->GivenInstallationChoiceDescription();
|
||||
|
||||
$this->CallGetModuleNamesFromInstallationChoices($this->GivenNonItilChoices(), $aInstallationDescription, $aRes);
|
||||
|
||||
$aExpected = [
|
||||
'combodo-backoffice-darkmoon-theme' => true,
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme' => true,
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme' => true,
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme' => true,
|
||||
'itop-attachments' => true,
|
||||
'itop-backup' => true,
|
||||
'itop-config' => true,
|
||||
'itop-files-information' => true,
|
||||
'itop-profiles-itil' => true,
|
||||
'itop-structure' => true,
|
||||
'itop-themes-compat' => true,
|
||||
'itop-tickets' => true,
|
||||
'itop-welcome-itil' => true,
|
||||
'combodo-db-tools' => true,
|
||||
'itop-config-mgmt' => true,
|
||||
'itop-core-update' => true,
|
||||
'itop-hub-connector' => true,
|
||||
'itop-oauth-client' => true,
|
||||
'combodo-password-expiration' => true,
|
||||
'combodo-webhook-integration' => true,
|
||||
'combodo-my-account-user-info' => true,
|
||||
'authent-token' => true,
|
||||
'itop-datacenter-mgmt' => true,
|
||||
'itop-endusers-devices' => true,
|
||||
'itop-storage-mgmt' => true,
|
||||
'itop-virtualization-mgmt' => true,
|
||||
'itop-service-mgmt' => true,
|
||||
'itop-request-mgmt' => true,
|
||||
'itop-portal' => true,
|
||||
'itop-portal-base' => true,
|
||||
'itop-change-mgmt' => true,
|
||||
'itop-faq-light' => true,
|
||||
'itop-knownerror-mgmt' => true,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
public function testProcessInstallationChoices_ItilChoices()
|
||||
{
|
||||
$aRes = [];
|
||||
$aInstallationDescription = $this->GivenInstallationChoiceDescription();
|
||||
|
||||
$this->CallGetModuleNamesFromInstallationChoices($this->GivenItilChoices(), $aInstallationDescription, $aRes);
|
||||
|
||||
$aExpected = [
|
||||
'combodo-backoffice-darkmoon-theme' => true,
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme' => true,
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme' => true,
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme' => true,
|
||||
'itop-attachments' => true,
|
||||
'itop-backup' => true,
|
||||
'itop-config' => true,
|
||||
'itop-files-information' => true,
|
||||
'itop-profiles-itil' => true,
|
||||
'itop-structure' => true,
|
||||
'itop-themes-compat' => true,
|
||||
'itop-tickets' => true,
|
||||
'itop-welcome-itil' => true,
|
||||
'combodo-db-tools' => true,
|
||||
'itop-config-mgmt' => true,
|
||||
'itop-core-update' => true,
|
||||
'itop-hub-connector' => true,
|
||||
'itop-oauth-client' => true,
|
||||
'combodo-password-expiration' => true,
|
||||
'combodo-webhook-integration' => true,
|
||||
'combodo-my-account-user-info' => true,
|
||||
'authent-token' => true,
|
||||
'itop-datacenter-mgmt' => true,
|
||||
'itop-endusers-devices' => true,
|
||||
'itop-storage-mgmt' => true,
|
||||
'itop-virtualization-mgmt' => true,
|
||||
'itop-service-mgmt' => true,
|
||||
'itop-portal' => true,
|
||||
'itop-portal-base' => true,
|
||||
'itop-request-mgmt-itil' => true,
|
||||
'itop-incident-mgmt-itil' => true,
|
||||
'itop-change-mgmt-itil' => true,
|
||||
];
|
||||
$this->assertEquals($aExpected, $aRes);
|
||||
}
|
||||
|
||||
private function CallGetModuleNamesFromInstallationChoices(array $aInstallationChoices, array $aInstallationDescription, array &$aModuleNames)
|
||||
{
|
||||
$this->InvokeNonPublicMethod(
|
||||
InstallationChoicesToModuleConverter::class,
|
||||
'GetModuleNamesFromInstallationChoices',
|
||||
InstallationChoicesToModuleConverter::GetInstance(),
|
||||
[$aInstallationChoices, $aInstallationDescription, &$aModuleNames]
|
||||
);
|
||||
}
|
||||
|
||||
private function GivenInstallationChoiceDescription(): array
|
||||
{
|
||||
$oXMLParameters = new XMLParameters(__DIR__."/ressources/installation.xml");
|
||||
return $oXMLParameters->Get('steps', []);
|
||||
}
|
||||
|
||||
private function GivenAllModules(): array
|
||||
{
|
||||
return json_decode(file_get_contents(__DIR__.'/ressources/available_modules.json'), true);
|
||||
}
|
||||
|
||||
private function GivenNonItilChoices(): array
|
||||
{
|
||||
return [
|
||||
'itop-config-mgmt-core',
|
||||
'itop-config-mgmt-datacenter',
|
||||
'itop-config-mgmt-end-user',
|
||||
'itop-config-mgmt-storage',
|
||||
'itop-config-mgmt-virtualization',
|
||||
'itop-service-mgmt-enterprise',
|
||||
'itop-ticket-mgmt-simple-ticket',
|
||||
'itop-ticket-mgmt-simple-ticket-enhanced-portal',
|
||||
'itop-change-mgmt-simple',
|
||||
'itop-kown-error-mgmt',
|
||||
];
|
||||
}
|
||||
|
||||
private function GivenItilChoices(): array
|
||||
{
|
||||
return [
|
||||
'itop-config-mgmt-datacenter',
|
||||
'itop-config-mgmt-end-user',
|
||||
'itop-config-mgmt-storage',
|
||||
'itop-config-mgmt-virtualization',
|
||||
'itop-service-mgmt-enterprise',
|
||||
'itop-ticket-mgmt-itil',
|
||||
'itop-ticket-mgmt-itil-user-request',
|
||||
'itop-ticket-mgmt-itil-incident',
|
||||
'itop-ticket-mgmt-itil-enhanced-portal',
|
||||
'itop-change-mgmt-itil',
|
||||
'itop-config-mgmt-core',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
private function GivenModuleDiscoveryInit(): array
|
||||
{
|
||||
$aSearchDirs = [APPROOT.'datamodels/2.x'];
|
||||
$this->SetNonPublicStaticProperty(ModuleDiscovery::class, 'm_aSearchDirs', $aSearchDirs);
|
||||
$aAllModules = $this->GivenAllModules();
|
||||
$this->SetNonPublicStaticProperty(ModuleDiscovery::class, 'm_aModules', $aAllModules);
|
||||
return $aSearchDirs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<installation>
|
||||
<steps type="array">
|
||||
<step>
|
||||
<title>Configuration Management options</title>
|
||||
<description><![CDATA[<h2>The options below allow you to configure the type of elements that are to be managed inside iTop.</h2>]]></description>
|
||||
<banner>/images/icons/icons8-apps-tab.svg</banner>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-core</extension_code>
|
||||
<title>Configuration Management Core</title>
|
||||
<description>All the base objects that are mandatory in the iTop CMDB: Organizations, Locations, Teams, Persons, etc.</description>
|
||||
<modules type="array">
|
||||
<module>combodo-backoffice-darkmoon-theme</module>
|
||||
<module>combodo-backoffice-fullmoon-high-contrast-theme</module>
|
||||
<module>combodo-backoffice-fullmoon-protanopia-deuteranopia-theme</module>
|
||||
<module>combodo-backoffice-fullmoon-tritanopia-theme</module>
|
||||
<module>combodo-db-tools</module>
|
||||
<module>combodo-password-expiration</module>
|
||||
<module>combodo-webhook-integration</module>
|
||||
<module>itop-attachments</module>
|
||||
<module>itop-backup</module>
|
||||
<module>itop-config</module>
|
||||
<module>itop-config-mgmt</module>
|
||||
<module>itop-core-update</module>
|
||||
<module>itop-files-information</module>
|
||||
<module>itop-hub-connector</module>
|
||||
<module>itop-oauth-client</module>
|
||||
<module>itop-profiles-itil</module>
|
||||
<module>itop-structure</module>
|
||||
<module>itop-themes-compat</module>
|
||||
<module>itop-tickets</module>
|
||||
<module>itop-welcome-itil</module>
|
||||
<module>combodo-my-account-user-info</module>
|
||||
<module>authent-token</module>
|
||||
</modules>
|
||||
<mandatory>true</mandatory>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-datacenter</extension_code>
|
||||
<title>Data Center Devices</title>
|
||||
<description>Manage Data Center devices such as Racks, Enclosures, PDUs, etc.</description>
|
||||
<modules type="array">
|
||||
<module>itop-datacenter-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-end-user</extension_code>
|
||||
<title>End-User Devices</title>
|
||||
<description>Manage devices related to end-users: PCs, Phones, Tablets, etc.</description>
|
||||
<modules type="array">
|
||||
<module>itop-endusers-devices</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-storage</extension_code>
|
||||
<title>Storage Devices</title>
|
||||
<description>Manage storage devices such as NAS, SAN Switches, Tape Libraries and Tapes, etc.</description>
|
||||
<modules type="array">
|
||||
<module>itop-storage-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-virtualization</extension_code>
|
||||
<title>Virtualization</title>
|
||||
<description>Manage Hypervisors, Virtual Machines and Farms.</description>
|
||||
<modules type="array">
|
||||
<module>itop-virtualization-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
</options>
|
||||
</step>
|
||||
<step>
|
||||
<title>Service Management options</title>
|
||||
<description><![CDATA[<h2>Select the choice that best describes the relationships between the services and the IT infrastructure in your IT environment.</h2>]]></description>
|
||||
<banner>/images/icons/icons8-services.svg</banner>
|
||||
<alternatives type="array">
|
||||
<choice>
|
||||
<extension_code>itop-service-mgmt-enterprise</extension_code>
|
||||
<title>Service Management for Enterprises</title>
|
||||
<description>Select this option if the IT delivers services based on a shared infrastructure. For example if different organizations within your company subscribe to services (like Mail and Print services) delivered by a single shared backend.</description>
|
||||
<modules type="array">
|
||||
<module>itop-service-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-service-mgmt-service-provider</extension_code>
|
||||
<title>Service Management for Service Providers</title>
|
||||
<description>Select this option if the IT manages the infrastructure of independent customers. This is the most flexible model, since the services can be delivered with a mix of shared and customer specific infrastructure devices.</description>
|
||||
<modules type="array">
|
||||
<module>itop-service-mgmt-provider</module>
|
||||
</modules>
|
||||
</choice>
|
||||
</alternatives>
|
||||
</step>
|
||||
<step>
|
||||
<title>Tickets Management options</title>
|
||||
<description><![CDATA[<h2>Select the type of tickets you want to use in order to respond to user requests and incidents.</h2>]]></description>
|
||||
<banner>/images/icons/icons8-discussion-forum.svg</banner>
|
||||
<alternatives type="array">
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-simple-ticket</extension_code>
|
||||
<title>Simple Ticket Management</title>
|
||||
<description>Select this option to use one single type of tickets for all kind of requests.</description>
|
||||
<modules type="array">
|
||||
<module>itop-request-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
<sub_options>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-simple-ticket-enhanced-portal</extension_code>
|
||||
<title>Customer Portal</title>
|
||||
<description><![CDATA[Modern & responsive portal for the end-users]]></description>
|
||||
<modules type="array">
|
||||
<module>itop-portal</module>
|
||||
<module>itop-portal-base</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
</options>
|
||||
</sub_options>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil</extension_code>
|
||||
<title>ITIL Compliant Tickets Management</title>
|
||||
<description>Select this option to have different types of ticket for managing user requests and incidents. Each type of ticket has a specific life cycle and specific fields</description>
|
||||
<sub_options>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil-user-request</extension_code>
|
||||
<title>User Request Management</title>
|
||||
<description>Manage User Request tickets in iTop</description>
|
||||
<modules type="array">
|
||||
<module>itop-request-mgmt-itil</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil-incident</extension_code>
|
||||
<title>Incident Management</title>
|
||||
<description>Manage Incidents tickets in iTop</description>
|
||||
<modules type="array">
|
||||
<module>itop-incident-mgmt-itil</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil-enhanced-portal</extension_code>
|
||||
<title>Customer Portal</title>
|
||||
<description><![CDATA[Modern & responsive portal for the end-users]]></description>
|
||||
<modules type="array">
|
||||
<module>itop-portal</module>
|
||||
<module>itop-portal-base</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
</options>
|
||||
</sub_options>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-none</extension_code>
|
||||
<title>No Tickets Management</title>
|
||||
<description>Don't manage incidents or user requests in iTop</description>
|
||||
<modules type="array">
|
||||
</modules>
|
||||
</choice>
|
||||
</alternatives>
|
||||
</step>
|
||||
<step>
|
||||
<title>Change Management options</title>
|
||||
<description><![CDATA[<h2>Select the type of tickets you want to use in order to manage changes to the IT infrastructure.</h2>]]></description>
|
||||
<banner>/images/icons/icons8-change.svg</banner>
|
||||
<alternatives type="array">
|
||||
<choice>
|
||||
<extension_code>itop-change-mgmt-simple</extension_code>
|
||||
<title>Simple Change Management</title>
|
||||
<description>Select this option to use one type of ticket for all kind of changes.</description>
|
||||
<modules type="array">
|
||||
<module>itop-change-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-change-mgmt-itil</extension_code>
|
||||
<title>ITIL Change Management</title>
|
||||
<description>Select this option to use Normal/Routine/Emergency change tickets.</description>
|
||||
<modules type="array">
|
||||
<module>itop-change-mgmt-itil</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-change-mgmt-none</extension_code>
|
||||
<title>No Change Management</title>
|
||||
<description>Don't manage changes in iTop</description>
|
||||
<modules type="array">
|
||||
</modules>
|
||||
</choice>
|
||||
</alternatives>
|
||||
</step>
|
||||
<step>
|
||||
<title>Additional ITIL tickets</title>
|
||||
<description><![CDATA[<h2>Pick from the list below the additional ITIL processes that are to be implemented in iTop.</h2>]]></description>
|
||||
<banner>/images/icons/icons8-important-book.svg</banner>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<!-- Extension code has a typo but fixing it would remove that setup option for all existing iTop -->
|
||||
<extension_code>itop-kown-error-mgmt</extension_code>
|
||||
<title>Known Errors Management and FAQ</title>
|
||||
<description>Select this option to track "Known Errors" and FAQs in iTop.</description>
|
||||
<modules type="array">
|
||||
<module>itop-faq-light</module>
|
||||
<module>itop-knownerror-mgmt</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-problem-mgmt</extension_code>
|
||||
<title>Problem Management</title>
|
||||
<description>Select this option track "Problems" in iTop.</description>
|
||||
<modules type="array">
|
||||
<module>itop-problem-mgmt</module>
|
||||
</modules>
|
||||
</choice>
|
||||
</options>
|
||||
</step>
|
||||
</steps>
|
||||
</installation>
|
||||
@@ -0,0 +1 @@
|
||||
{"itop-config-mgmt":{"label":"Configuration+Management+customized+for+Combodo+IT(CMDB)","value":"2.7.0"},"itop-icalendar-action":{"label":"Calendar+Invitations","value":"1.1.0"},"itop-fence":{"label":"iTop+Fence","value":"1.1.2"},"authent-ldap":{"label":"User+authentication+based+on+LDAP","value":"3.2.1"},"itop-faq-light":{"label":"Frequently+Asked+Questions+Database","value":"3.2.1"},"authent-local":{"label":"User+authentication+based+on+the+local+DB","value":"3.2.1"},"combodo-custom-hyperlinks":{"label":"Hyperlinks+configurator","value":"1.1.3"},"authent-token":{"label":"User+authentication+by+token","value":"2.2.1"},"itop-service-mgmt":{"label":"Service+Management+Customized+for+Combodo+IT(services,+SLAs,+contracts)","value":"2.7.0"},"combodo-impersonate":{"label":"Impersonate+user+for+support","value":"1.2.1"},"combodo-hybridauth":{"label":"oAuth\/OpenID+authentication","value":"1.2.4"},"combodo-login-page":{"label":"Combodo+login+page","value":"2.1.0"},"itop-core-update":{"label":"iTop+Core+Update","value":"3.2.1"},"itop-communications":{"label":"Communications+to+the+Customers","value":"1.3.4"},"itsm-designer-connector":{"label":"ITSM+Designer+Connector","value":"1.8.3"},"authent-external":{"label":"External+user+authentication","value":"3.2.1"},"itop-object-copier":{"label":"Object+copier","value":"1.4.5"},"combodo-backoffice-compact-themes":{"label":"Backoffice:+compact+themes","value":"1.0.1"},"data-localizer":{"label":"Data+localizer","value":"1.3.4"},"combodo-support-portal":{"label":"Combodo+Support+Portal","value":"3.0.1"},"combodo-calendar-view":{"label":"Calendar+View","value":"2.2.1"},"combodo-email-synchro":{"label":"Tickets+synchronization+via+e-mail","value":"3.8.2"},"combodo-webhook-integration":{"label":"Webhook+integrations","value":"1.4.1"},"combodo-notify-on-expiration":{"label":"Notify+on+expiration","value":"1.0.4"},"combodo-db-tools":{"label":"Database+maintenance+tools","value":"3.2.1"},"precanned-replies":{"label":"Helpdesk+Precanned+Replies","value":"1.4.0"},"combodo-dokuwiki-portal-brick":{"label":"Docuwiki+brick+(Portal)","value":"1.2.0"},"itop-rh-mgmt":{"label":"Human+Resource+Management","value":"2.7.0"},"itop-request-mgmt":{"label":"User+request+management+(Service+Desk)","value":"2.7.0"},"customer-survey":{"label":"Customer+Survey","value":"2.5.5"},"itop-standard-email-synchro":{"label":"Ticket+Creation+from+Emails+(Standard)","value":"3.8.2"},"itop-system-information":{"label":"System+information","value":"1.2.6"},"itop-sales-mgmt":{"label":"Sales+Management","value":"2.7.0"},"combodo-password-expiration":{"label":"Password+Expiration+Enforcement","value":"1.0.0"},"combodo-workflow-graphical-view":{"label":"Workflow+graphical+view","value":"1.1.3"},"combodo-itsm-master":{"label":"Data+master+for+the+ITSM+Designer","value":"2.7.0"},"combodo-email-tickets":{"label":"Tickets+Creation+from+Emails+for+Combodo","value":"2.7.0"},"itop-training-mgmt":{"label":"Training+Management","value":"2.7.0"},"precanned-replies-pro":{"label":"Helpdesk+Precanned+Replies+Extension","value":"1.2.0"},"combodo-fulltext-search":{"label":"Enhanced+global+search","value":"2.0.0"},"itop-request-template":{"label":"Customized+Request+Forms","value":"2.3.6"},"itop-rest-data-push":{"label":"Data+push+(based+on+standard+REST+services)","value":"1.0.2"},"combodo-kpi-logger":{"label":"KPI+logger","value":"1.0.3"},"itop-incident-mgmt":{"label":"Incident+Management","value":"2.7.0"},"combodo-my-account-user-info":{"label":"User+info+for+MyAccount+module","value":"1.0.0"},"email-reply":{"label":"Send+Ticket+Log+Updates+by+Email","value":"1.4.5"},"itop-attachments":{"label":"Tickets+Attachments","value":"3.2.1"},"itop-log-mgmt":{"label":"iTop+Log+management","value":"2.0.8"},"itop-ui-copypaste":{"label":"CopyPaste+UI+Component","value":"1.0.0"}}
|
||||
@@ -0,0 +1,216 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<installation>
|
||||
<steps type="array">
|
||||
<step>
|
||||
<title>Configuration Management options</title>
|
||||
<description><![CDATA[<h2>The options below allow you to configure the type of elements that are to be managed inside iTop.</h2>]]></description>
|
||||
<banner>/images/modules.png</banner>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-core</extension_code>
|
||||
<title>Configuration Management Core</title>
|
||||
<description>All the base objects that are mandatory in the iTop CMDB: Organizations, Locations, Teams, Persons, etc.</description>
|
||||
<modules type="array">
|
||||
<module>itop-config-mgmt</module>
|
||||
<module>itop-attachments</module>
|
||||
<module>itop-profiles-itil</module>
|
||||
<module>itop-welcome-itil</module>
|
||||
<module>itop-tickets</module>
|
||||
<module>itop-files-information</module>
|
||||
<module>combodo-db-tools</module>
|
||||
<module>itop-core-update</module>
|
||||
<module>itop-hub-connector</module>
|
||||
<module>itop-oauth-client</module>
|
||||
</modules>
|
||||
<mandatory>true</mandatory>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-datacenter</extension_code>
|
||||
<title>Data Center Devices</title>
|
||||
<description>Manage Data Center devices such as Racks, Enclosures, PDUs, etc.</description>
|
||||
<modules type="array">
|
||||
<module>itop-datacenter-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-end-user</extension_code>
|
||||
<title>End-User Devices</title>
|
||||
<description>Manage devices related to end-users: PCs, Phones, Tablets, etc.</description>
|
||||
<modules type="array">
|
||||
<module>itop-endusers-devices</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-storage</extension_code>
|
||||
<title>Storage Devices</title>
|
||||
<description>Manage storage devices such as NAS, SAN Switches, Tape Libraries and Tapes, etc.</description>
|
||||
<modules type="array">
|
||||
<module>itop-storage-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-config-mgmt-virtualization</extension_code>
|
||||
<title>Virtualization</title>
|
||||
<description>Manage Hypervisors, Virtual Machines and Farms.</description>
|
||||
<modules type="array">
|
||||
<module>itop-virtualization-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
</options>
|
||||
</step>
|
||||
<step>
|
||||
<title>Service Management options</title>
|
||||
<description><![CDATA[<h2>Select the choice that best describes the relationships between the services and the IT infrastructure in your IT environment.</h2>]]></description>
|
||||
<banner>./wizard-icons/service.png</banner>
|
||||
<alternatives type="array">
|
||||
<choice>
|
||||
<extension_code>itop-service-mgmt-enterprise</extension_code>
|
||||
<title>Service Management for Enterprises</title>
|
||||
<description>Select this option if the IT delivers services based on a shared infrastructure. For example if different organizations within your company subscribe to services (like Mail and Print services) delivered by a single shared backend.</description>
|
||||
<modules type="array">
|
||||
<module>itop-service-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-service-mgmt-service-provider</extension_code>
|
||||
<title>Service Management for Service Providers</title>
|
||||
<description>Select this option if the IT manages the infrastructure of independent customers. This is the most flexible model, since the services can be delivered with a mix of shared and customer specific infrastructure devices.</description>
|
||||
<modules type="array">
|
||||
<module>itop-service-mgmt-provider</module>
|
||||
</modules>
|
||||
</choice>
|
||||
</alternatives>
|
||||
</step>
|
||||
<step>
|
||||
<title>Tickets Management options</title>
|
||||
<description><![CDATA[<h2>Select the type of tickets you want to use in order to respond to user requests and incidents.</h2>]]></description>
|
||||
<banner>./itop-incident-mgmt-itil/images/incident-escalated.svg</banner>
|
||||
<alternatives type="array">
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-simple-ticket</extension_code>
|
||||
<title>Simple Ticket Management</title>
|
||||
<description>Select this option to use one single type of tickets for all kind of requests.</description>
|
||||
<modules type="array">
|
||||
<module>itop-request-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
<sub_options>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-simple-ticket-enhanced-portal</extension_code>
|
||||
<title>Customer Portal</title>
|
||||
<description><![CDATA[Modern & responsive portal for the end-users]]></description>
|
||||
<modules type="array">
|
||||
<module>itop-portal</module>
|
||||
<module>itop-portal-base</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
</options>
|
||||
</sub_options>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil</extension_code>
|
||||
<title>ITIL Compliant Tickets Management</title>
|
||||
<description>Select this option to have different types of ticket for managing user requests and incidents. Each type of ticket has a specific life cycle and specific fields</description>
|
||||
<sub_options>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil-user-request</extension_code>
|
||||
<title>User Request Management</title>
|
||||
<description>Manage User Request tickets in iTop</description>
|
||||
<modules type="array">
|
||||
<module>itop-request-mgmt-itil</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil-incident</extension_code>
|
||||
<title>Incident Management</title>
|
||||
<description>Manage Incidents tickets in iTop</description>
|
||||
<modules type="array">
|
||||
<module>itop-incident-mgmt-itil</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-itil-enhanced-portal</extension_code>
|
||||
<title>Customer Portal</title>
|
||||
<description><![CDATA[Modern & responsive portal for the end-users]]></description>
|
||||
<modules type="array">
|
||||
<module>itop-portal</module>
|
||||
<module>itop-portal-base</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
</options>
|
||||
</sub_options>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-ticket-mgmt-none</extension_code>
|
||||
<title>No Tickets Management</title>
|
||||
<description>Don't manage incidents or user requests in iTop</description>
|
||||
<modules type="array">
|
||||
</modules>
|
||||
</choice>
|
||||
</alternatives>
|
||||
</step>
|
||||
<step>
|
||||
<title>Change Management options</title>
|
||||
<description><![CDATA[<h2>Select the type of tickets you want to use in order to manage changes to the IT infrastructure.</h2>]]></description>
|
||||
<banner>./itop-change-mgmt/images/change.svg</banner>
|
||||
<alternatives type="array">
|
||||
<choice>
|
||||
<extension_code>itop-change-mgmt-simple</extension_code>
|
||||
<title>Simple Change Management</title>
|
||||
<description>Select this option to use one type of ticket for all kind of changes.</description>
|
||||
<modules type="array">
|
||||
<module>itop-change-mgmt</module>
|
||||
</modules>
|
||||
<default>true</default>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-change-mgmt-itil</extension_code>
|
||||
<title>ITIL Change Management</title>
|
||||
<description>Select this option to use Normal/Routine/Emergency change tickets.</description>
|
||||
<modules type="array">
|
||||
<module>itop-change-mgmt-itil</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-change-mgmt-none</extension_code>
|
||||
<title>No Change Management</title>
|
||||
<description>Don't manage changes in iTop</description>
|
||||
<modules type="array">
|
||||
</modules>
|
||||
</choice>
|
||||
</alternatives>
|
||||
</step>
|
||||
<step>
|
||||
<title>Additional ITIL tickets</title>
|
||||
<description><![CDATA[<h2>Pick from the list below the additional ITIL processes that are to be implemented in iTop.</h2>]]></description>
|
||||
<banner>./itop-knownerror-mgmt/images/known-error.svg</banner>
|
||||
<options type="array">
|
||||
<choice>
|
||||
<extension_code>itop-kown-error-mgmt</extension_code>
|
||||
<title>Known Errors Management</title>
|
||||
<description>Select this option to track "Known Errors" and FAQs in iTop.</description>
|
||||
<modules type="array">
|
||||
<module>itop-knownerror-mgmt</module>
|
||||
</modules>
|
||||
</choice>
|
||||
<choice>
|
||||
<extension_code>itop-problem-mgmt</extension_code>
|
||||
<title>Problem Management</title>
|
||||
<description>Select this option track "Problems" in iTop.</description>
|
||||
<modules type="array">
|
||||
<module>itop-problem-mgmt</module>
|
||||
</modules>
|
||||
</choice>
|
||||
</options>
|
||||
</step>
|
||||
</steps>
|
||||
</installation>
|
||||
Reference in New Issue
Block a user