mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°8796 - Add PHP code style validation in iTop and extensions - format whole code base
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024 Combodo SAS
|
||||
//
|
||||
// This file is part of iTop.
|
||||
@@ -36,10 +37,10 @@ require_once(APPROOT.'setup/backup.class.inc.php');
|
||||
|
||||
class ApplicationInstaller
|
||||
{
|
||||
const OK = 1;
|
||||
const ERROR = 2;
|
||||
const WARNING = 3;
|
||||
const INFO = 4;
|
||||
public const OK = 1;
|
||||
public const ERROR = 2;
|
||||
public const WARNING = 3;
|
||||
public const INFO = 4;
|
||||
|
||||
/** @var \Parameters */
|
||||
protected $oParams;
|
||||
@@ -67,8 +68,7 @@ class ApplicationInstaller
|
||||
private function GetTargetEnv()
|
||||
{
|
||||
$sTargetEnvironment = $this->oParams->Get('target_env', '');
|
||||
if ($sTargetEnvironment !== '')
|
||||
{
|
||||
if ($sTargetEnvironment !== '') {
|
||||
return $sTargetEnvironment;
|
||||
}
|
||||
|
||||
@@ -100,17 +100,12 @@ class ApplicationInstaller
|
||||
$sStep = '';
|
||||
$sStepLabel = '';
|
||||
$iOverallStatus = self::OK;
|
||||
do
|
||||
{
|
||||
if ($bVerbose)
|
||||
{
|
||||
if ($sStep != '')
|
||||
{
|
||||
do {
|
||||
if ($bVerbose) {
|
||||
if ($sStep != '') {
|
||||
echo "$sStepLabel\n";
|
||||
echo "Executing '$sStep'\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
echo "Starting the installation...\n";
|
||||
}
|
||||
}
|
||||
@@ -118,11 +113,9 @@ class ApplicationInstaller
|
||||
$sStep = $aRes['next-step'];
|
||||
$sStepLabel = $aRes['next-step-label'];
|
||||
$sMessage = $aRes['message'];
|
||||
if ($bVerbose)
|
||||
{
|
||||
switch ($aRes['status'])
|
||||
{
|
||||
case self::OK;
|
||||
if ($bVerbose) {
|
||||
switch ($aRes['status']) {
|
||||
case self::OK:
|
||||
echo "Ok. ".$aRes['percentage-completed']." % done.\n";
|
||||
break;
|
||||
|
||||
@@ -142,11 +135,8 @@ class ApplicationInstaller
|
||||
echo $aRes['percentage-completed']." % done.\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($aRes['status'])
|
||||
{
|
||||
} else {
|
||||
switch ($aRes['status']) {
|
||||
case self::ERROR:
|
||||
$iOverallStatus = self::ERROR;
|
||||
break;
|
||||
@@ -155,8 +145,7 @@ class ApplicationInstaller
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while(($aRes['status'] != self::ERROR) && ($aRes['next-step'] != ''));
|
||||
} while (($aRes['status'] != self::ERROR) && ($aRes['next-step'] != ''));
|
||||
|
||||
return ($iOverallStatus == self::OK);
|
||||
}
|
||||
@@ -167,8 +156,7 @@ class ApplicationInstaller
|
||||
$sConfigFile = APPCONF.$sTargetEnvironment.'/'.ITOP_CONFIG_FILE;
|
||||
try {
|
||||
$oConfig = new Config($sConfigFile);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -189,21 +177,19 @@ class ApplicationInstaller
|
||||
*/
|
||||
public function ExecuteStep($sStep = '', $sInstallComment = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
try {
|
||||
$fStart = microtime(true);
|
||||
SetupLog::Info("##### STEP {$sStep} start");
|
||||
$this->EnterReadOnlyMode();
|
||||
switch ($sStep)
|
||||
{
|
||||
switch ($sStep) {
|
||||
case '':
|
||||
$aResult = array(
|
||||
$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');
|
||||
@@ -217,8 +203,7 @@ class ApplicationInstaller
|
||||
// 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'))
|
||||
{
|
||||
while (file_exists(APPROOT.'log/'.$sFileName.'.xml')) {
|
||||
$index++;
|
||||
$sFileName = 'install-'.date('Y-m-d').'-'.$index;
|
||||
}
|
||||
@@ -233,18 +218,15 @@ class ApplicationInstaller
|
||||
self::DoCopy($aCopies);
|
||||
$sReport = "Copying...";
|
||||
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => $sReport,
|
||||
);
|
||||
if (isset($aPreinstall['backup']))
|
||||
{
|
||||
];
|
||||
if (isset($aPreinstall['backup'])) {
|
||||
$aResult['next-step'] = 'backup';
|
||||
$aResult['next-step-label'] = 'Performing a backup of the database';
|
||||
$aResult['percentage-completed'] = 20;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$aResult['next-step'] = 'compile';
|
||||
$aResult['next-step-label'] = 'Compiling the data model';
|
||||
$aResult['percentage-completed'] = 20;
|
||||
@@ -262,13 +244,13 @@ class ApplicationInstaller
|
||||
$sMySQLBinDir = $this->oParams->Get('mysql_bindir', null);
|
||||
self::DoBackup($oTempConfig, $sDestination, $sSourceConfigFile, $sMySQLBinDir);
|
||||
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => "Created backup",
|
||||
'next-step' => 'compile',
|
||||
'next-step-label' => 'Compiling the data model',
|
||||
'percentage-completed' => 20,
|
||||
);
|
||||
];
|
||||
break;
|
||||
|
||||
case 'compile':
|
||||
@@ -277,7 +259,7 @@ class ApplicationInstaller
|
||||
$sExtensionDir = $this->oParams->Get('extensions_dir', 'extensions');
|
||||
$sTargetEnvironment = $this->GetTargetEnv();
|
||||
$sTargetDir = $this->GetTargetDir();
|
||||
$aMiscOptions = $this->oParams->Get('options', array());
|
||||
$aMiscOptions = $this->oParams->Get('options', []);
|
||||
|
||||
$bUseSymbolicLinks = null;
|
||||
if ((isset($aMiscOptions['symlinks']) && $aMiscOptions['symlinks'])) {
|
||||
@@ -290,36 +272,49 @@ class ApplicationInstaller
|
||||
}
|
||||
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
self::DoCompile($aSelectedModules, $sSourceDir, $sExtensionDir, $sTargetDir, $sTargetEnvironment,
|
||||
$bUseSymbolicLinks, $aParamValues);
|
||||
self::DoCompile(
|
||||
$aSelectedModules,
|
||||
$sSourceDir,
|
||||
$sExtensionDir,
|
||||
$sTargetDir,
|
||||
$sTargetEnvironment,
|
||||
$bUseSymbolicLinks,
|
||||
$aParamValues
|
||||
);
|
||||
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'db-schema',
|
||||
'next-step-label' => 'Updating database schema',
|
||||
'percentage-completed' => 40,
|
||||
);
|
||||
];
|
||||
break;
|
||||
|
||||
case 'db-schema':
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules', array());
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules', []);
|
||||
$sTargetEnvironment = $this->GetTargetEnv();
|
||||
$sTargetDir = $this->GetTargetDir();
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
$bOldAddon = $this->oParams->Get('old_addon', false);
|
||||
$sUrl = $this->oParams->Get('url', '');
|
||||
|
||||
self::DoUpdateDBSchema($aSelectedModules, $sTargetDir, $aParamValues, $sTargetEnvironment,
|
||||
$bOldAddon, $sUrl);
|
||||
self::DoUpdateDBSchema(
|
||||
$aSelectedModules,
|
||||
$sTargetDir,
|
||||
$aParamValues,
|
||||
$sTargetEnvironment,
|
||||
$bOldAddon,
|
||||
$sUrl
|
||||
);
|
||||
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'after-db-create',
|
||||
'next-step-label' => 'Creating profiles',
|
||||
'percentage-completed' => 60,
|
||||
);
|
||||
];
|
||||
break;
|
||||
|
||||
case 'after-db-create':
|
||||
@@ -330,19 +325,27 @@ class ApplicationInstaller
|
||||
$sAdminUser = $aAdminParams['user'];
|
||||
$sAdminPwd = $aAdminParams['pwd'];
|
||||
$sAdminLanguage = $aAdminParams['language'];
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules', array());
|
||||
$aSelectedModules = $this->oParams->Get('selected_modules', []);
|
||||
$bOldAddon = $this->oParams->Get('old_addon', false);
|
||||
|
||||
self::AfterDBCreate($sTargetDir, $aParamValues, $sAdminUser, $sAdminPwd, $sAdminLanguage,
|
||||
$aSelectedModules, $sTargetEnvironment, $bOldAddon);
|
||||
self::AfterDBCreate(
|
||||
$sTargetDir,
|
||||
$aParamValues,
|
||||
$sAdminUser,
|
||||
$sAdminPwd,
|
||||
$sAdminLanguage,
|
||||
$aSelectedModules,
|
||||
$sTargetEnvironment,
|
||||
$bOldAddon
|
||||
);
|
||||
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'status' => self::OK,
|
||||
'message' => '',
|
||||
'next-step' => 'load-data',
|
||||
'next-step-label' => 'Loading data',
|
||||
'percentage-completed' => 80,
|
||||
);
|
||||
];
|
||||
break;
|
||||
|
||||
case 'load-data':
|
||||
@@ -353,16 +356,22 @@ class ApplicationInstaller
|
||||
$bOldAddon = $this->oParams->Get('old_addon', false);
|
||||
$bSampleData = ($this->oParams->Get('sample_data', 0) == 1);
|
||||
|
||||
self::DoLoadFiles($aSelectedModules, $sTargetDir, $aParamValues, $sTargetEnvironment, $bOldAddon,
|
||||
$bSampleData);
|
||||
self::DoLoadFiles(
|
||||
$aSelectedModules,
|
||||
$sTargetDir,
|
||||
$aParamValues,
|
||||
$sTargetEnvironment,
|
||||
$bOldAddon,
|
||||
$bSampleData
|
||||
);
|
||||
|
||||
$aResult = array(
|
||||
$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':
|
||||
@@ -371,51 +380,56 @@ class ApplicationInstaller
|
||||
$sPreviousConfigFile = $this->oParams->Get('previous_configuration_file', '');
|
||||
$sDataModelVersion = $this->oParams->Get('datamodel_version', '0.0.0');
|
||||
$bOldAddon = $this->oParams->Get('old_addon', false);
|
||||
$aSelectedModuleCodes = $this->oParams->Get('selected_modules', array());
|
||||
$aSelectedExtensionCodes = $this->oParams->Get('selected_extensions', array());
|
||||
$aSelectedModuleCodes = $this->oParams->Get('selected_modules', []);
|
||||
$aSelectedExtensionCodes = $this->oParams->Get('selected_extensions', []);
|
||||
$aParamValues = $this->oParams->GetParamForConfigArray();
|
||||
|
||||
self::DoCreateConfig($sTargetDir, $sPreviousConfigFile, $sTargetEnvironment, $sDataModelVersion,
|
||||
$bOldAddon, $aSelectedModuleCodes, $aSelectedExtensionCodes, $aParamValues, $sInstallComment);
|
||||
self::DoCreateConfig(
|
||||
$sTargetDir,
|
||||
$sPreviousConfigFile,
|
||||
$sTargetEnvironment,
|
||||
$sDataModelVersion,
|
||||
$bOldAddon,
|
||||
$aSelectedModuleCodes,
|
||||
$aSelectedExtensionCodes,
|
||||
$aParamValues,
|
||||
$sInstallComment
|
||||
);
|
||||
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'status' => self::INFO,
|
||||
'message' => 'Configuration file created',
|
||||
'next-step' => '',
|
||||
'next-step-label' => 'Completed',
|
||||
'percentage-completed' => 100,
|
||||
);
|
||||
];
|
||||
$this->ExitReadOnlyMode();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'status' => self::ERROR,
|
||||
'message' => '',
|
||||
'next-step' => '',
|
||||
'next-step-label' => "Unknown setup step '$sStep'.",
|
||||
'percentage-completed' => 100,
|
||||
);
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$aResult = array(
|
||||
} 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)
|
||||
{
|
||||
foreach ($e->getTrace() as $aTrace) {
|
||||
$sLine = empty($aTrace['line']) ? "" : $aTrace['line'];
|
||||
$sFile = empty($aTrace['file']) ? "" : $aTrace['file'];
|
||||
$sClass = empty($aTrace['class']) ? "" : $aTrace['class'];
|
||||
@@ -425,9 +439,7 @@ class ApplicationInstaller
|
||||
SetupLog::Ok("#$idx $sFile($sLine): $sVerb(...)");
|
||||
$idx++;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
$fDuration = round(microtime(true) - $fStart, 2);
|
||||
SetupLog::Info("##### STEP {$sStep} duration: {$fDuration}s");
|
||||
}
|
||||
@@ -437,13 +449,11 @@ class ApplicationInstaller
|
||||
|
||||
private function EnterReadOnlyMode()
|
||||
{
|
||||
if ($this->GetTargetEnv() != 'production')
|
||||
{
|
||||
if ($this->GetTargetEnv() != 'production') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SetupUtils::IsInReadOnlyMode())
|
||||
{
|
||||
if (SetupUtils::IsInReadOnlyMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -452,25 +462,21 @@ class ApplicationInstaller
|
||||
|
||||
private function ExitReadOnlyMode()
|
||||
{
|
||||
if ($this->GetTargetEnv() != 'production')
|
||||
{
|
||||
if ($this->GetTargetEnv() != 'production') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetupUtils::IsInReadOnlyMode())
|
||||
{
|
||||
if (!SetupUtils::IsInReadOnlyMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetupUtils::ExitReadOnlyMode();
|
||||
}
|
||||
|
||||
|
||||
protected static function DoCopy($aCopies)
|
||||
{
|
||||
$aReports = array();
|
||||
foreach ($aCopies as $aCopy)
|
||||
{
|
||||
$aReports = [];
|
||||
foreach ($aCopies as $aCopy) {
|
||||
$sSource = $aCopy['source'];
|
||||
$sDestination = APPROOT.$aCopy['destination'];
|
||||
|
||||
@@ -479,12 +485,9 @@ class ApplicationInstaller
|
||||
SetupUtils::copydir($sSource, $sDestination);
|
||||
$aReports[] = "'{$aCopy['source']}' to '{$aCopy['destination']}' (OK)";
|
||||
}
|
||||
if (count($aReports) > 0)
|
||||
{
|
||||
if (count($aReports) > 0) {
|
||||
$sReport = "Copies: ".count($aReports).': '.implode('; ', $aReports);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$sReport = "No file copy";
|
||||
}
|
||||
return $sReport;
|
||||
@@ -513,7 +516,6 @@ class ApplicationInstaller
|
||||
$oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $aSelectedModules
|
||||
* @param string $sSourceDir
|
||||
@@ -542,28 +544,24 @@ class ApplicationInstaller
|
||||
}
|
||||
|
||||
$sSourcePath = APPROOT.$sSourceDir;
|
||||
$aDirsToScan = array($sSourcePath);
|
||||
$aDirsToScan = [$sSourcePath];
|
||||
$sExtensionsPath = APPROOT.$sExtensionDir;
|
||||
if (is_dir($sExtensionsPath))
|
||||
{
|
||||
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 (is_dir($sExtraPath)) {
|
||||
// if the extra dir exists, scan it for additional modules as well
|
||||
$aDirsToScan[] = $sExtraPath;
|
||||
}
|
||||
$sTargetPath = APPROOT.$sTargetDir;
|
||||
|
||||
if (!is_dir($sSourcePath))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (($sEnvironment == 'production') && !$bIsAlreadyInMaintenanceMode) {
|
||||
$sConfigFilePath = utils::GetConfigFilePath($sEnvironment);
|
||||
if (is_file($sConfigFilePath)) {
|
||||
$oConfig = new Config($sConfigFilePath);
|
||||
@@ -578,21 +576,15 @@ class ApplicationInstaller
|
||||
SetupUtils::EnterMaintenanceMode($oConfig);
|
||||
}
|
||||
|
||||
if (!is_dir($sTargetPath))
|
||||
{
|
||||
if (!mkdir($sTargetPath))
|
||||
{
|
||||
if (!is_dir($sTargetPath)) {
|
||||
if (!mkdir($sTargetPath)) {
|
||||
throw new Exception("Failed to create directory '$sTargetPath', please check the rights of the web server");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// adjust the rights if and only if the directory was just created
|
||||
// owner:rwx user/group:rx
|
||||
chmod($sTargetPath, 0755);
|
||||
}
|
||||
}
|
||||
else if (substr($sTargetPath, 0, strlen(APPROOT)) == APPROOT)
|
||||
{
|
||||
} 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);
|
||||
}
|
||||
@@ -603,25 +595,21 @@ class ApplicationInstaller
|
||||
$oFactory->LoadModule($oDictModule);
|
||||
|
||||
$sDeltaFile = APPROOT.'core/datamodel.core.xml';
|
||||
if (file_exists($sDeltaFile))
|
||||
{
|
||||
if (file_exists($sDeltaFile)) {
|
||||
$oCoreModule = new MFCoreModule('core', 'Core Module', $sDeltaFile);
|
||||
$oFactory->LoadModule($oCoreModule);
|
||||
}
|
||||
$sDeltaFile = APPROOT.'application/datamodel.application.xml';
|
||||
if (file_exists($sDeltaFile))
|
||||
{
|
||||
if (file_exists($sDeltaFile)) {
|
||||
$oApplicationModule = new MFCoreModule('application', 'Application Module', $sDeltaFile);
|
||||
$oFactory->LoadModule($oApplicationModule);
|
||||
}
|
||||
|
||||
$aModules = $oFactory->FindModules();
|
||||
|
||||
foreach($aModules as $oModule)
|
||||
{
|
||||
foreach ($aModules as $oModule) {
|
||||
$sModule = $oModule->GetName();
|
||||
if (in_array($sModule, $aSelectedModules))
|
||||
{
|
||||
if (in_array($sModule, $aSelectedModules)) {
|
||||
$oFactory->LoadModule($oModule);
|
||||
}
|
||||
}
|
||||
@@ -629,8 +617,7 @@ class ApplicationInstaller
|
||||
$oFactory->SaveToFile(APPROOT.'data/datamodel-'.$sEnvironment.'.xml');
|
||||
|
||||
$sDeltaFile = APPROOT.'data/'.$sEnvironment.'.delta.xml';
|
||||
if (file_exists($sDeltaFile))
|
||||
{
|
||||
if (file_exists($sDeltaFile)) {
|
||||
$oDelta = new MFDeltaModule($sDeltaFile);
|
||||
$oFactory->LoadModule($oDelta);
|
||||
$oFactory->SaveToFile(APPROOT.'data/datamodel-'.$sEnvironment.'-with-delta.xml');
|
||||
@@ -648,8 +635,7 @@ class ApplicationInstaller
|
||||
|
||||
// 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))
|
||||
{
|
||||
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);
|
||||
@@ -660,13 +646,11 @@ class ApplicationInstaller
|
||||
// Set an "Instance UUID" identifying this machine based on a file located in the data directory
|
||||
$sInstanceUUIDFile = APPROOT.'data/instance.txt';
|
||||
SetupUtils::builddir(APPROOT.'data');
|
||||
if (!file_exists($sInstanceUUIDFile))
|
||||
{
|
||||
if (!file_exists($sInstanceUUIDFile)) {
|
||||
$sIntanceUUID = utils::CreateUUID('filesystem');
|
||||
file_put_contents($sInstanceUUIDFile, $sIntanceUUID);
|
||||
}
|
||||
if (($sEnvironment == 'production') && !$bIsAlreadyInMaintenanceMode)
|
||||
{
|
||||
if (($sEnvironment == 'production') && !$bIsAlreadyInMaintenanceMode) {
|
||||
SetupUtils::ExitMaintenanceMode();
|
||||
}
|
||||
}
|
||||
@@ -698,12 +682,11 @@ class ApplicationInstaller
|
||||
$oConfig = new Config();
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
|
||||
|
||||
if ($bOldAddon)
|
||||
{
|
||||
if ($bOldAddon) {
|
||||
// Old version of the add-on for backward compatibility with pre-2.0 data models
|
||||
$oConfig->SetAddons(array(
|
||||
$oConfig->SetAddons([
|
||||
'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
|
||||
@@ -717,39 +700,32 @@ class ApplicationInstaller
|
||||
// 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')
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
} 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
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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...");
|
||||
@@ -757,14 +733,10 @@ class ApplicationInstaller
|
||||
CMDBSource::Query($sCleanup);
|
||||
SetupLog::Info("Cleanup completed successfully.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetupLog::Info("Ok, nothing to cleanup.");
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Info("Cleanup of orphan records in `{$sDBPrefix}priv_change` failed: ".$e->getMessage());
|
||||
}
|
||||
|
||||
@@ -775,15 +747,13 @@ class ApplicationInstaller
|
||||
$aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT.$sModulesDir);
|
||||
$oProductionEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'BeforeDatabaseCreation');
|
||||
|
||||
if(!$oProductionEnv->CreateDatabaseStructure(MetaModel::GetConfig(), $sMode))
|
||||
{
|
||||
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 === '')
|
||||
{
|
||||
if ($sUUID === '') {
|
||||
$sUUID = utils::CreateUUID('database');
|
||||
DBProperty::SetProperty('database_uuid', $sUUID, 'Installation/upgrade of '.ITOP_APPLICATION, 'Unique ID of this '.ITOP_APPLICATION.' Database');
|
||||
}
|
||||
@@ -792,12 +762,10 @@ class ApplicationInstaller
|
||||
// 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
|
||||
{
|
||||
try {
|
||||
$sCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_change` WHERE `origin` IS NULL";
|
||||
$iCount = (int)CMDBSource::QueryToScalar($sCount);
|
||||
if ($iCount > 0)
|
||||
{
|
||||
if ($iCount > 0) {
|
||||
SetupLog::Info("Initializing '{$sDBPrefix}priv_change.origin' ($iCount records to update)");
|
||||
|
||||
// By default all uninitialized values are considered as 'interactive'
|
||||
@@ -812,13 +780,11 @@ class ApplicationInstaller
|
||||
$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 = array();
|
||||
foreach(array_keys(Dict::GetLanguages()) as $sLangCode)
|
||||
{
|
||||
$aSuffixes = [];
|
||||
foreach (array_keys(Dict::GetLanguages()) as $sLangCode) {
|
||||
Dict::SetUserLanguage($sLangCode);
|
||||
$sSuffix = CMDBSource::Quote('%'.Dict::S('Core:SyncDataExchangeComment'));
|
||||
$aSuffixes[$sSuffix] = true;
|
||||
@@ -830,26 +796,20 @@ class ApplicationInstaller
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
SetupLog::Info("Initialization of '{$sDBPrefix}priv_change.origin' completed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetupLog::Info("'{$sDBPrefix}priv_change.origin' already initialized, nothing to do.");
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} 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
|
||||
{
|
||||
try {
|
||||
$sCount = "SELECT COUNT(*) FROM `{$sDBPrefix}priv_async_task` WHERE `status` IS NULL";
|
||||
$iCount = (int)CMDBSource::QueryToScalar($sCount);
|
||||
if ($iCount > 0)
|
||||
{
|
||||
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)";
|
||||
@@ -859,14 +819,10 @@ class ApplicationInstaller
|
||||
CMDBSource::Query($sInit);
|
||||
|
||||
SetupLog::Info("Initialization of '{$sDBPrefix}priv_async_task.status' completed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetupLog::Info("'{$sDBPrefix}priv_async_task.status' already initialized, nothing to do.");
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error("Initializing '{$sDBPrefix}priv_async_task.status' failed: ".$e->getMessage());
|
||||
}
|
||||
|
||||
@@ -886,10 +842,15 @@ class ApplicationInstaller
|
||||
}
|
||||
|
||||
protected static function AfterDBCreate(
|
||||
$sModulesDir, $aParamValues, $sAdminUser, $sAdminPwd, $sAdminLanguage, $aSelectedModules, $sTargetEnvironment,
|
||||
$sModulesDir,
|
||||
$aParamValues,
|
||||
$sAdminUser,
|
||||
$sAdminPwd,
|
||||
$sAdminLanguage,
|
||||
$aSelectedModules,
|
||||
$sTargetEnvironment,
|
||||
$bOldAddon
|
||||
)
|
||||
{
|
||||
) {
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
@@ -901,12 +862,11 @@ class ApplicationInstaller
|
||||
$oConfig = new Config();
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
|
||||
|
||||
if ($bOldAddon)
|
||||
{
|
||||
if ($bOldAddon) {
|
||||
// Old version of the add-on for backward compatibility with pre-2.0 data models
|
||||
$oConfig->SetAddons(array(
|
||||
$oConfig->SetAddons([
|
||||
'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
|
||||
@@ -921,14 +881,10 @@ class ApplicationInstaller
|
||||
|
||||
$oProductionEnv->UpdatePredefinedObjects();
|
||||
|
||||
if($sMode == 'install')
|
||||
{
|
||||
if (!self::CreateAdminAccount(MetaModel::GetConfig(), $sAdminUser, $sAdminPwd, $sAdminLanguage))
|
||||
{
|
||||
if ($sMode == 'install') {
|
||||
if (!self::CreateAdminAccount(MetaModel::GetConfig(), $sAdminUser, $sAdminPwd, $sAdminLanguage)) {
|
||||
throw(new Exception("Failed to create the administrator account '$sAdminUser'"));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SetupLog::Info("Administrator account '$sAdminUser' created.");
|
||||
}
|
||||
}
|
||||
@@ -946,21 +902,21 @@ class ApplicationInstaller
|
||||
{
|
||||
SetupLog::Info('CreateAdminAccount');
|
||||
|
||||
if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage))
|
||||
{
|
||||
if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage)) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected static function DoLoadFiles(
|
||||
$aSelectedModules, $sModulesDir, $aParamValues, $sTargetEnvironment = 'production', $bOldAddon = false,
|
||||
$aSelectedModules,
|
||||
$sModulesDir,
|
||||
$aParamValues,
|
||||
$sTargetEnvironment = 'production',
|
||||
$bOldAddon = false,
|
||||
$bSampleData = false
|
||||
)
|
||||
{
|
||||
) {
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
@@ -970,19 +926,17 @@ class ApplicationInstaller
|
||||
$oConfig = new Config();
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir);
|
||||
|
||||
if ($bOldAddon)
|
||||
{
|
||||
if ($bOldAddon) {
|
||||
// Old version of the add-on for backward compatibility with pre-2.0 data models
|
||||
$oConfig->SetAddons(array(
|
||||
$oConfig->SetAddons([
|
||||
'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
$oProductionEnv = new RunTimeEnvironment($sTargetEnvironment);
|
||||
|
||||
//Load the MetaModel if needed (asynchronous mode)
|
||||
if (!self::$bMetaModelStarted)
|
||||
{
|
||||
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
|
||||
@@ -991,7 +945,7 @@ class ApplicationInstaller
|
||||
$aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, APPROOT.$sModulesDir);
|
||||
$oProductionEnv->LoadData($aAvailableModules, $aSelectedModules, $bSampleData);
|
||||
|
||||
// Perform after dbload setup tasks here
|
||||
// Perform after dbload setup tasks here
|
||||
//
|
||||
$oProductionEnv->CallInstallerHandlers($aAvailableModules, $aSelectedModules, 'AfterDataLoad');
|
||||
}
|
||||
@@ -1013,8 +967,15 @@ class ApplicationInstaller
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected static function DoCreateConfig(
|
||||
$sModulesDir, $sPreviousConfigFile, $sTargetEnvironment, $sDataModelVersion, $bOldAddon, $aSelectedModuleCodes,
|
||||
$aSelectedExtensionCodes, $aParamValues, $sInstallComment = null
|
||||
$sModulesDir,
|
||||
$sPreviousConfigFile,
|
||||
$sTargetEnvironment,
|
||||
$sDataModelVersion,
|
||||
$bOldAddon,
|
||||
$aSelectedModuleCodes,
|
||||
$aSelectedExtensionCodes,
|
||||
$aParamValues,
|
||||
$sInstallComment = null
|
||||
) {
|
||||
/**
|
||||
* @since 3.2.0 move the ContextTag init at the very beginning of the method
|
||||
@@ -1026,22 +987,16 @@ class ApplicationInstaller
|
||||
$sMode = $aParamValues['mode'];
|
||||
|
||||
$bPreserveModuleSettings = false;
|
||||
if ($sMode == 'upgrade')
|
||||
{
|
||||
try
|
||||
{
|
||||
if ($sMode == 'upgrade') {
|
||||
try {
|
||||
$oOldConfig = new Config($sPreviousConfigFile);
|
||||
$oConfig = clone($oOldConfig);
|
||||
$bPreserveModuleSettings = true;
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
// In case the previous configuration is corrupted... start with a blank new one
|
||||
$oConfig = new Config();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} 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
|
||||
@@ -1051,26 +1006,23 @@ class ApplicationInstaller
|
||||
$oConfig->Set('access_mode', ACCESS_FULL);
|
||||
// Final config update: add the modules
|
||||
$oConfig->UpdateFromParams($aParamValues, $sModulesDir, $bPreserveModuleSettings);
|
||||
if ($bOldAddon)
|
||||
{
|
||||
if ($bOldAddon) {
|
||||
// Old version of the add-on for backward compatibility with pre-2.0 data models
|
||||
$oConfig->SetAddons(array(
|
||||
$oConfig->SetAddons([
|
||||
'user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
// 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))
|
||||
{
|
||||
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))
|
||||
{
|
||||
if (!file_exists(APPCONF)) {
|
||||
mkdir(APPCONF);
|
||||
chmod(APPCONF, 0770); // RWX for owner and group, nothing for others
|
||||
SetupLog::Info("Created configuration directory: ".APPCONF);
|
||||
|
||||
Reference in New Issue
Block a user