mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
Refactor Core Update (+3 squashed commit)
Squashed commit: [e1cbfe93f] Refactor Core Update [41ec2adf7] Refactor Core Update [ca6cefca3] Refactor Core Update
This commit is contained in:
@@ -8,8 +8,20 @@ namespace Combodo\iTop\CoreUpdate;
|
||||
|
||||
use Combodo\iTop\CoreUpdate\Controller\AjaxController;
|
||||
use ContextTag;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
if (!defined('MODULESROOT'))
|
||||
{
|
||||
define('MODULESROOT', APPROOT.'env-production/');
|
||||
}
|
||||
|
||||
require_once(MODULESROOT.'itop-core-update/src/Service/RunTimeEnvironmentCoreUpdater.php');
|
||||
require_once(MODULESROOT.'itop-core-update/src/Service/CoreUpdater.php');
|
||||
require_once(MODULESROOT.'itop-core-update/src/Controller/AjaxController.php');
|
||||
|
||||
MetaModel::LoadConfig(utils::GetConfig());
|
||||
|
||||
require_once(APPROOT.'application/startup.inc.php');
|
||||
new ContextTag('Setup');
|
||||
|
||||
$oUpdateController = new AjaxController();
|
||||
|
||||
@@ -20,7 +20,6 @@ SetupWebPage::AddModule(
|
||||
// Setup
|
||||
//
|
||||
'dependencies' => array(
|
||||
'itop-twig-base/1.0.0',
|
||||
'itop-files-information/1.0.0',
|
||||
'combodo-db-tools/1.0.8',
|
||||
),
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
namespace Combodo\iTop\CoreUpdate\Controller;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\TwigBase\Controller\Controller;
|
||||
use Combodo\iTop\CoreUpdate\Service\CoreUpdater;
|
||||
use Combodo\iTop\DBTools\Service\DBToolsUtils;
|
||||
use Combodo\iTop\FilesInformation\Service\FileNotExistException;
|
||||
use Combodo\iTop\FilesInformation\Service\FilesInformation;
|
||||
use Combodo\iTop\TwigBase\Controller\Controller;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use IssueLog;
|
||||
@@ -22,61 +22,63 @@ use utils;
|
||||
|
||||
class AjaxController extends Controller
|
||||
{
|
||||
const LOCAL_DIR = __DIR__;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->InitFromModule();
|
||||
}
|
||||
|
||||
public function OperationCanUpdateCore()
|
||||
{
|
||||
$aParams = array();
|
||||
public function OperationCanUpdateCore()
|
||||
{
|
||||
$aParams = array();
|
||||
|
||||
try
|
||||
{
|
||||
$bCanUpdateCore = FilesInformation::CanUpdateCore($sMessage);
|
||||
$aParams['bStatus'] = $bCanUpdateCore;
|
||||
if ($bCanUpdateCore)
|
||||
{
|
||||
$aParams['sMessage'] = Dict::S('iTopUpdate:UI:CanCoreUpdate:Yes');
|
||||
}
|
||||
else
|
||||
{
|
||||
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:No', $sMessage);
|
||||
}
|
||||
}
|
||||
catch (FileNotExistException $e)
|
||||
{
|
||||
$aParams['bStatus'] = false;
|
||||
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:ErrorFileNotExist', $e->getMessage());
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$aParams['bStatus'] = false;
|
||||
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:Error', $e->getMessage());
|
||||
}
|
||||
try
|
||||
{
|
||||
$bCanUpdateCore = FilesInformation::CanUpdateCore($sMessage);
|
||||
$aParams['bStatus'] = $bCanUpdateCore;
|
||||
if ($bCanUpdateCore)
|
||||
{
|
||||
$aParams['sMessage'] = Dict::S('iTopUpdate:UI:CanCoreUpdate:Yes');
|
||||
}
|
||||
else
|
||||
{
|
||||
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:No', $sMessage);
|
||||
}
|
||||
} catch (FileNotExistException $e)
|
||||
{
|
||||
$aParams['bStatus'] = false;
|
||||
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:ErrorFileNotExist', $e->getMessage());
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$aParams['bStatus'] = false;
|
||||
$aParams['sMessage'] = Dict::Format('iTopUpdate:UI:CanCoreUpdate:Error', $e->getMessage());
|
||||
}
|
||||
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
|
||||
public function OperationGetItopDiskSpace()
|
||||
{
|
||||
$aParams = array();
|
||||
$aParams['iItopDiskSpace'] = FilesInformation::GetItopDiskSpace();
|
||||
$aParams['sItopDiskSpace'] = utils::BytesToFriendlyFormat($aParams['iItopDiskSpace']);
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
public function OperationGetItopDiskSpace()
|
||||
{
|
||||
$aParams = array();
|
||||
$aParams['iItopDiskSpace'] = FilesInformation::GetItopDiskSpace();
|
||||
$aParams['sItopDiskSpace'] = utils::BytesToFriendlyFormat($aParams['iItopDiskSpace']);
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
|
||||
public function OperationGetDBDiskSpace()
|
||||
{
|
||||
$aParams = array();
|
||||
$aParams['iDBDiskSpace'] = DBToolsUtils::GetDatabaseSize();
|
||||
$aParams['sDBDiskSpace'] = utils::BytesToFriendlyFormat($aParams['iDBDiskSpace']);
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
public function OperationGetDBDiskSpace()
|
||||
{
|
||||
$aParams = array();
|
||||
$aParams['iDBDiskSpace'] = DBToolsUtils::GetDatabaseSize();
|
||||
$aParams['sDBDiskSpace'] = utils::BytesToFriendlyFormat($aParams['iDBDiskSpace']);
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
|
||||
public function OperationGetCurrentVersion()
|
||||
{
|
||||
$aParams = array();
|
||||
$aParams['sVersion'] = Dict::Format('UI:iTopVersion:Long', ITOP_APPLICATION, ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE);
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
public function OperationGetCurrentVersion()
|
||||
{
|
||||
$aParams = array();
|
||||
$aParams['sVersion'] = Dict::Format('UI:iTopVersion:Long', ITOP_APPLICATION, ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE);
|
||||
$this->DisplayJSONPage($aParams);
|
||||
}
|
||||
|
||||
public function OperationEnterMaintenance()
|
||||
{
|
||||
@@ -85,8 +87,7 @@ class AjaxController extends Controller
|
||||
{
|
||||
SetupUtils::EnterReadOnlyMode(MetaModel::GetConfig());
|
||||
$iResponseCode = 200;
|
||||
}
|
||||
catch (Exception $e)
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("EnterMaintenance: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
@@ -102,8 +103,7 @@ class AjaxController extends Controller
|
||||
{
|
||||
SetupUtils::ExitReadOnlyMode();
|
||||
$iResponseCode = 200;
|
||||
}
|
||||
catch (Exception $e)
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("ExitMaintenance: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
@@ -112,22 +112,21 @@ class AjaxController extends Controller
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
|
||||
public function OperationBackup()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::Backup();
|
||||
$iResponseCode = 200;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("Backup: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
public function OperationBackup()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::Backup();
|
||||
$iResponseCode = 200;
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("Backup: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
|
||||
public function OperationFilesArchive()
|
||||
{
|
||||
@@ -136,8 +135,7 @@ class AjaxController extends Controller
|
||||
{
|
||||
CoreUpdater::CreateItopArchive();
|
||||
$iResponseCode = 200;
|
||||
}
|
||||
catch (Exception $e)
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("FilesArchive: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
@@ -146,39 +144,71 @@ class AjaxController extends Controller
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
|
||||
public function OperationCopyFiles()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::CopyCoreFiles();
|
||||
$iResponseCode = 200;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("CopyFiles: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
public function OperationCopyFiles()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::CopyCoreFiles();
|
||||
$iResponseCode = 200;
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("CopyFiles: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
|
||||
public function OperationCompile()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::Compile();
|
||||
$iResponseCode = 200;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("Compile: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
public function OperationCheckCompile()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::CheckCompile();
|
||||
$iResponseCode = 200;
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("Compile: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
|
||||
public function OperationCompile()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::Compile();
|
||||
$iResponseCode = 200;
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("Compile: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
|
||||
public function OperationUpdateDatabase()
|
||||
{
|
||||
$aParams = array();
|
||||
try
|
||||
{
|
||||
CoreUpdater::UpdateDatabase();
|
||||
$iResponseCode = 200;
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::Error("Compile: ".$e->getMessage());
|
||||
$aParams['sError'] = $e->getMessage();
|
||||
$iResponseCode = 500;
|
||||
}
|
||||
|
||||
$this->DisplayJSONPage($aParams, $iResponseCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
namespace Combodo\iTop\CoreUpdate\Controller;
|
||||
|
||||
use Combodo\iTop\Application\TwigBase\Controller\Controller;
|
||||
use Combodo\iTop\CoreUpdate\Service\CoreUpdater;
|
||||
use Combodo\iTop\DBTools\Service\DBToolsUtils;
|
||||
use Combodo\iTop\TwigBase\Controller\Controller;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use SetupUtils;
|
||||
@@ -16,7 +16,11 @@ use utils;
|
||||
|
||||
class UpdateController extends Controller
|
||||
{
|
||||
const LOCAL_DIR = __DIR__;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->InitFromModule();
|
||||
}
|
||||
|
||||
public function OperationSelectUpdateFile()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* iTop
|
||||
*
|
||||
* @copyright Copyright (C) 2010,2019 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*
|
||||
@@ -26,14 +27,14 @@ require_once APPROOT.'setup/runtimeenv.class.inc.php';
|
||||
|
||||
final class CoreUpdater
|
||||
{
|
||||
const DOWNLOAD_DIR = APPROOT.'data/downloaded-core/';
|
||||
const DOWNLOAD_DIR = APPROOT.'data/downloaded-core/';
|
||||
const UPDATE_DIR = APPROOT.'data/core-update/';
|
||||
|
||||
/**
|
||||
* @param bool $bDoBackup
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
/**
|
||||
* @param bool $bDoBackup
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function CopyCoreFiles()
|
||||
{
|
||||
set_time_limit(600);
|
||||
@@ -69,19 +70,39 @@ final class CoreUpdater
|
||||
FilesIntegrity::CheckInstallationIntegrity(APPROOT);
|
||||
IssueLog::Info('itop-core-update: Files integrity OK');
|
||||
|
||||
}
|
||||
catch (Exception $e)
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::error($e->getMessage());
|
||||
IssueLog::Info('itop-core-update: ended');
|
||||
throw $e;
|
||||
}
|
||||
finally
|
||||
} finally
|
||||
{
|
||||
self::RRmdir(self::UPDATE_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function CheckCompile()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Compile code in env-production-build
|
||||
IssueLog::Info('itop-core-update: Check compilation');
|
||||
|
||||
$sTargetEnv = 'production';
|
||||
$oRuntimeEnv = new RunTimeEnvironmentCoreUpdater($sTargetEnv, false);
|
||||
$oRuntimeEnv->CheckDirectories($sTargetEnv);
|
||||
$oRuntimeEnv->CompileFrom('production');
|
||||
SetupUtils::tidydir(APPROOT."env-{$sTargetEnv}-build");
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::error($e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
@@ -91,18 +112,44 @@ final class CoreUpdater
|
||||
{
|
||||
// Compile code
|
||||
IssueLog::Info('itop-core-update: Start compilation');
|
||||
IssueLog::Info('itop-core-update: Version Dev');
|
||||
|
||||
$sTargetEnv = 'production';
|
||||
$oRuntimeEnv = new RunTimeEnvironmentCoreUpdater($sTargetEnv);
|
||||
$oRuntimeEnv->CheckDirectories($sTargetEnv);
|
||||
$oRuntimeEnv->CompileFrom('production');
|
||||
|
||||
IssueLog::Info('itop-core-update: Compilation done');
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::error($e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function UpdateDatabase()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Compile code
|
||||
IssueLog::Info('itop-core-update: Update database');
|
||||
|
||||
$sTargetEnv = 'production';
|
||||
$oRuntimeEnv = new RunTimeEnvironmentCoreUpdater($sTargetEnv);
|
||||
$oRuntimeEnv->CheckDirectories($sTargetEnv);
|
||||
$oConfig = $oRuntimeEnv->MakeConfigFile($sTargetEnv.' (built on '.date('Y-m-d').')');
|
||||
$oConfig->Set('access_mode', ACCESS_FULL);
|
||||
$oRuntimeEnv->WriteConfigFileSafe($oConfig);
|
||||
$oRuntimeEnv->InitDataModel($oConfig, true);
|
||||
|
||||
$aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $oRuntimeEnv->GetBuildDir());
|
||||
$sModulesDirToKeep = $oRuntimeEnv->GetBuildDir();
|
||||
$aDirsToScanForModules = array(
|
||||
$sModulesDirToKeep,
|
||||
APPROOT.'extensions'
|
||||
);
|
||||
$aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $aDirsToScanForModules);
|
||||
$aSelectedModules = array();
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule)
|
||||
{
|
||||
@@ -142,9 +189,10 @@ final class CoreUpdater
|
||||
$oRuntimeEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModules,
|
||||
$aSelectedExtensionCodes, 'Done by the iTop Core Updater');
|
||||
|
||||
IssueLog::Info('itop-core-update: Compilation done');
|
||||
}
|
||||
catch (Exception $e)
|
||||
$oRuntimeEnv->Commit();
|
||||
|
||||
IssueLog::Info('itop-core-update: Update database done');
|
||||
} catch (Exception $e)
|
||||
{
|
||||
IssueLog::error($e->getMessage());
|
||||
throw $e;
|
||||
@@ -186,87 +234,87 @@ final class CoreUpdater
|
||||
*/
|
||||
public static function Backup()
|
||||
{
|
||||
$sBackupName = self::GetBackupName();
|
||||
$sBackupFile = self::GetBackupFile();
|
||||
if (file_exists($sBackupFile))
|
||||
{
|
||||
@unlink($sBackupFile);
|
||||
}
|
||||
$sBackupName = self::GetBackupName();
|
||||
$sBackupFile = self::GetBackupFile();
|
||||
if (file_exists($sBackupFile))
|
||||
{
|
||||
@unlink($sBackupFile);
|
||||
}
|
||||
|
||||
self::DoBackup($sBackupName);
|
||||
self::DoBackup($sBackupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function CreateItopArchive()
|
||||
{
|
||||
set_time_limit(0);
|
||||
$sItopArchiveFile = self::GetItopArchiveFile();
|
||||
if (file_exists($sItopArchiveFile))
|
||||
{
|
||||
@unlink($sItopArchiveFile);
|
||||
}
|
||||
{
|
||||
set_time_limit(0);
|
||||
$sItopArchiveFile = self::GetItopArchiveFile();
|
||||
if (file_exists($sItopArchiveFile))
|
||||
{
|
||||
@unlink($sItopArchiveFile);
|
||||
}
|
||||
|
||||
$sTempFile = sys_get_temp_dir().'/'.basename($sItopArchiveFile);
|
||||
if (file_exists($sTempFile))
|
||||
{
|
||||
@unlink($sTempFile);
|
||||
}
|
||||
$sTempFile = sys_get_temp_dir().'/'.basename($sItopArchiveFile);
|
||||
if (file_exists($sTempFile))
|
||||
{
|
||||
@unlink($sTempFile);
|
||||
}
|
||||
|
||||
$aPathInfo = pathInfo(realpath(APPROOT));
|
||||
$sParentPath = $aPathInfo['dirname'];
|
||||
$sDirName = $aPathInfo['basename'];
|
||||
$aPathInfo = pathInfo(realpath(APPROOT));
|
||||
$sParentPath = $aPathInfo['dirname'];
|
||||
$sDirName = $aPathInfo['basename'];
|
||||
|
||||
$oZipArchive = new ZipArchive();
|
||||
$oZipArchive->open($sTempFile, ZIPARCHIVE::CREATE);
|
||||
$oZipArchive->addEmptyDir($sDirName);
|
||||
self::ZipFolder(realpath(APPROOT), $oZipArchive, strlen("$sParentPath/"));
|
||||
$oZipArchive->close();
|
||||
|
||||
if (!file_exists($sTempFile))
|
||||
{
|
||||
IssueLog::Error("Failed to create itop archive $sTempFile");
|
||||
}
|
||||
$oZipArchive = new ZipArchive();
|
||||
$oZipArchive->open($sTempFile, ZIPARCHIVE::CREATE);
|
||||
$oZipArchive->addEmptyDir($sDirName);
|
||||
self::ZipFolder(realpath(APPROOT), $oZipArchive, strlen("$sParentPath/"));
|
||||
$oZipArchive->close();
|
||||
|
||||
if (@rename($sTempFile, $sItopArchiveFile))
|
||||
{
|
||||
IssueLog::Info("Archive $sItopArchiveFile Created");
|
||||
}
|
||||
else
|
||||
{
|
||||
IssueLog::Error("Failed to create archive $sItopArchiveFile");
|
||||
}
|
||||
}
|
||||
if (!file_exists($sTempFile))
|
||||
{
|
||||
IssueLog::Error("Failed to create itop archive $sTempFile");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sTargetFile
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function DoBackup($sTargetFile)
|
||||
{
|
||||
// Make sure the target directory exists
|
||||
$sBackupDir = dirname($sTargetFile);
|
||||
SetupUtils::builddir($sBackupDir);
|
||||
if (@rename($sTempFile, $sItopArchiveFile))
|
||||
{
|
||||
IssueLog::Info("Archive $sItopArchiveFile Created");
|
||||
}
|
||||
else
|
||||
{
|
||||
IssueLog::Error("Failed to create archive $sItopArchiveFile");
|
||||
}
|
||||
}
|
||||
|
||||
$oBackup = new DBBackup();
|
||||
$oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
|
||||
/**
|
||||
*
|
||||
* @param string $sTargetFile
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function DoBackup($sTargetFile)
|
||||
{
|
||||
// Make sure the target directory exists
|
||||
$sBackupDir = dirname($sTargetFile);
|
||||
SetupUtils::builddir($sBackupDir);
|
||||
|
||||
$oMutex = new iTopMutex('backup.'.utils::GetCurrentEnvironment());
|
||||
$oMutex->Lock();
|
||||
try
|
||||
{
|
||||
$oBackup->CreateCompressedBackup($sTargetFile);
|
||||
IssueLog::Info('itop-core-update: Backup done: '.$sTargetFile);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$oMutex->Unlock();
|
||||
throw $e;
|
||||
}
|
||||
$oMutex->Unlock();
|
||||
}
|
||||
$oBackup = new DBBackup();
|
||||
$oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
|
||||
|
||||
$oMutex = new iTopMutex('backup.'.utils::GetCurrentEnvironment());
|
||||
$oMutex->Lock();
|
||||
try
|
||||
{
|
||||
$oBackup->CreateCompressedBackup($sTargetFile);
|
||||
IssueLog::Info('itop-core-update: Backup done: '.$sTargetFile);
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$oMutex->Unlock();
|
||||
throw $e;
|
||||
}
|
||||
$oMutex->Unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sSource
|
||||
@@ -283,9 +331,9 @@ final class CoreUpdater
|
||||
@mkdir($sDest, 0755);
|
||||
}
|
||||
$aFiles = scandir($sSource);
|
||||
if(sizeof($aFiles) > 0 )
|
||||
if (sizeof($aFiles) > 0)
|
||||
{
|
||||
foreach($aFiles as $sFile)
|
||||
foreach ($aFiles as $sFile)
|
||||
{
|
||||
if ($sFile == '.' || $sFile == '..' || $sFile == '.svn' || $sFile == '.git')
|
||||
{
|
||||
@@ -315,7 +363,8 @@ final class CoreUpdater
|
||||
}
|
||||
}
|
||||
|
||||
public static function RRmdir($sDir) {
|
||||
public static function RRmdir($sDir)
|
||||
{
|
||||
if (is_dir($sDir))
|
||||
{
|
||||
$oDir = @opendir($sDir);
|
||||
@@ -368,9 +417,11 @@ final class CoreUpdater
|
||||
* @param ZipArchive $oZipArchive
|
||||
* @param int $iStrippedLength Number of text to be removed from the file path.
|
||||
*/
|
||||
private static function ZipFolder($sFolder, &$oZipArchive, $iStrippedLength) {
|
||||
private static function ZipFolder($sFolder, &$oZipArchive, $iStrippedLength)
|
||||
{
|
||||
$oFolder = opendir($sFolder);
|
||||
while (false !== ($sFile = readdir($oFolder))) {
|
||||
while (false !== ($sFile = readdir($oFolder)))
|
||||
{
|
||||
if (($sFile == '.') || ($sFile == '..'))
|
||||
{
|
||||
continue;
|
||||
@@ -385,9 +436,12 @@ final class CoreUpdater
|
||||
|
||||
// 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);
|
||||
@@ -414,109 +468,106 @@ final class CoreUpdater
|
||||
return $sItopArchiveFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function GetBackupName()
|
||||
{
|
||||
$sBackupName = APPROOT.'data/backups/manual/backup-core-update';
|
||||
return $sBackupName;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function GetBackupName()
|
||||
{
|
||||
$sBackupName = APPROOT.'data/backups/manual/backup-core-update';
|
||||
return $sBackupName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function GetBackupFile()
|
||||
{
|
||||
$sBackupFile = self::GetBackupName().'.tar.gz';
|
||||
return $sBackupFile;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function GetBackupFile()
|
||||
{
|
||||
$sBackupFile = self::GetBackupName().'.tar.gz';
|
||||
return $sBackupFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sArchiveFile
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function ExtractDownloadedFile($sArchiveFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Extract archive file
|
||||
self::ExtractUpdateFile($sArchiveFile);
|
||||
/**
|
||||
* @param $sArchiveFile
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function ExtractDownloadedFile($sArchiveFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Extract archive file
|
||||
self::ExtractUpdateFile($sArchiveFile);
|
||||
|
||||
IssueLog::Info('itop-core-update: Archive extracted, check files integrity');
|
||||
IssueLog::Info('itop-core-update: Archive extracted, check files integrity');
|
||||
|
||||
// Check files integrity
|
||||
FilesIntegrity::CheckInstallationIntegrity(self::UPDATE_DIR.'web/');
|
||||
// Check files integrity
|
||||
FilesIntegrity::CheckInstallationIntegrity(self::UPDATE_DIR.'web/');
|
||||
|
||||
IssueLog::Info('itop-core-update: Files integrity OK');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
self::RRmdir(self::UPDATE_DIR);
|
||||
throw $e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
self::RRmdir(self::DOWNLOAD_DIR);
|
||||
}
|
||||
}
|
||||
IssueLog::Info('itop-core-update: Files integrity OK');
|
||||
} catch (Exception $e)
|
||||
{
|
||||
self::RRmdir(self::UPDATE_DIR);
|
||||
throw $e;
|
||||
} finally
|
||||
{
|
||||
self::RRmdir(self::DOWNLOAD_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function GetVersionToInstall()
|
||||
{
|
||||
try
|
||||
{
|
||||
$sConfigFile = self::UPDATE_DIR.'web/core/config.class.inc.php';
|
||||
if (!is_file($sConfigFile))
|
||||
{
|
||||
throw new Exception(Dict::S(Dict::S('iTopUpdate:Error:BadFileContent')));
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function GetVersionToInstall()
|
||||
{
|
||||
try
|
||||
{
|
||||
$sConfigFile = self::UPDATE_DIR.'web/core/config.class.inc.php';
|
||||
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))
|
||||
{
|
||||
throw new Exception(Dict::S(Dict::S('iTopUpdate:Error:BadFileContent')));
|
||||
}
|
||||
$aValues = array();
|
||||
foreach ($aMatches['name'] as $index => $sName)
|
||||
{
|
||||
$aValues[$sName] = $aMatches['value'][$index];
|
||||
}
|
||||
$sContents = file_get_contents($sConfigFile);
|
||||
preg_match_all("@define\('(?<name>ITOP_[^']*)', '(?<value>[^']*)'\);@", $sContents, $aMatches);
|
||||
if (empty($aMatches))
|
||||
{
|
||||
throw new Exception(Dict::S(Dict::S('iTopUpdate:Error:BadFileContent')));
|
||||
}
|
||||
$aValues = array();
|
||||
foreach ($aMatches['name'] as $index => $sName)
|
||||
{
|
||||
$aValues[$sName] = $aMatches['value'][$index];
|
||||
}
|
||||
|
||||
if ($aValues['ITOP_APPLICATION'] != ITOP_APPLICATION)
|
||||
{
|
||||
throw new Exception(Dict::S('iTopUpdate:Error:BadItopProduct'));
|
||||
}
|
||||
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'))
|
||||
{
|
||||
// Remove previous specific updater
|
||||
@unlink(APPROOT.'setup/appupgradecheck.php');
|
||||
}
|
||||
if (is_file(self::UPDATE_DIR.'web/setup/appupgradecheck.php'))
|
||||
{
|
||||
IssueLog::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'))
|
||||
{
|
||||
AppUpgradeCheckInstall();
|
||||
}
|
||||
// Extract updater file from the new version if available
|
||||
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'))
|
||||
{
|
||||
IssueLog::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'))
|
||||
{
|
||||
AppUpgradeCheckInstall();
|
||||
}
|
||||
|
||||
return Dict::Format('UI:iTopVersion:Long', $aValues['ITOP_APPLICATION'], $aValues['ITOP_VERSION'], $aValues['ITOP_REVISION'], $aValues['ITOP_BUILD_DATE']);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
self::RRmdir(self::UPDATE_DIR);
|
||||
self::RRmdir(self::DOWNLOAD_DIR);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
return Dict::Format('UI:iTopVersion:Long', $aValues['ITOP_APPLICATION'], $aValues['ITOP_VERSION'], $aValues['ITOP_REVISION'], $aValues['ITOP_BUILD_DATE']);
|
||||
} catch (Exception $e)
|
||||
{
|
||||
self::RRmdir(self::UPDATE_DIR);
|
||||
self::RRmdir(self::DOWNLOAD_DIR);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,36 @@ require_once(APPROOT."setup/runtimeenv.class.inc.php");
|
||||
use Config;
|
||||
use Exception;
|
||||
use RunTimeEnvironment;
|
||||
use SetupUtils;
|
||||
|
||||
class RunTimeEnvironmentCoreUpdater extends RunTimeEnvironment
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $sEnvironment
|
||||
* @param bool $bAutoCommit
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($sEnvironment = 'production', $bAutoCommit = true)
|
||||
{
|
||||
parent::__construct($sEnvironment, $bAutoCommit);
|
||||
|
||||
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'))
|
||||
{
|
||||
SetupUtils::rrmdir(APPROOT.'/data/'.$this->sTargetEnv.'-modules');
|
||||
}
|
||||
SetupUtils::copydir(APPROOT.'/data/'.$sEnvironment.'-modules', APPROOT.'/data/'.$this->sTargetEnv.'-modules');
|
||||
}
|
||||
}
|
||||
|
||||
public function CheckDirectories($sTargetEnv)
|
||||
{
|
||||
$sTargetDir = APPROOT.'env-'.$sTargetEnv;
|
||||
|
||||
@@ -57,7 +57,7 @@ function GetAjaxRequest(sOperation)
|
||||
return oAjaxRequest;
|
||||
}
|
||||
|
||||
{% set aSteps = ['EnterMaintenance', 'Backup', 'FilesArchive', 'CopyFiles', 'Compile', 'ExitMaintenance', 'UpdateDone'] %}
|
||||
{% set aSteps = ['EnterMaintenance', 'Backup', 'FilesArchive', 'CopyFiles', 'CheckCompile', 'Compile', 'UpdateDatabase', 'ExitMaintenance', 'UpdateDone'] %}
|
||||
|
||||
aStepsName = [];
|
||||
|
||||
@@ -75,7 +75,7 @@ var sFilesArchiveStep;
|
||||
sFilesArchiveStep = "FilesArchive";
|
||||
{% endif %}
|
||||
|
||||
var aStepsAjaxOperation = ["EnterMaintenance", sBackupStep, sFilesArchiveStep, "CopyFiles", "Compile", "ExitMaintenance", null];
|
||||
var aStepsAjaxOperation = ["EnterMaintenance", sBackupStep, sFilesArchiveStep, "CopyFiles", "CheckCompile", "Compile", "UpdateDatabase", "ExitMaintenance", null];
|
||||
|
||||
var iNextStep = 0;
|
||||
function ExecNextStep() {
|
||||
|
||||
Reference in New Issue
Block a user