N°9144 - setup robustness

This commit is contained in:
odain
2026-05-05 16:46:49 +02:00
parent 99a5b47899
commit 73ebf663d6
5 changed files with 29 additions and 17 deletions

View File

@@ -36,19 +36,6 @@ class ModelReflectionSerializer
{
IssueLog::Info(__METHOD__, null, ['env' => $sEnv]);
$sCurrentEnvt = MetaModel::GetEnvironment();
if ($sCurrentEnvt === $sEnv) {
$aClasses = MetaModel::GetClasses();
if (count($aClasses) === 0) {
//MetaModel not started yet
$sConfFile = utils::GetConfigFilePath($sEnv);
MetaModel::Startup($sConfFile, false /* $bModelOnly */, false /* $bAllowCache */, false /* $bTraceSourceFiles */, $sEnv);
$aClasses = MetaModel::GetClasses();
}
return $aClasses;
}
$sPHPExec = trim(utils::GetConfig()->Get('php_path'));
$sOutput = "";
$iRes = 0;

View File

@@ -16,6 +16,7 @@ use PhpParser\Node\Stmt\ElseIf_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\ParserFactory;
use SetupLog;
require_once __DIR__.'/ModuleFileReaderException.php';
require_once APPROOT.'sources/PhpParser/Evaluation/PhpExpressionEvaluator.php';
@@ -143,6 +144,7 @@ class ModuleFileReader
}
// Replace the main function call by an assignment to a variable, as an array...
$sModuleFileContents = str_replace(['SetupWebPage::AddModule', 'ModuleDiscovery::AddModule'], '$aModuleInfo = array', $sModuleFileContents);
SetupLog::Debug(__METHOD__, null, ['module_file' => $sModuleFilePath]);
eval($sModuleFileContents); // Assigns $aModuleInfo
if (count($aModuleInfo) === 0) {

View File

@@ -1126,7 +1126,9 @@ class RunTimeEnvironment
}
if (is_null($aSelectedModules) || in_array($sModuleId, $aSelectedModules)) {
$aArgs = [MetaModel::GetConfig(), $aModule['installed_version'], $aModule['available_version']];
$oConfig = MetaModel::GetConfig();
$oConfig->Set('access_mode', ACCESS_FULL);
$aArgs = [$oConfig, $aModule['installed_version'], $aModule['available_version']];
RunTimeEnvironment::CallInstallerHandler($aModule, $sHandlerName, $aArgs);
}
}
@@ -1193,6 +1195,9 @@ class RunTimeEnvironment
*/
public function LoadData($aAvailableModules, $bSampleData, $aSelectedModules = null)
{
$oConfig = MetaModel::GetConfig();
$oConfig->Set('access_mode', ACCESS_FULL);
$oDataLoader = new XMLDataLoader();
CMDBObject::SetCurrentChangeFromParams("Initialization from XML files for the selected modules ");
@@ -1326,9 +1331,6 @@ class RunTimeEnvironment
{
$oSetupAudit = new SetupAudit(ITOP_DEFAULT_ENV, $this->sBuildEnv);
//Make sure the MetaModel is started before analysing for issues
$sConfFile = utils::GetConfigFilePath(ITOP_DEFAULT_ENV);
MetaModel::Startup($sConfFile, false, false); // Start on production environment
$oSetupAudit->RunDataAudit(true);
$iCount = $oSetupAudit->GetDataToCleanupCount();
@@ -1537,6 +1539,15 @@ class RunTimeEnvironment
$oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile);
}
/**
* @param \Config $oConfig
* @return void
*/
public function EnterMaintenanceMode(Config $oConfig)
{
SetupUtils::EnterMaintenanceMode($oConfig);
}
public function EnterReadOnlyMode(Config $oConfig)
{
if ($this->GetFinalEnv() != 'production') {
@@ -1550,6 +1561,11 @@ class RunTimeEnvironment
SetupUtils::EnterReadOnlyMode($oConfig);
}
public function ExitMaintenanceMode(): void
{
SetupUtils::ExitMaintenanceMode();
}
public function ExitReadOnlyMode()
{
if ($this->GetFinalEnv() != 'production') {

View File

@@ -89,6 +89,7 @@ class ApplicationInstallSequencer extends StepSequencer
return $this->ComputeNextStep($sStep);
case 'migrate-before':
$this->oRunTimeEnvironment->EnterMaintenanceMode($this->GetConfig());
if (array_key_exists($sStep, $this->oParams->Get('optional_steps', []))) {
$this->oRunTimeEnvironment->MigrateDataBeforeUpdateStructure($this->oParams->Get('mode'), $this->GetConfig());
}
@@ -139,6 +140,7 @@ class ApplicationInstallSequencer extends StepSequencer
case 'commit':
$this->oRunTimeEnvironment->Commit();
$this->oRunTimeEnvironment->ExitReadOnlyMode();
$this->oRunTimeEnvironment->ExitMaintenanceMode();
return $this->GetNextStep('', 'Completed', 100);
default:

View File

@@ -159,6 +159,11 @@ abstract class StepSequencer
file_put_contents(APPROOT.'log/'.$sFileName.'.xml', $sSafeXml);
}
/**
* @return \Config
* @throws \ConfigException
* @throws \CoreException
*/
protected function GetConfig()
{
if (! is_null($this->oTestConfig)) {