Merge branch 'support/3.2' into develop

This commit is contained in:
odain
2025-11-07 20:33:14 +01:00
1837 changed files with 33034 additions and 34549 deletions

View File

@@ -1,10 +1,10 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\CoreUpdate\Controller;
require_once APPROOT.'setup/runtimeenv.class.inc.php';
@@ -42,8 +42,7 @@ class AjaxController extends Controller
*/
public function __construct($sViewPath = '', $sModuleName = 'core', $aAdditionalPaths = [])
{
if (!defined('MODULESROOT'))
{
if (!defined('MODULESROOT')) {
define('MODULESROOT', APPROOT.'env-production/');
}
@@ -67,28 +66,22 @@ class AjaxController extends Controller
{
$aParams = [];
try
{
try {
$sCanUpdateCore = FilesInformation::CanUpdateCore($sMessage);
$bCanUpdateCore = ($sCanUpdateCore == 'Yes');
$aParams['bStatus'] = $bCanUpdateCore;
if ($bCanUpdateCore)
{
if ($bCanUpdateCore) {
$aParams['sMessage'] = Dict::S('iTopUpdate:UI:CanCoreUpdate:Yes');
}
else
{
} else {
$sLink = utils::GetAbsoluteUrlAppRoot().'setup/';
$sLinkManualUpdate = 'https://www.itophub.io/wiki/page?id='.utils::GetItopVersionWikiSyntax().'%3Ainstall%3Aupgrading_itop#manually';
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CannotUpdateUseSetup', $sLink, $sLinkManualUpdate);
$aParams['sMessageDetails'] = $sMessage;
}
} catch (FileNotExistException $e)
{
} catch (FileNotExistException $e) {
$aParams['bStatus'] = false;
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:ErrorFileNotExist', $e->getMessage());
} catch (Exception $e)
{
} catch (Exception $e) {
$aParams['bStatus'] = false;
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:Error', $e->getMessage());
}
@@ -122,13 +115,11 @@ class AjaxController extends Controller
public function OperationEnterMaintenance()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken();
SetupUtils::EnterReadOnlyMode(MetaModel::GetConfig());
$iResponseCode = 200;
} catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error("EnterMaintenance: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -139,13 +130,11 @@ class AjaxController extends Controller
public function OperationExitMaintenance()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken(true);
SetupUtils::ExitReadOnlyMode();
$iResponseCode = 200;
} catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error("ExitMaintenance: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -156,13 +145,11 @@ class AjaxController extends Controller
public function OperationBackup()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken();
CoreUpdater::Backup();
$iResponseCode = 200;
} catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error("Backup: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -173,13 +160,11 @@ class AjaxController extends Controller
public function OperationFilesArchive()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken();
CoreUpdater::CreateItopArchive();
$iResponseCode = 200;
} catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error("FilesArchive: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -190,13 +175,11 @@ class AjaxController extends Controller
public function OperationCopyFiles()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken();
CoreUpdater::CopyCoreFiles();
$iResponseCode = 200;
} catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error("CopyFiles: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -208,14 +191,11 @@ class AjaxController extends Controller
public function OperationCheckCompile()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken();
CoreUpdater::CheckCompile();
$iResponseCode = 200;
}
catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error("Compile: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -227,14 +207,11 @@ class AjaxController extends Controller
public function OperationCompile()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken();
CoreUpdater::Compile();
$iResponseCode = 200;
}
catch (Exception $e)
{
} catch (Exception $e) {
IssueLog::Error("Compile: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -246,13 +223,11 @@ class AjaxController extends Controller
public function OperationUpdateDatabase()
{
$aParams = [];
try
{
try {
SetupUtils::CheckSetupToken();
CoreUpdater::UpdateDatabase();
$iResponseCode = 200;
}
catch (Exception $e) {
} catch (Exception $e) {
IssueLog::Error("Compile: ".$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;
@@ -261,7 +236,7 @@ class AjaxController extends Controller
$this->DisplayJSONPage($aParams, $iResponseCode);
}
function OperationRebuildToolkitEnvironment()
public function OperationRebuildToolkitEnvironment()
{
$sTransactionId = utils::GetNewTransactionId();
$aParams = [];
@@ -275,8 +250,7 @@ class AjaxController extends Controller
$oEnvironment = new RunTimeEnvironment('production');
$oEnvironment->WriteConfigFileSafe($oConfig);
$oEnvironment->CompileFrom('production');
}
catch (Exception $e) {
} catch (Exception $e) {
IssueLog::Error('RebuildToolkitEnvironment: '.$e->getMessage());
$aParams['sError'] = $e->getMessage();
$iResponseCode = 500;

View File

@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -54,7 +55,7 @@ class UpdateController extends Controller
$bConfigParamSetupLaunchButtonEnabled = $oConfig->Get('setup.launch_button.enabled');
if (is_null($bConfigParamSetupLaunchButtonEnabled)) {
$bIsSetupLaunchButtonEnabled = utils::IsDevelopmentEnvironment();
} else if (false === $bConfigParamSetupLaunchButtonEnabled) {
} elseif (false === $bConfigParamSetupLaunchButtonEnabled) {
$bIsSetupLaunchButtonEnabled = false;
} else {
$bIsSetupLaunchButtonEnabled = $bConfigParamSetupLaunchButtonEnabled || utils::IsDevelopmentEnvironment();
@@ -108,8 +109,7 @@ class UpdateController extends Controller
} else {
throw new Exception(Dict::S('iTopUpdate:Error:NoFile'));
}
}
catch (Exception $e) {
} catch (Exception $e) {
$iError = UPLOAD_ERR_NO_FILE;
$sError = $e->getMessage();
}
@@ -163,19 +163,19 @@ class UpdateController extends Controller
$this->DisplaySetupPage($aParams);
}
public function OperationRunSetup()
{
SetupUtils::CheckSetupToken(true);
$sConfigFile = APPCONF.'production/'.ITOP_CONFIG_FILE;
@chmod($sConfigFile, 0770);
$sRedirectURL = utils::GetAbsoluteUrlAppRoot().'setup/index.php';
header("Location: $sRedirectURL");
}
public function OperationRunSetup()
{
SetupUtils::CheckSetupToken(true);
$sConfigFile = APPCONF.'production/'.ITOP_CONFIG_FILE;
@chmod($sConfigFile, 0770);
$sRedirectURL = utils::GetAbsoluteUrlAppRoot().'setup/index.php';
header("Location: $sRedirectURL");
}
private function GetPreviousInstallations()
{
return DBToolsUtils::GetPreviousInstallations();
}
private function GetPreviousInstallations()
{
return DBToolsUtils::GetPreviousInstallations();
}
// Returns a file size limit in bytes based on the PHP upload_max_filesize
// and post_max_size

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -25,8 +26,8 @@ require_once APPROOT.'setup/runtimeenv.class.inc.php';
final class CoreUpdater
{
const DOWNLOAD_DIR = APPROOT.'data/downloaded-core/';
const UPDATE_DIR = APPROOT.'data/core-update/';
public const DOWNLOAD_DIR = APPROOT.'data/downloaded-core/';
public const UPDATE_DIR = APPROOT.'data/core-update/';
/**
* @param bool $bDoBackup
@@ -38,28 +39,22 @@ final class CoreUpdater
set_time_limit(600);
// Extract updater file from the new version if available
if (is_file(APPROOT.'setup/appupgradecopy.php'))
{
if (is_file(APPROOT.'setup/appupgradecopy.php')) {
// Remove previous specific updater
@unlink(APPROOT.'setup/appupgradecopy.php');
}
if (is_file(self::UPDATE_DIR.'web/setup/appupgradecopy.php'))
{
if (is_file(self::UPDATE_DIR.'web/setup/appupgradecopy.php')) {
SetupLog::Info('itop-core-update: Use updater provided in the archive');
self::CopyFile(self::UPDATE_DIR.'web/setup/appupgradecopy.php', APPROOT.'setup/appupgradecopy.php');
@include_once(APPROOT.'setup/appupgradecopy.php');
}
try
{
if (function_exists('AppUpgradeCopyFiles'))
{
try {
if (function_exists('AppUpgradeCopyFiles')) {
// start the update
set_time_limit(600);
AppUpgradeCopyFiles(self::UPDATE_DIR.'web/');
}
else
{
} else {
// Local function for older iTop versions
SetupLog::Info('itop-core-update: Use default updater');
self::LocalUpdateCoreFiles(self::UPDATE_DIR.'web/');
@@ -68,23 +63,19 @@ final class CoreUpdater
FilesIntegrity::CheckInstallationIntegrity(APPROOT);
SetupLog::Info('itop-core-update: Files integrity OK');
// Reset the opcache since otherwise the "core" files may still be cached !!
if (function_exists('opcache_reset'))
{
if (function_exists('opcache_reset')) {
// Zend opcode cache
opcache_reset();
}
if (function_exists('apc_clear_cache'))
{
if (function_exists('apc_clear_cache')) {
// APC(u) cache
apc_clear_cache();
}
} catch (Exception $e)
{
} catch (Exception $e) {
SetupLog::error($e->getMessage());
SetupLog::Info('itop-core-update: ended');
throw $e;
} finally
{
} finally {
self::RRmdir(self::UPDATE_DIR);
}
}
@@ -94,8 +85,7 @@ final class CoreUpdater
*/
public static function CheckCompile()
{
try
{
try {
// Compile code
SetupLog::Info('itop-core-update: Start checking compilation');
@@ -107,15 +97,11 @@ final class CoreUpdater
$oRuntimeEnv->Rollback();
SetupLog::Info('itop-core-update: Checking compilation done');
}
catch (Exception $e)
{
} catch (Exception $e) {
SetupLog::error($e->getMessage());
try
{
try {
SetupUtils::ExitReadOnlyMode();
} catch (Exception $e1)
{
} catch (Exception $e1) {
IssueLog::Error("ExitMaintenance: ".$e1->getMessage());
}
throw $e;
@@ -127,8 +113,7 @@ final class CoreUpdater
*/
public static function Compile()
{
try
{
try {
// Compile code
SetupLog::Info('itop-core-update: Start compilation');
@@ -138,15 +123,11 @@ final class CoreUpdater
$oRuntimeEnv->CompileFrom('production');
SetupLog::Info('itop-core-update: Compilation done');
}
catch (Exception $e)
{
} catch (Exception $e) {
SetupLog::error($e->getMessage());
try
{
try {
SetupUtils::ExitReadOnlyMode();
} catch (Exception $e1)
{
} catch (Exception $e1) {
IssueLog::Error("ExitMaintenance: ".$e1->getMessage());
}
throw $e;
@@ -158,8 +139,7 @@ final class CoreUpdater
*/
public static function UpdateDatabase()
{
try
{
try {
SetupLog::Info('itop-core-update: Start Update database');
$sFinalEnv = 'production';
@@ -172,18 +152,14 @@ final class CoreUpdater
$sModulesDirToKeep = $oRuntimeEnv->GetBuildDir();
$aDirsToScanForModules = [
$sModulesDirToKeep,
APPROOT.'extensions'
APPROOT.'extensions',
];
$aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $aDirsToScanForModules);
$aSelectedModules = [];
foreach ($aAvailableModules as $sModuleId => $aModule)
{
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE))
{
foreach ($aAvailableModules as $sModuleId => $aModule) {
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) {
continue;
}
else
{
} else {
$aSelectedModules[] = $sModuleId;
}
}
@@ -198,32 +174,30 @@ final class CoreUpdater
$oExtensionsMap = new iTopExtensionsMap();
// Default choices = as before
$oExtensionsMap->LoadChoicesFromDatabase($oConfig);
foreach ($oExtensionsMap->GetAllExtensions() as $oExtension)
{
foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) {
// Plus all "remote" extensions
if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE)
{
if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE) {
$oExtensionsMap->MarkAsChosen($oExtension->sCode);
}
}
$aSelectedExtensionCodes = [];
foreach ($oExtensionsMap->GetChoices() as $oExtension)
{
foreach ($oExtensionsMap->GetChoices() as $oExtension) {
$aSelectedExtensionCodes[] = $oExtension->sCode;
}
$oRuntimeEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModules,
$aSelectedExtensionCodes, 'Done by the iTop Core Updater');
$oRuntimeEnv->RecordInstallation(
$oConfig,
$sDataModelVersion,
$aSelectedModules,
$aSelectedExtensionCodes,
'Done by the iTop Core Updater'
);
SetupLog::Info('itop-core-update: Update database done');
}
catch (Exception $e)
{
} catch (Exception $e) {
SetupLog::error($e->getMessage());
try
{
try {
SetupUtils::ExitReadOnlyMode();
} catch (Exception $e1)
{
} catch (Exception $e1) {
IssueLog::Error("ExitMaintenance: ".$e1->getMessage());
}
throw $e;
@@ -247,8 +221,7 @@ final class CoreUpdater
*/
private static function ExtractUpdateFile($sArchiveFile)
{
if (!utils::EndsWith($sArchiveFile, '.zip'))
{
if (!utils::EndsWith($sArchiveFile, '.zip')) {
throw new Exception(Dict::S('iTopUpdate:Error:BadFileFormat'));
}
@@ -267,8 +240,7 @@ final class CoreUpdater
{
$sBackupName = self::GetBackupName();
$sBackupFile = self::GetBackupFile();
if (file_exists($sBackupFile))
{
if (file_exists($sBackupFile)) {
@unlink($sBackupFile);
}
@@ -282,14 +254,12 @@ final class CoreUpdater
{
set_time_limit(0);
$sItopArchiveFile = self::GetItopArchiveFile();
if (file_exists($sItopArchiveFile))
{
if (file_exists($sItopArchiveFile)) {
@unlink($sItopArchiveFile);
}
$sTempFile = sys_get_temp_dir().'/'.basename($sItopArchiveFile);
if (file_exists($sTempFile))
{
if (file_exists($sTempFile)) {
@unlink($sTempFile);
}
@@ -303,17 +273,13 @@ final class CoreUpdater
self::ZipFolder(realpath(APPROOT), $oZipArchive, strlen("$sParentPath/"));
$oZipArchive->close();
if (!file_exists($sTempFile))
{
if (!file_exists($sTempFile)) {
SetupLog::Error("Failed to create itop archive $sTempFile");
}
if (@rename($sTempFile, $sItopArchiveFile))
{
if (@rename($sTempFile, $sItopArchiveFile)) {
SetupLog::Info("Archive $sItopArchiveFile Created");
}
else
{
} else {
SetupLog::Error("Failed to create archive $sItopArchiveFile");
}
}
@@ -335,12 +301,10 @@ final class CoreUpdater
$oMutex = new iTopMutex('backup.'.utils::GetCurrentEnvironment());
$oMutex->Lock();
try
{
try {
$oBackup->CreateCompressedBackup($sTargetFile);
SetupLog::Info('itop-core-update: Backup done: '.$sTargetFile);
} catch (Exception $e)
{
} catch (Exception $e) {
$oMutex->Unlock();
throw $e;
}
@@ -355,61 +319,44 @@ final class CoreUpdater
*/
public static function CopyDir($sSource, $sDest)
{
if (is_dir($sSource))
{
if (!is_dir($sDest))
{
if (is_dir($sSource)) {
if (!is_dir($sDest)) {
@mkdir($sDest, 0755);
}
$aFiles = scandir($sSource);
if (sizeof($aFiles) > 0)
{
foreach ($aFiles as $sFile)
{
if ($sFile == '.' || $sFile == '..' || $sFile == '.svn' || $sFile == '.git')
{
if (sizeof($aFiles) > 0) {
foreach ($aFiles as $sFile) {
if ($sFile == '.' || $sFile == '..' || $sFile == '.svn' || $sFile == '.git') {
// Skip
continue;
}
if (is_dir($sSource.'/'.$sFile))
{
if (is_dir($sSource.'/'.$sFile)) {
// Recurse
self::CopyDir($sSource.'/'.$sFile, $sDest.'/'.$sFile);
}
else
{
if (is_link($sDest.'/'.$sFile))
{
} else {
if (is_link($sDest.'/'.$sFile)) {
unlink($sDest.'/'.$sFile);
}
self::CopyFile($sSource.'/'.$sFile, $sDest.'/'.$sFile);
}
}
}
}
elseif (is_file($sSource))
{
} elseif (is_file($sSource)) {
self::CopyFile($sSource, $sDest);
}
}
public static function RRmdir($sDir)
{
if (is_dir($sDir))
{
if (is_dir($sDir)) {
$oDir = @opendir($sDir);
while (false !== ($sFile = @readdir($oDir)))
{
if (($sFile != '.') && ($sFile != '..'))
{
while (false !== ($sFile = @readdir($oDir))) {
if (($sFile != '.') && ($sFile != '..')) {
$sFull = $sDir.'/'.$sFile;
if (is_dir($sFull))
{
if (is_dir($sFull)) {
self::RRmdir($sFull);
}
else
{
} else {
@unlink($sFull);
}
}
@@ -427,14 +374,11 @@ final class CoreUpdater
*/
public static function CopyFile($sSource, $sDest)
{
if (is_file($sSource))
{
if (!@copy($sSource, $sDest))
{
if (is_file($sSource)) {
if (!@copy($sSource, $sDest)) {
// Try changing the mode of the file
@chmod($sDest, 0644);
if (!@copy($sSource, $sDest))
{
if (!@copy($sSource, $sDest)) {
throw new Exception(Dict::Format('iTopUpdate:Error:Copy', $sSource, $sDest));
}
}
@@ -451,28 +395,22 @@ final class CoreUpdater
private static function ZipFolder($sFolder, &$oZipArchive, $iStrippedLength)
{
$oFolder = opendir($sFolder);
while (false !== ($sFile = readdir($oFolder)))
{
if (($sFile == '.') || ($sFile == '..'))
{
while (false !== ($sFile = readdir($oFolder))) {
if (($sFile == '.') || ($sFile == '..')) {
continue;
}
$sFilePath = "$sFolder/$sFile";
$sLocalItopPath = utils::LocalPath($sFilePath);
if ($sLocalItopPath == 'data/backups' || $sLocalItopPath == 'log')
{
if ($sLocalItopPath == 'data/backups' || $sLocalItopPath == 'log') {
continue;
}
// Remove prefix from file path before add to zip.
$sLocalPath = substr($sFilePath, $iStrippedLength);
if (is_file($sFilePath))
{
if (is_file($sFilePath)) {
$oZipArchive->addFile($sFilePath, $sLocalPath);
}
elseif (is_dir($sFilePath))
{
} elseif (is_dir($sFilePath)) {
// Add sub-directory.
$oZipArchive->addEmptyDir($sLocalPath);
self::ZipFolder($sFilePath, $oZipArchive, $iStrippedLength);
@@ -524,8 +462,7 @@ final class CoreUpdater
*/
public static function ExtractDownloadedFile($sArchiveFile)
{
try
{
try {
// Extract archive file
self::ExtractUpdateFile($sArchiveFile);
@@ -536,12 +473,10 @@ final class CoreUpdater
FilesIntegrity::CheckInstallationIntegrity($sRootPath);
SetupLog::Info('itop-core-update: Files integrity OK');
} catch (Exception $e)
{
} catch (Exception $e) {
self::RRmdir(self::UPDATE_DIR);
throw $e;
} finally
{
} finally {
self::RRmdir(self::DOWNLOAD_DIR);
}
}
@@ -552,51 +487,42 @@ final class CoreUpdater
*/
public static function GetVersionToInstall()
{
try
{
try {
$sConfigFile = self::UPDATE_DIR.'web/core/config.class.inc.php';
if (!is_file($sConfigFile))
{
if (!is_file($sConfigFile)) {
throw new Exception(Dict::S(Dict::S('iTopUpdate:Error:BadFileContent')));
}
$sContents = file_get_contents($sConfigFile);
preg_match_all("@define\('(?<name>ITOP_[^']*)', '(?<value>[^']*)'\);@", $sContents, $aMatches);
if (empty($aMatches))
{
if (empty($aMatches)) {
throw new Exception(Dict::S(Dict::S('iTopUpdate:Error:BadFileContent')));
}
$aValues = [];
foreach ($aMatches['name'] as $index => $sName)
{
foreach ($aMatches['name'] as $index => $sName) {
$aValues[$sName] = $aMatches['value'][$index];
}
if ($aValues['ITOP_APPLICATION'] != ITOP_APPLICATION)
{
if ($aValues['ITOP_APPLICATION'] != ITOP_APPLICATION) {
throw new Exception(Dict::S('iTopUpdate:Error:BadItopProduct'));
}
// Extract updater file from the new version if available
if (is_file(APPROOT.'setup/appupgradecheck.php'))
{
if (is_file(APPROOT.'setup/appupgradecheck.php')) {
// Remove previous specific updater
@unlink(APPROOT.'setup/appupgradecheck.php');
}
if (is_file(self::UPDATE_DIR.'web/setup/appupgradecheck.php'))
{
if (is_file(self::UPDATE_DIR.'web/setup/appupgradecheck.php')) {
SetupLog::Info('itop-core-update: Use updater provided in the archive');
self::CopyFile(self::UPDATE_DIR.'web/setup/appupgradecheck.php', APPROOT.'setup/appupgradecheck.php');
@include_once(APPROOT.'setup/appupgradecheck.php');
}
if (function_exists('AppUpgradeCheckInstall'))
{
if (function_exists('AppUpgradeCheckInstall')) {
AppUpgradeCheckInstall();
}
return Dict::Format('UI:iTopVersion:Long', $aValues['ITOP_APPLICATION'], $aValues['ITOP_VERSION'], $aValues['ITOP_REVISION'], $aValues['ITOP_BUILD_DATE']);
} catch (Exception $e)
{
} catch (Exception $e) {
self::RRmdir(self::UPDATE_DIR);
self::RRmdir(self::DOWNLOAD_DIR);
throw $e;

View File

@@ -1,10 +1,10 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\CoreUpdate\Service;
require_once(APPROOT."setup/runtimeenv.class.inc.php");
@@ -29,14 +29,11 @@ class RunTimeEnvironmentCoreUpdater extends RunTimeEnvironment
{
parent::__construct($sEnvironment, $bAutoCommit);
if ($sEnvironment != $this->sTargetEnv)
{
if (is_dir(APPROOT.'/env-'.$this->sTargetEnv))
{
if ($sEnvironment != $this->sTargetEnv) {
if (is_dir(APPROOT.'/env-'.$this->sTargetEnv)) {
SetupUtils::rrmdir(APPROOT.'/env-'.$this->sTargetEnv);
}
if (is_dir(APPROOT.'/data/'.$this->sTargetEnv.'-modules'))
{
if (is_dir(APPROOT.'/data/'.$this->sTargetEnv.'-modules')) {
SetupUtils::rrmdir(APPROOT.'/data/'.$this->sTargetEnv.'-modules');
}
SetupUtils::copydir(APPROOT.'/data/'.$sEnvironment.'-modules', APPROOT.'/data/'.$this->sTargetEnv.'-modules');
@@ -63,17 +60,14 @@ class RunTimeEnvironmentCoreUpdater extends RunTimeEnvironment
*/
public static function CheckDirectory($sDir)
{
if (!is_dir($sDir))
{
if (!@mkdir($sDir,0770))
{
if (!is_dir($sDir)) {
if (!@mkdir($sDir, 0770)) {
throw new Exception('Creating directory '.$sDir.' is denied (Check access rights)');
}
}
// Try create a file
$sTempFile = $sDir.'/__itop_temp_file__';
if (!@touch($sTempFile))
{
if (!@touch($sTempFile)) {
throw new Exception('Write access to '.$sDir.' is denied (Check access rights)');
}
@unlink($sTempFile);
@@ -93,8 +87,7 @@ class RunTimeEnvironmentCoreUpdater extends RunTimeEnvironment
$oConfig->UpdateIncludes('env-'.$this->sTargetEnv);
if (is_null($sEnvironmentLabel))
{
if (is_null($sEnvironmentLabel)) {
$sEnvironmentLabel = $this->sTargetEnv;
}
$oConfig->Set('app_env_label', $sEnvironmentLabel, 'application updater');
@@ -110,19 +103,14 @@ class RunTimeEnvironmentCoreUpdater extends RunTimeEnvironment
*/
protected function GetConfig($sEnvironment = null)
{
if (is_null($sEnvironment))
{
if (is_null($sEnvironment)) {
$sEnvironment = $this->sTargetEnv;
}
$sFile = APPCONF.$sEnvironment.'/'.ITOP_CONFIG_FILE;
if (file_exists($sFile))
{
try
{
if (file_exists($sFile)) {
try {
return new Config($sFile);
}
catch (Exception $e)
{
} catch (Exception $e) {
}
}
throw new Exception('No configuration file available');
@@ -134,8 +122,7 @@ class RunTimeEnvironmentCoreUpdater extends RunTimeEnvironment
// Add new mandatory modules from datamodel 2.x only
$sSourceDirFull = APPROOT.$sSourceDir;
if (!is_dir($sSourceDirFull))
{
if (!is_dir($sSourceDirFull)) {
throw new Exception("The source directory '$sSourceDirFull' does not exist (or could not be read)");
}
$aDirsToCompile = [$sSourceDirFull];
@@ -148,7 +135,7 @@ class RunTimeEnvironmentCoreUpdater extends RunTimeEnvironment
$aAvailableModules[$oModule->GetName()] = $oModule;
}
// TODO check the auto-selected modules here
foreach($this->oExtensionsMap->GetAllExtensions() as $oExtension) {
foreach ($this->oExtensionsMap->GetAllExtensions() as $oExtension) {
if ($oExtension->bMarkedAsChosen) {
foreach ($oExtension->aModules as $sModuleName) {
if (!isset($aRet[$sModuleName]) && isset($aAvailableModules[$sModuleName])) {