diff --git a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php index fa87b18..1579aae 100644 --- a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php +++ b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php @@ -10,17 +10,17 @@ class IHMConfigClass private static $genericDataDir = "generic_data/"; private static $functionsDir = "Functions/"; - + private static $constantsFile = "constants.xml"; private static $functionsFile = "functions.xml"; - + private static $paramTemplateDir = "LocalData/ParamTemplate/"; private static $paramTemplateFile = "ParamTemplateList.xml"; - + private static $paramTemplateGenerateDir = "generateTemplateParams"; - + private static $dataDir = "data/"; private static $compilationDir = "compilation/"; @@ -28,33 +28,35 @@ class IHMConfigClass private static $requestDir = "RES/"; private static $sharedDir = "shared_data/"; - + private static $sharedTreeFile = "SharedObjectTree.xml"; private static $ttDir = "TT/"; private static $wsDir = "WS/"; - + private static $downloadTmp = "DOWNLOAD.TEMP/"; private static $jobsDir = "JOBS/"; - + private static $localBaseDir = "DATA/"; private static $aliasesFile = "Alias.xml"; + private static $infoFile = "info.json"; + private static $processMgrFile = "processManager.xml"; private static $jobsMgrFile = "jobs.xml"; - + private static $userParamMgrFile = "WsParams.xml"; private static $userName; - + private static $userHost; - + public static $remoteDataDir = "RemoteData/"; - + public static function setUserName($userName) { self::$userName = $userName; @@ -64,7 +66,7 @@ class IHMConfigClass { return self::$userName; } - + public static function setUserHost($userHost) { self::$userHost = $userHost; @@ -74,39 +76,44 @@ class IHMConfigClass { return self::$userHost; } - + public static function getDataDir() { return IHM_SRC_DIR."/".self::$dataDir.'/'; } - + public static function getRelativeResultPath() { $userPath = self::$dataDir."/".self::$userName.'/'.self::$requestDir; - + return $userPath; } - + public static function getUserPath() { $userPath = self::getDataDir().self::$userName.'/'; if (!is_dir($userPath)) mkdir($userPath); - + return $userPath; } + public static function getUserWSInfoFilePath() + { + return self::getUserPath().self::$infoFile; + } + public static function getProcessManagerFilePath() { return self::getDataDir().self::$processMgrFile; } - + public static function getGenericDataPath() { return IHM_SRC_DIR."/".self::$genericDataDir."/"; } - + public static function getConstantsFilePath() { return self::getGenericDataPath().self::$functionsDir.self::$constantsFile; @@ -116,37 +123,37 @@ class IHMConfigClass { return self::getGenericDataPath().self::$functionsDir.self::$functionsFile; } - + public static function getParamTemplateFilePath($fileName) { return self::getGenericDataPath().self::$paramTemplateDir.$fileName.".xml"; } - + public static function getTemplateParamGeneratePath() { return self::getUserPath().self::$paramTemplateGenerateDir; } - + public static function getDownloadTmpPath() { return self::getUserPath().self::$downloadTmp; } - + public static function getParamTemplateListFilePath() { return self::getGenericDataPath().self::$paramTemplateDir.self::$paramTemplateFile; } - + public static function getUserParamManagerFilePath() { return self::getUserWSPath().self::$userParamMgrFile; } - + public static function getUserDerivedParamFilePath($paramId) { return self::getUserWSPath().$paramId.".xml"; } - + public static function getUserUploadedParamFilePath($paramId) { return self::getUserWSPath().$paramId.".xml"; @@ -156,7 +163,7 @@ class IHMConfigClass { return PARAMS_LOCALDB_DIR; } - + public static function getLocalParamInfoPath() { return PARAMS_LOCALINFO_DIR; @@ -166,7 +173,7 @@ class IHMConfigClass { return IHM_SRC_DIR.'/'.self::$sharedDir; } - + public static function getSharedTreeFilePath() { return self::getSharedPath().self::$sharedTreeFile; @@ -215,44 +222,44 @@ class IHMConfigClass mkdir($compilationPath."lib/"); } } - + return $compilationPath; } public static function getLocalBasePath() { $localBasePath = self::getUserPath().self::$localBaseDir; - + if (!is_dir($localBasePath)) mkdir($localBasePath); - + return $localBasePath; } - + public static function getRemoteParamsFile() { $remoteBasePath = self::getUserPath().self::$wsDir; - + return $remoteBasePath.'RemoteParams.xml'; } - + public static function getRequestPath() { $requestPath = self::getUserPath().self::$requestDir; if (!is_dir($requestPath)) mkdir($requestPath); - + return $requestPath; } - + public static function getRemoteDataPath() { $remoteDataPath = self::getGenericDataPath().self::$remoteDataDir; - + return $remoteDataPath; } - + } ?> diff --git a/src/InputOutput/IHMImpl/IHMInputOutputClass.php b/src/InputOutput/IHMImpl/IHMInputOutputClass.php index 58e2da9..dbdfae6 100644 --- a/src/InputOutput/IHMImpl/IHMInputOutputClass.php +++ b/src/InputOutput/IHMImpl/IHMInputOutputClass.php @@ -8,6 +8,7 @@ class IHMInputOutputClass implements InputOutputInterface { protected $inputOutput = null; + protected $userWSMgr = null; /* * @brief Constructor @@ -16,6 +17,7 @@ class IHMInputOutputClass implements InputOutputInterface { IHMConfigClass::setUserName($userName); IHMConfigClass::setUserHost($userHost); + $this->userWSMgr = new IHMUserWSManagerClass(); } /* @@ -23,9 +25,8 @@ class IHMInputOutputClass implements InputOutputInterface */ public function getInputData($input,$function,$requestId = "") { - //check user workspace - if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath())) - throw new Exception('Cannot find user workspace.'); + //check user workspace + $this->userWSMgr->init(); switch ($function) { diff --git a/src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php b/src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php new file mode 100644 index 0000000..9480fe9 --- /dev/null +++ b/src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php @@ -0,0 +1,91 @@ +<?php + +/** + * @class IHMUserWSManagerClass + * @brief Manager for IHM user workspace + * @details + */ +class IHMUserWSManagerClass +{ + private static $version = 1; + + protected $wsInfo = null; + + public function init() + { + //check user workspace + if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath())) + throw new Exception('Cannot find user workspace.'); + + //Load info about WS + if (!$this->loadWSInfoFile()) + throw new Exception('Error to load workspace info file.'); + + //Update WS if need + if (!$this->update()) + throw new Exception('Error during user workspace conversion.'); + } + + public function update() + { + error_log(print_r($this->wsInfo,TRUE)); + error_log('BRE - update - '.$this->wsInfo['version']); + //while (IHMUserWSManagerClass::$version > $this->wsInfo['version']) { + $updateMethod = "updateFromVersion".$this->wsInfo['version']; + error_log('BRE - '.$updateMethod); + if (method_exists($this,$updateMethod)) { + if (!$this->{$updateMethod}()) { + return FALSE; + } + } + ++$this->wsInfo['version']; + error_log('BRE - saveWSInfoFile'); + $this->saveWSInfoFile(); + //} + return $this->saveWSInfoFile(); + } + + private function loadWSInfoFile() + { + if (file_exists(IHMConfigClass::getUserWSInfoFilePath())) { + $infoContent = file_get_contents(IHMConfigClass::getUserWSInfoFilePath()); + if (empty($infoContent)) { + return FALSE; + } + $this->wsInfo = json_decode($infoContent); + if (empty($this->wsInfo)) { + return FALSE; + } + } + + //Init info file + $this->wsInfo = array( + "version" => 0, + ); + + return $this->saveWSInfoFile(); + } + + private function saveWSInfoFile() + { + error_log('BRE - saveWSInfoFile'); + if (empty($this->wsInfo)) { + return FALSE; + } + + $json_data = json_encode($this->wsInfo); + + if ($json_data === FALSE) { + return FALSE; + } + + error_log(IHMConfigClass::getUserWSInfoFilePath()); + + return file_put_contents(IHMConfigClass::getUserWSInfoFilePath(),$json_data); + } + + private function updateFromVersion0() { + error_log('BRE - updateFromVersion0 call'); + return TRUE; + } +} -- libgit2 0.21.2