mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
86 lines
2.6 KiB
PHP
86 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Combodo\iTop\HubConnector\setup;
|
|
|
|
use Config;
|
|
use Exception;
|
|
use RunTimeEnvironment;
|
|
use SetupUtils;
|
|
|
|
class HubRunTimeEnvironment extends RunTimeEnvironment
|
|
{
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param string $sEnvironment
|
|
* @param string $bAutoCommit
|
|
*/
|
|
public function __construct($sEnvironment = 'production', $bAutoCommit = true)
|
|
{
|
|
parent::__construct($sEnvironment, $bAutoCommit);
|
|
|
|
if ($sEnvironment != $this->sBuildEnv) {
|
|
if (is_dir(APPROOT.'/env-'.$this->sBuildEnv)) {
|
|
SetupUtils::rrmdir(APPROOT.'/env-'.$this->sBuildEnv);
|
|
}
|
|
if (is_dir(APPROOT.'/data/'.$this->sBuildEnv.'-modules')) {
|
|
SetupUtils::rrmdir(APPROOT.'/data/'.$this->sBuildEnv.'-modules');
|
|
}
|
|
SetupUtils::copydir(APPROOT.'/data/'.$sEnvironment.'-modules', APPROOT.'/data/'.$this->sBuildEnv.'-modules');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the includes for the build environment
|
|
*
|
|
* @param Config $oConfig
|
|
*/
|
|
public function UpdateIncludes(Config $oConfig)
|
|
{
|
|
$oConfig->UpdateIncludes('env-'.$this->sBuildEnv); // BuildEnv != FinalEnv
|
|
}
|
|
|
|
/**
|
|
* Move an extension (path to folder of this extension) to the build environment
|
|
*
|
|
* @param string $sExtensionDirectory The folder of the extension
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function MoveExtension($sExtensionDirectory)
|
|
{
|
|
if (!is_dir(APPROOT.'/data/'.$this->sBuildEnv.'-modules')) {
|
|
if (!mkdir(APPROOT.'/data/'.$this->sBuildEnv.'-modules')) {
|
|
throw new Exception("ERROR: failed to create directory:'".(APPROOT.'/data/'.$this->sBuildEnv.'-modules')."'");
|
|
}
|
|
}
|
|
$sDestinationPath = APPROOT.'/data/'.$this->sBuildEnv.'-modules/';
|
|
|
|
// Make sure that the destination directory of the extension does not already exist
|
|
if (is_dir($sDestinationPath.basename($sExtensionDirectory))) {
|
|
// Cleanup before moving...
|
|
SetupUtils::rrmdir($sDestinationPath.basename($sExtensionDirectory));
|
|
}
|
|
if (!rename($sExtensionDirectory, $sDestinationPath.basename($sExtensionDirectory))) {
|
|
throw new Exception("ERROR: failed move directory:'$sExtensionDirectory' to '".$sDestinationPath.basename($sExtensionDirectory)."'");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Move the selected extensions located in the given directory in data/<build-env>-modules
|
|
*
|
|
* @param string $sDownloadedExtensionsDir The directory to scan
|
|
* @param string[] $aSelectedExtensionDirs The list of folders to move
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function MoveSelectedExtensions($sDownloadedExtensionsDir, $aSelectedExtensionDirs)
|
|
{
|
|
foreach (glob($sDownloadedExtensionsDir.'*', GLOB_ONLYDIR) as $sExtensionDir) {
|
|
if (in_array(basename($sExtensionDir), $aSelectedExtensionDirs)) {
|
|
$this->MoveExtension($sExtensionDir);
|
|
}
|
|
}
|
|
}
|
|
}
|