N°9144 - fix broken fresh install

This commit is contained in:
odain
2026-04-20 15:44:09 +02:00
parent 423807d32a
commit dc8f186443
5 changed files with 42 additions and 29 deletions

View File

@@ -84,7 +84,7 @@ class ApplicationInstallSequencer extends StepSequencer
$sDestination = $aBackupOptions['destination']; $sDestination = $aBackupOptions['destination'];
$sSourceConfigFile = $aBackupOptions['configuration_file']; $sSourceConfigFile = $aBackupOptions['configuration_file'];
$sMySQLBinDir = $this->oParams->Get('mysql_bindir', null); $sMySQLBinDir = $this->oParams->Get('mysql_bindir', null);
$this->oRunTimeEnvironment->Backup($this->oConfig, $sDestination, $sSourceConfigFile, $sMySQLBinDir); $this->oRunTimeEnvironment->Backup($this->GetConfig(), $sDestination, $sSourceConfigFile, $sMySQLBinDir);
} }
return $this->ComputeNextStep($sStep); return $this->ComputeNextStep($sStep);
@@ -176,8 +176,6 @@ class ApplicationInstallSequencer extends StepSequencer
$this->oRunTimeEnvironment->UpdateDBSchema($oConfig, $sMode, $aSelectedModules); $this->oRunTimeEnvironment->UpdateDBSchema($oConfig, $sMode, $aSelectedModules);
$oConfig->Set('access_mode', ACCESS_FULL);
$this->oRunTimeEnvironment->SetDbUUID(); $this->oRunTimeEnvironment->SetDbUUID();
SetupLog::Info("Database Schema Successfully Updated for environment '$sTargetEnvironment'."); SetupLog::Info("Database Schema Successfully Updated for environment '$sTargetEnvironment'.");

View File

@@ -25,7 +25,7 @@ abstract class StepSequencer
public const INFO = 4; public const INFO = 4;
protected array $aStepsHistory = []; protected array $aStepsHistory = [];
protected Parameters $oParams; protected Parameters $oParams;
protected Config $oConfig; protected ?Config $oTestConfig = null;
protected RunTimeEnvironment $oRunTimeEnvironment; protected RunTimeEnvironment $oRunTimeEnvironment;
protected string $sSourceDesc; protected string $sSourceDesc;
@@ -46,11 +46,7 @@ abstract class StepSequencer
} }
$this->oParams = $oParams; $this->oParams = $oParams;
utils::SetConfig($this->GetConfig());
$aParamValues = $oParams->GetParamForConfigArray();
$this->oConfig = new Config();
$this->oConfig->UpdateFromParams($aParamValues);
utils::SetConfig($this->oConfig);
$this->sSourceDesc = $sSourceDesc; $this->sSourceDesc = $sSourceDesc;
} }
@@ -165,24 +161,30 @@ abstract class StepSequencer
protected function GetConfig() protected function GetConfig()
{ {
if (! is_null($this->oTestConfig)) {
return $this->oTestConfig;
}
// Caching config here is a bad idea, the first config loaded does not contain module settings // Caching config here is a bad idea, the first config loaded does not contain module settings
$sTargetEnvironment = $this->oRunTimeEnvironment->GetBuildEnv(); $sTargetEnvironment = $this->oRunTimeEnvironment->GetBuildEnv();
$sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE; $sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE;
try { try {
if (file_exists($sConfigFile)) { if (file_exists($sConfigFile)) {
$this->oConfig = new Config($sConfigFile); $oConfig = new Config($sConfigFile);
} else { } else {
$this->oConfig = new Config(); $oConfig = new Config();
} }
$oConfig->Set('access_mode', ACCESS_FULL);
} catch (Exception $e) { } catch (Exception $e) {
SetupLog::Exception("Setup error", $e); SetupLog::Exception("Setup error", $e);
throw $e; throw $e;
} }
$aParamValues = $this->oParams->GetParamForConfigArray(); $aParamValues = $this->oParams->GetParamForConfigArray();
$this->oConfig->UpdateFromParams($aParamValues); $oConfig->UpdateFromParams($aParamValues);
return $this->oConfig; return $oConfig;
} }
/** /**

View File

@@ -53,7 +53,6 @@ abstract class AbstractWizStepInstall extends WizardStep
} }
$sSourceDir = $this->oWizard->GetParameter('source_dir'); $sSourceDir = $this->oWizard->GetParameter('source_dir');
$aCopies = [];
if (($sMode == 'upgrade') && ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous')) { if (($sMode == 'upgrade') && ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous')) {
$sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir'); $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir');
//$aCopies[] = ['source' => $sSourceDir, 'destination' => 'modules']; // Source is an absolute path, destination is relative to APPROOT //$aCopies[] = ['source' => $sSourceDir, 'destination' => 'modules']; // Source is an absolute path, destination is relative to APPROOT

View File

@@ -11,6 +11,7 @@ use RunTimeEnvironment;
class ApplicationInstallerSequencerTest extends ItopTestCase class ApplicationInstallerSequencerTest extends ItopTestCase
{ {
private \RunTimeEnvironment&\PHPUnit\Framework\MockObject\MockObject $oRunTimeEnvironment; private \RunTimeEnvironment&\PHPUnit\Framework\MockObject\MockObject $oRunTimeEnvironment;
private \Config&\PHPUnit\Framework\MockObject\MockObject $oConfig;
private ApplicationInstallSequencer $oSequencer; private ApplicationInstallSequencer $oSequencer;
protected function setUp(): void protected function setUp(): void
@@ -24,9 +25,6 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
$this->RequireOnceItopFile('/setup/parameters.class.inc.php'); $this->RequireOnceItopFile('/setup/parameters.class.inc.php');
$this->RequireOnceItopFile('/setup/setuputils.class.inc.php'); $this->RequireOnceItopFile('/setup/setuputils.class.inc.php');
$this->RequireOnceItopFile('/setup/runtimeenv.class.inc.php'); $this->RequireOnceItopFile('/setup/runtimeenv.class.inc.php');
// Copy conf to production-test
\SetupUtils::copydir(APPROOT.'conf/production', APPROOT.'conf/production-test');
} }
public static function FirstStepProvider() public static function FirstStepProvider()
@@ -141,7 +139,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
]; ];
$this->GivenApplicationInstallSequencer($aAdditionalParams); $this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('Backup'); $this->oRunTimeEnvironment->expects($this->once())->method('Backup')
->with($this->oConfig, '/my_backup_file_path', '/my_config_file_path', null);
$aRes = $this->oSequencer->ExecuteStep('backup'); $aRes = $this->oSequencer->ExecuteStep('backup');
$aExpected = [ $aExpected = [
@@ -163,7 +162,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
]; ];
$this->GivenApplicationInstallSequencer($aAdditionalParams); $this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataBeforeUpdateStructure'); $this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataBeforeUpdateStructure')
->with('install', $this->oConfig);
$aRes = $this->oSequencer->ExecuteStep('migrate-before'); $aRes = $this->oSequencer->ExecuteStep('migrate-before');
$aExpected = [ $aExpected = [
@@ -207,7 +207,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
]; ];
$this->GivenApplicationInstallSequencer($aAdditionalParams); $this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('UpdateDBSchema'); $this->oRunTimeEnvironment->expects($this->once())->method('UpdateDBSchema')
->with($this->oConfig, 'install', ["a" => "b"]);
$this->oRunTimeEnvironment->expects($this->once())->method('SetDbUUID') $this->oRunTimeEnvironment->expects($this->once())->method('SetDbUUID')
->with(); ->with();
@@ -231,7 +232,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
]; ];
$this->GivenApplicationInstallSequencer($aAdditionalParams); $this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataAfterUpdateStructure'); $this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataAfterUpdateStructure')
->with('install', $this->oConfig);
$aRes = $this->oSequencer->ExecuteStep('migrate-after'); $aRes = $this->oSequencer->ExecuteStep('migrate-after');
$aExpected = [ $aExpected = [
@@ -257,7 +259,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
]; ];
$this->GivenApplicationInstallSequencer($aAdditionalParams); $this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('AfterDBCreate'); $this->oRunTimeEnvironment->expects($this->once())->method('AfterDBCreate')
->with($this->oConfig, 'install', ["a" => "b"], $aAdminParams);
$aRes = $this->oSequencer->ExecuteStep('after-db-create'); $aRes = $this->oSequencer->ExecuteStep('after-db-create');
$aExpected = [ $aExpected = [
@@ -278,7 +281,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
]; ];
$this->GivenApplicationInstallSequencer($aAdditionalParams); $this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('DoLoadData'); $this->oRunTimeEnvironment->expects($this->once())->method('DoLoadData')
->with($this->oConfig, true, ["a" => "b"]);
$aRes = $this->oSequencer->ExecuteStep('load-data'); $aRes = $this->oSequencer->ExecuteStep('load-data');
$aExpected = [ $aExpected = [
@@ -300,7 +304,8 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
'sample_data' => 1, 'sample_data' => 1,
]; ];
$this->GivenApplicationInstallSequencer($aAdditionalParams); $this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->oRunTimeEnvironment->expects($this->once())->method('DoCreateConfig'); $this->oRunTimeEnvironment->expects($this->once())->method('DoCreateConfig')
->with($this->oConfig, "6.6.6", ["a" => "b"], ["c" => "d"], null);
$aRes = $this->oSequencer->ExecuteStep('create-config'); $aRes = $this->oSequencer->ExecuteStep('create-config');
$aExpected = [ $aExpected = [
@@ -333,7 +338,7 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
public function testAnyFailure() public function testAnyFailure()
{ {
$this->GivenApplicationInstallSequencer(); $this->GivenApplicationInstallSequencer();
$this->oRunTimeEnvironment->expects($this->once())->method('UpdateDBSchema') $this->oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv')
->willThrowException(new \CoreException('SHADOK MSG')); ->willThrowException(new \CoreException('SHADOK MSG'));
$aRes = $this->oSequencer->ExecuteStep('db-schema'); $aRes = $this->oSequencer->ExecuteStep('db-schema');
@@ -483,14 +488,21 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
{ {
$this->oRunTimeEnvironment = $this->createMock(RunTimeEnvironment::class); $this->oRunTimeEnvironment = $this->createMock(RunTimeEnvironment::class);
if (! $bStepComputationOnly) { if (! $bStepComputationOnly) {
$this->oRunTimeEnvironment->expects($this->once())->method('EnterReadOnlyMode'); $this->oRunTimeEnvironment->expects($this->once())->method('EnterReadOnlyMode')
$this->oRunTimeEnvironment->expects($this->any())->method('GetBuildEnv')->willReturn('production-test'); ->with($this->oConfig);
} }
} }
private function GivenConfig(): void
{
$this->oConfig = $this->createMock(Config::class);
}
private function GivenApplicationInstallSequencer(array $aAdditionalParams = [], bool $bStepComputationOnly = false): void private function GivenApplicationInstallSequencer(array $aAdditionalParams = [], bool $bStepComputationOnly = false): void
{ {
$this->GivenConfig();
$this->GivenRunTimeEnvironment($bStepComputationOnly); $this->GivenRunTimeEnvironment($bStepComputationOnly);
$this->oSequencer = new ApplicationInstallSequencer($this->GivenParams($aAdditionalParams), $this->oRunTimeEnvironment); $this->oSequencer = new ApplicationInstallSequencer($this->GivenParams($aAdditionalParams), $this->oRunTimeEnvironment);
$this->SetNonPublicProperty($this->oSequencer, 'oTestConfig', $this->oConfig);
} }
} }

View File

@@ -24,7 +24,8 @@ class DataAuditSequencerTest extends ItopTestCase
public function testDataAuditFirstStep() public function testDataAuditFirstStep()
{ {
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class); $oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->never())->method($this->anything()); $oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv')
->willReturn('production-test');
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment); $oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep(); $aRes = $oSequencer->ExecuteStep();
@@ -41,7 +42,8 @@ class DataAuditSequencerTest extends ItopTestCase
public function testDataUnknownStep() public function testDataUnknownStep()
{ {
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class); $oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->never())->method($this->anything()); $oRunTimeEnvironment->expects($this->once())->method('GetBuildEnv')
->willReturn('production-test');
$oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment); $oSequencer = new DataAuditSequencer($this->GivenParams(), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('gabuzomeu'); $aRes = $oSequencer->ExecuteStep('gabuzomeu');