Files
iTop/setup/feature_removal/ModelReflectionSerializer.php
odain-cbd ba6cc9dcba N°9567 - Extension Mgmt : Run setup (#912)
* N°9144 - correct next button in audit page

* N°9567 - WIP

code style

* N°9412 - Screen Analysis results wip + test endpoint

* N°9412 - next button label

* N°9412 - Mask CI pbs

* N°9412 - Analysis results screen wip

* N°9412 - Analysis results screen wip

* N°9567 - fix extension map init of installation choices

* N°9567 - fix test

* N°9567 - link from ext mgt to setup WIP

* N°9567 - add enc_type in UIForm to be able to change content type in twigs

* N°9412 - wip

* N°9567 - Extension Mgmt : Run setup

* N°9567 - Extension Mgmt : Run setup

* N°9567 - Extension Mgmt : Run setup (fix post-deletion button inputs)

* N°9567 - Extension Mgmt : Run setup

* N°9567 - Extension Mgmt : Run setup

* N°9567 - Extension Mgmt : Run setup

---------

Co-authored-by: Eric Espie <eric.espie@combodo.com>
2026-05-20 10:16:32 +02:00

73 lines
1.9 KiB
PHP

<?php
namespace Combodo\iTop\Setup\FeatureRemoval;
use ContextTag;
use CoreException;
use Exception;
use IssueLog;
use SetupLog;
use utils;
class ModelReflectionSerializer
{
private static ModelReflectionSerializer $oInstance;
protected function __construct()
{
}
final public static function GetInstance(): ModelReflectionSerializer
{
if (!isset(self::$oInstance)) {
self::$oInstance = new ModelReflectionSerializer();
}
return self::$oInstance;
}
final public static function SetInstance(?ModelReflectionSerializer $oInstance): void
{
self::$oInstance = $oInstance;
}
public function GetModelFromEnvironment(string $sEnv): array
{
IssueLog::Debug(__METHOD__, null, ['env' => $sEnv]);
$sPHPExec = trim(utils::GetConfig()->Get('php_path'));
$sOutput = "";
$iRes = 0;
$sCommandLine = sprintf("$sPHPExec %s/get_model_reflection.php --env=%s", __DIR__, escapeshellarg($sEnv));
exec($sCommandLine, $sOutput, $iRes);
if ($iRes != 0) {
$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) {
$this->LogErrorWithProperLogger("Invalid JSON", null, ['env' => $sEnv, "output" => $sOutput]);
throw new Exception("cannot get classes");
}
if (!is_array($aClasses)) {
$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);
}
}
}