N°8764 - stop setup and display data to cleanup message

This commit is contained in:
odain
2026-01-09 14:52:00 +01:00
parent 43bd621731
commit 0996e8fae0
2 changed files with 42 additions and 13 deletions

View File

@@ -262,7 +262,7 @@ class ApplicationInstaller
$sExtensionDir = $this->oParams->Get('extensions_dir', 'extensions');
$aMiscOptions = $this->oParams->Get('options', []);
$aRemovedExtensionCodes = $this->oParams->Get('removed_extensions', []);
$sForceUninstall = $this->oParams->Get('force-uninstall', '');
$sDisableDataAudit = $this->oParams->Get('disable-data-audit', '');
$bUseSymbolicLinks = null;
if ((isset($aMiscOptions['symlinks']) && $aMiscOptions['symlinks'])) {
@@ -279,7 +279,7 @@ class ApplicationInstaller
$aSelectedModules,
$sSourceDir,
$sExtensionDir,
$sForceUninstall,
$sDisableDataAudit,
$bUseSymbolicLinks
);
@@ -293,8 +293,8 @@ class ApplicationInstaller
break;
case 'setup-audit':
$sForceUninstall = $this->oParams->Get('force-uninstall', '');
$this->DoSetupAudit($sForceUninstall);
$sDisableDataAudit = $this->oParams->Get('disable-data-audit', '');
$this->DoSetupAudit($sDisableDataAudit);
$aResult = [
'status' => self::OK,
'message' => '',
@@ -499,7 +499,7 @@ class ApplicationInstaller
* @param array $aSelectedModules
* @param string $sSourceDir
* @param string $sExtensionDir
* @param string $sForceUninstall
* @param string $sDisableDataAudit
* @param boolean $bUseSymbolicLinks
*
* @return void
@@ -508,7 +508,7 @@ class ApplicationInstaller
*
* @since 3.1.0 N°2013 added the aParamValues param
*/
protected function DoCompile($aRemovedExtensionCodes, $aSelectedModules, $sSourceDir, $sExtensionDir, $sForceUninstall, $bUseSymbolicLinks = null)
protected function DoCompile($aRemovedExtensionCodes, $aSelectedModules, $sSourceDir, $sExtensionDir, $sDisableDataAudit, $bUseSymbolicLinks = null)
{
/**
* @since 3.2.0 move the ContextTag init at the very beginning of the method
@@ -549,9 +549,9 @@ class ApplicationInstaller
}
$bIsAlreadyInMaintenanceMode = SetupUtils::IsInMaintenanceMode();
if ($sForceUninstall === "checked") {
if ($sDisableDataAudit !== "checked") {
//audit required
SetupLog::Info(__METHOD__, null, ['force-uninstall' => $sForceUninstall]);
SetupLog::Info(__METHOD__, null, ['disable-data-audit' => $sDisableDataAudit]);
if ($bIsAlreadyInMaintenanceMode) {
//required to read DM before calling SaveModelInfo
SetupUtils::ExitMaintenanceMode();
@@ -670,13 +670,13 @@ class ApplicationInstaller
$aModelInfo = json_decode($sContent, true);
if (false === $aModelInfo) {
throw new \Exception("Could not read (before compilation) previous model to audit data");
throw new Exception("Could not read (before compilation) previous model to audit data");
}
return $aModelInfo;
}
protected function DoSetupAudit(string $sForceUninstall)
protected function DoSetupAudit(string $sDisableDataAudit)
{
/**
* @since 3.2.0 move the ContextTag init at the very beginning of the method
@@ -690,11 +690,9 @@ class ApplicationInstaller
return;
}
if ($sForceUninstall !== "checked") {
if ($sDisableDataAudit === "checked") {
SetupLog::Info("Setup data audit disabled (force-uninstall)");
return;
} else {
SetupLog::Info(__METHOD__, null, ['force-uninstall' => $sForceUninstall]);
}
$sTargetEnvironment = $this->GetTargetEnv();
@@ -702,6 +700,13 @@ class ApplicationInstaller
$oSetupAudit = new SetupAudit($sTargetEnvironment, $sTargetEnvironment);
$oSetupAudit->ComputeClasses($aPreviousCompilationModelInfo);
try {
$oSetupAudit->GetIssues(true);
} catch (Exception $e) {
$iCount = $oSetupAudit->GetLastComputedFinalClassesRemovedCount();
throw new Exception("$iCount elements require data adjustments or cleanup in the backoffice prior to upgrading iTop");
}
}
/**

View File

@@ -2,9 +2,12 @@
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';
@@ -121,14 +124,25 @@ class SetupAudit
$this->aFinalClassesRemoved[$sClass] = $iCount;
if ($bThrowExceptionAtFirstIssue && $iCount > 0) {
//setup envt: should raise issue ASAP
$this->LogInfoWithProperLogger("Setup audit found data to cleanup", null, $this->aFinalClassesRemoved);
throw new \Exception($sClass);
}
}
}
$this->LogInfoWithProperLogger("Setup audit found data to cleanup", null, $this->aFinalClassesRemoved);
return $this->aFinalClassesRemoved;
}
public function GetLastComputedFinalClassesRemovedCount(): int
{
$res = 0;
foreach ($this->aFinalClassesRemoved as $sClass => $iCount) {
$res += $iCount;
}
return $res;
}
private function Count($sClass): int
{
$oSearch = DBObjectSearch::FromOQL("SELECT $sClass", []);
@@ -137,4 +151,14 @@ class SetupAudit
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);
}
}
}