mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 23:32:17 +02:00
N°6648 - Use \utils::GetDataPath() instead of hard-coded paths (#555)
* N°6648 - Use \utils::GetDataPath() instead of hard-coded paths * Update setup/applicationinstaller.class.inc.php Co-authored-by: Thomas Casteleyn <thomas.casteleyn@super-visions.com> --------- Co-authored-by: Thomas Casteleyn <thomas.casteleyn@super-visions.com>
This commit is contained in:
@@ -120,7 +120,7 @@ try
|
||||
try
|
||||
{
|
||||
set_time_limit(0);
|
||||
$oBB = new BackupExec(APPROOT.'data/backups/manual/', 0 /*iRetentionCount*/);
|
||||
$oBB = new BackupExec(utils::GetDataPath().'backups/manual/', 0 /*iRetentionCount*/);
|
||||
$sRes = $oBB->Process(time() + 36000); // 10 hours to complete should be sufficient!
|
||||
}
|
||||
catch (Exception $e)
|
||||
@@ -185,7 +185,7 @@ try
|
||||
$oDBRS = new DBRestore($oItopConfig);
|
||||
$oDBRS->SetMySQLBinDir($sMySQLBinDir);
|
||||
|
||||
$sBackupDir = APPROOT.'data/backups/';
|
||||
$sBackupDir = utils::GetDataPath().'backups/';
|
||||
$sBackupFile = $sBackupDir.$sFile;
|
||||
$sRes = $oDBRS->RestoreFromCompressedBackup($sBackupFile, $sEnvironment);
|
||||
|
||||
@@ -210,7 +210,7 @@ try
|
||||
}
|
||||
$sFile = utils::ReadParam('file', '', false, 'raw_data');
|
||||
$oBackup = new DBBackupScheduled();
|
||||
$sBackupDir = APPROOT.'data/backups/';
|
||||
$sBackupDir = utils::GetDataPath().'backups/';
|
||||
$sBackupFilePath = utils::RealPath($sBackupDir.$sFile, $sBackupDir);
|
||||
if ($sBackupFilePath === false)
|
||||
{
|
||||
|
||||
@@ -154,7 +154,7 @@ class DBRestore extends DBBackup
|
||||
|
||||
// Load the database
|
||||
//
|
||||
$sDataDir = APPROOT.'data/tmp-backup-'.rand(10000, getrandmax());
|
||||
$sDataDir = utils::GetDataPath().'tmp-backup-'.rand(10000, getrandmax());
|
||||
|
||||
SetupUtils::builddir($sDataDir); // Here is the directory
|
||||
$oArchive->extractTo($sDataDir);
|
||||
@@ -164,7 +164,7 @@ class DBRestore extends DBBackup
|
||||
|
||||
// Update the code
|
||||
//
|
||||
$sDeltaFile = APPROOT.'data/'.$sEnvironment.'.delta.xml';
|
||||
$sDeltaFile = utils::GetDataPath().$sEnvironment.'.delta.xml';
|
||||
|
||||
if (is_file($sDataDir.'/delta.xml')) {
|
||||
// Extract and rename delta.xml => <env>.delta.xml;
|
||||
@@ -172,15 +172,15 @@ class DBRestore extends DBBackup
|
||||
} else {
|
||||
@unlink($sDeltaFile);
|
||||
}
|
||||
if (is_dir(APPROOT.'data/production-modules/')) {
|
||||
if (is_dir(utils::GetDataPath().'production-modules/')) {
|
||||
try {
|
||||
SetupUtils::rrmdir(APPROOT.'data/production-modules/');
|
||||
SetupUtils::rrmdir(utils::GetDataPath().'production-modules/');
|
||||
} catch (Exception $e) {
|
||||
throw new BackupException("Can't remove production-modules dir", 0, $e);
|
||||
}
|
||||
}
|
||||
if (is_dir($sDataDir.'/production-modules')) {
|
||||
rename($sDataDir.'/production-modules', APPROOT.'data/production-modules/');
|
||||
rename($sDataDir.'/production-modules', utils::GetDataPath().'production-modules/');
|
||||
}
|
||||
|
||||
$sConfigFile = APPROOT.'conf/'.$sEnvironment.'/config-itop.php';
|
||||
|
||||
@@ -109,7 +109,7 @@ class BackupExec extends AbstractWeeklyScheduledProcess
|
||||
{
|
||||
if (is_null($sBackupDir))
|
||||
{
|
||||
$this->sBackupDir = APPROOT.'data/backups/auto/';
|
||||
$this->sBackupDir = utils::GetDataPath().'backups/auto/';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -131,7 +131,7 @@ try {
|
||||
// Destination directory
|
||||
//
|
||||
// Make sure the target directory exists and is writeable
|
||||
$sBackupDir = realpath(APPROOT.'data/backups/');
|
||||
$sBackupDir = realpath(utils::GetDataPath().'backups/');
|
||||
SetupUtils::builddir($sBackupDir);
|
||||
if (!is_dir($sBackupDir)) {
|
||||
$oBlockForChecks->AddSubBlock(
|
||||
|
||||
@@ -486,7 +486,7 @@ final class CoreUpdater
|
||||
*/
|
||||
private static function GetItopArchiveName()
|
||||
{
|
||||
$sItopArchiveName = APPROOT.'data/backups/itop';
|
||||
$sItopArchiveName = utils::GetDataPath().'backups/itop';
|
||||
return $sItopArchiveName;
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ final class CoreUpdater
|
||||
*/
|
||||
private static function GetBackupName()
|
||||
{
|
||||
$sBackupName = APPROOT.'data/backups/manual/backup-core-update';
|
||||
$sBackupName = utils::GetDataPath().'backups/manual/backup-core-update';
|
||||
return $sBackupName;
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ try
|
||||
require_once (APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
|
||||
|
||||
$sDBBackupPath = APPROOT.'data/backups/manual';
|
||||
$sDBBackupPath = utils::GetDataPath().'backups/manual';
|
||||
$aChecks = SetupUtils::CheckBackupPrerequisites($sDBBackupPath);
|
||||
$bFailed = false;
|
||||
foreach ($aChecks as $oCheckResult)
|
||||
@@ -258,7 +258,7 @@ try
|
||||
case 'compile':
|
||||
SetupLog::Info('Deployment starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(APPROOT.'data/hub/compile_authent') || $sAuthent !== file_get_contents(APPROOT.'data/hub/compile_authent'))
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent'))
|
||||
{
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
@@ -301,11 +301,11 @@ try
|
||||
{
|
||||
SetupLog::Info('Move to production starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(APPROOT.'data/hub/compile_authent') || $sAuthent !== file_get_contents(APPROOT.'data/hub/compile_authent'))
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent'))
|
||||
{
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
unlink(APPROOT.'data/hub/compile_authent');
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
// Load the "production" config file to clone & update it
|
||||
$oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE);
|
||||
SetupUtils::EnterReadOnlyMode($oConfig);
|
||||
@@ -370,9 +370,9 @@ try
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if(file_exists(APPROOT.'data/hub/compile_authent'))
|
||||
if(file_exists(utils::GetDataPath().'hub/compile_authent'))
|
||||
{
|
||||
unlink(APPROOT.'data/hub/compile_authent');
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
}
|
||||
// Note: at this point, the dictionnary is not necessarily loaded
|
||||
SetupLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage());
|
||||
|
||||
@@ -78,7 +78,7 @@ class HubNewsroomProvider extends NewsroomProviderBase
|
||||
$sBaseUrl = $this->oConfig->GetModuleSetting('itop-hub-connector', 'url').MetaModel::GetModuleSetting('itop-hub-connector', $sRouteCode);
|
||||
|
||||
$sParameters = 'uuid[bdd]='.urlencode((string) trim(DBProperty::GetProperty('database_uuid', ''), '{}'));
|
||||
$sParameters .= '&uuid[file]='.urlencode((string) trim(@file_get_contents(APPROOT."data/instance.txt"), "{} \n"));
|
||||
$sParameters .= '&uuid[file]='.urlencode((string) trim(@file_get_contents(utils::GetDataPath()."instance.txt"), "{} \n"));
|
||||
$sParameters .= '&uuid[user]='.urlencode(UserRights::GetUserId());
|
||||
|
||||
return $sBaseUrl.'?'.$sParameters;
|
||||
|
||||
@@ -15,7 +15,7 @@ function DisplayStatus(WebPage $oPage)
|
||||
|
||||
$oPage->add('<div class="module-selection-body">');
|
||||
// Now scan the extensions and display a report of the extensions brought by the hub
|
||||
$sPath = APPROOT.'data/downloaded-extensions/';
|
||||
$sPath = utils::GetDataPath().'downloaded-extensions/';
|
||||
$aExtraDirs = array();
|
||||
if (is_dir($sPath)) {
|
||||
$aExtraDirs[] = $sPath; // Also read the extra downloaded-modules directory
|
||||
@@ -84,7 +84,7 @@ function DoLanding(WebPage $oPage)
|
||||
throw new Exception("Inconsistent version '$sVersion', expecting ".ITOP_VERSION."'");
|
||||
}
|
||||
|
||||
$sFileUUID = (string)trim(@file_get_contents(APPROOT."data/instance.txt"), "{} \n");
|
||||
$sFileUUID = (string)trim(@file_get_contents(utils::GetDataPath()."instance.txt"), "{} \n");
|
||||
if ($sInstanceUUID != $sFileUUID) {
|
||||
throw new Exception("Inconsistent file UUID '$sInstanceUUID', expecting ".$sFileUUID."'");
|
||||
}
|
||||
@@ -97,7 +97,7 @@ function DoLanding(WebPage $oPage)
|
||||
// Uncompression of extensions in data/downloaded-extensions
|
||||
// only newly downloaded extensions reside in this folder
|
||||
$i = 0;
|
||||
$sPath = APPROOT.'data/downloaded-extensions/';
|
||||
$sPath = utils::GetDataPath().'downloaded-extensions/';
|
||||
if (!is_dir($sPath)) {
|
||||
if (!mkdir($sPath)) {
|
||||
throw new Exception("ERROR: Unable to create the directory '$sPath'. Cannot download any extension. Check the access rights on '".dirname('data/downloaded-extensions/')."'");
|
||||
@@ -112,7 +112,7 @@ function DoLanding(WebPage $oPage)
|
||||
|
||||
$sZipArchiveFile = $sPath."/extension-{$i}.zip";
|
||||
file_put_contents($sZipArchiveFile, $sArchive);
|
||||
// Expand the content of extension-x.zip into APPROOT.'data/downloaded-extensions/'
|
||||
// Expand the content of extension-x.zip into utils::GetDataPath().'downloaded-extensions/'
|
||||
// where the installation will load the extension automatically
|
||||
$oZip = new ZipArchive();
|
||||
if (!$oZip->open($sZipArchiveFile)) {
|
||||
@@ -136,7 +136,7 @@ function DoLanding(WebPage $oPage)
|
||||
function DoInstall(WebPage $oPage)
|
||||
{
|
||||
$sUID = hash('sha256', rand());
|
||||
file_put_contents(APPROOT.'data/hub/compile_authent', $sUID);
|
||||
file_put_contents(utils::GetDataPath().'hub/compile_authent', $sUID);
|
||||
|
||||
$oPage->add_linked_stylesheet(utils::GetAbsoluteUrlModulesRoot().'itop-hub-connector/css/hub.css');
|
||||
$oPage->add('<table class="module-selection-banner"><tr>');
|
||||
@@ -151,7 +151,7 @@ function DoInstall(WebPage $oPage)
|
||||
|
||||
// Now scan the extensions and display a report of the extensions brought by the hub
|
||||
// Now scan the extensions and display a report of the extensions brought by the hub
|
||||
$sPath = APPROOT.'data/downloaded-extensions/';
|
||||
$sPath = utils::GetDataPath().'downloaded-extensions/';
|
||||
$aExtraDirs = array();
|
||||
if (is_dir($sPath)) {
|
||||
$aExtraDirs[] = $sPath; // Also read the extra downloaded-modules directory
|
||||
@@ -283,8 +283,8 @@ CSS
|
||||
break;
|
||||
|
||||
case 'install':
|
||||
if (!file_exists(APPROOT.'data/hub')) {
|
||||
mkdir(APPROOT.'data/hub');
|
||||
if (!file_exists(utils::GetDataPath().'hub')) {
|
||||
mkdir(utils::GetDataPath().'hub');
|
||||
}
|
||||
DoInstall($oPage);
|
||||
break;
|
||||
|
||||
@@ -231,7 +231,7 @@ function MakeDataToPost($sTargetRoute)
|
||||
'itop_hub_target_route' => $sTargetRoute,
|
||||
'itop_stack' => array(
|
||||
"uuidBdd" => (string)trim(DBProperty::GetProperty('database_uuid', ''), '{}'), // TODO check if empty and... regenerate a new UUID ??
|
||||
"uuidFile" => (string)trim(@file_get_contents(APPROOT."data/instance.txt"), "{} \n"), // TODO check if empty and... regenerate a new UUID ??
|
||||
"uuidFile" => (string)trim(@file_get_contents(utils::GetDataPath()."instance.txt"), "{} \n"), // TODO check if empty and... regenerate a new UUID ??
|
||||
'instance_friendly_name' => (string)$_SERVER['SERVER_NAME'],
|
||||
'instance_host' => (string)utils::GetAbsoluteUrlAppRoot(),
|
||||
'application_name' => (string)ITOP_APPLICATION,
|
||||
|
||||
Reference in New Issue
Block a user