diff --git a/src/FunctionTypeEnumClass.php b/src/FunctionTypeEnumClass.php index 393881d..31e7457 100644 --- a/src/FunctionTypeEnumClass.php +++ b/src/FunctionTypeEnumClass.php @@ -19,6 +19,7 @@ abstract class FunctionTypeEnumClass const TTUNION = "tt_union"; const TTCONVERT = "tt_convert"; const PARAMINFO = "param_info"; + const USERWSINIT = "user_init"; } ?> diff --git a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php index fa87b18..f0cf4b0 100644 --- a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php +++ b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php @@ -25,6 +25,8 @@ class IHMConfigClass private static $compilationDir = "compilation/"; + private static $storedRequestDir = "REQ/"; + private static $requestDir = "RES/"; private static $sharedDir = "shared_data/"; @@ -43,12 +45,16 @@ class IHMConfigClass private static $aliasesFile = "Alias.xml"; + private static $wsInfoFile = "WS_info.json"; + private static $processMgrFile = "processManager.xml"; private static $jobsMgrFile = "jobs.xml"; private static $userParamMgrFile = "WsParams.xml"; + private static $userRequestMgrFile = "Request.xml"; + private static $userName; private static $userHost; @@ -97,6 +103,11 @@ class IHMConfigClass return $userPath; } + public static function getUserWSInfoFilePath() + { + return self::getUserPath().self::$wsInfoFile; + } + public static function getProcessManagerFilePath() { return self::getDataDir().self::$processMgrFile; @@ -141,6 +152,11 @@ class IHMConfigClass { return self::getUserWSPath().self::$userParamMgrFile; } + + public static function getUserRequestManagerFilePath() + { + return self::getUserWSPath().self::$userRequestMgrFile; + } public static function getUserDerivedParamFilePath($paramId) { @@ -245,6 +261,16 @@ class IHMConfigClass return $requestPath; } + + public static function getStoredRequestPath() + { + $storedRequestPath = self::getUserPath().self::$storedRequestDir; + + if (!is_dir($storedRequestPath)) + mkdir($storedRequestPath); + + return $storedRequestPath; + } public static function getRemoteDataPath() { diff --git a/src/InputOutput/IHMImpl/IHMInputOutputClass.php b/src/InputOutput/IHMImpl/IHMInputOutputClass.php index 58e2da9..cc7f37e 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,10 +25,6 @@ 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.'); - switch ($function) { case FunctionTypeEnumClass::PARAMS : @@ -102,6 +100,8 @@ class IHMInputOutputClass implements InputOutputInterface case FunctionTypeEnumClass::PARAMINFO : $this->inputOutput = new IHMInputOutputParamInfoClass(); break; + case FunctionTypeEnumClass::USERWSINIT : + return $this->userWSMgr->init(); default : throw new Exception('Request type '.$function.' not implemented for this client.'); } diff --git a/src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php b/src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php new file mode 100644 index 0000000..c51c8de --- /dev/null +++ b/src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php @@ -0,0 +1,138 @@ +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.'); + + return TRUE; + } + + public function update() + { + while (IHMUserWSManagerClass::$WS_VERSION > $this->wsInfo['version']) { + $updateMethod = "updateFromVersion".$this->wsInfo['version']; + if (method_exists($this,$updateMethod)) { + if (!$this->{$updateMethod}()) { + return FALSE; + } + } + $this->wsInfo['version'] += 1; + if (!$this->saveWSInfoFile()) { + return FALSE; + } + } + return TRUE; + } + + private function loadWSInfoFile() + { + if (file_exists(IHMConfigClass::getUserWSInfoFilePath())) { + $infoContent = file_get_contents(IHMConfigClass::getUserWSInfoFilePath()); + if (empty($infoContent)) { + return FALSE; + } + $this->wsInfo = json_decode($infoContent, TRUE); + if (empty($this->wsInfo)) { + return FALSE; + } + return TRUE; + } + + //Init info file + $this->wsInfo = array( + "version" => 0, + ); + + return $this->saveWSInfoFile(); + } + + private function saveWSInfoFile() + { + if (empty($this->wsInfo)) { + return FALSE; + } + + $json_data = json_encode($this->wsInfo); + + if ($json_data === FALSE) { + return FALSE; + } + + + return file_put_contents(IHMConfigClass::getUserWSInfoFilePath(),$json_data); + } + + private function updateFromVersion0() { + // This update split plot requests + + // Load user requests file + $req_mgr_file_path = IHMConfigClass::getUserRequestManagerFilePath(); + if (!file_exists($req_mgr_file_path)) { + return TRUE; + } + + $dom = new DOMDocument(); + if (!$dom->load($req_mgr_file_path)) { + return FALSE; + } + + // Retrieve all plot requests and last request id + $plot_requests = array(); + $last_id = 0; + foreach ($dom->getElementsByTagName('request') as $requestNode) { + $request_id = $requestNode->getAttribute("xml:id"); + $plot_requests[$request_id] = $requestNode; + sscanf($request_id, "req_%d", $crt_id); + if ($crt_id > $last_id) { + $last_id = $crt_id; + } + } + + if (empty($plot_requests)) { + //No plot requests + return TRUE; + } + + // Split requests + foreach ($plot_requests as $id => $node) { + $req_data_path = IHMConfigClass::getStoredRequestPath() . $id; + if (!file_exists($req_data_path)) { + continue; + } + $req_data_content = file_get_contents($req_data_path); + if (!$req_data_content) { + continue; + } + $req_data_json = json_decode($req_data_content); + if (!$req_data_json) { + continue; + } + // ToDo + } + + + return TRUE; + } +} + diff --git a/src/Request/UserRequestClass.php b/src/Request/UserRequestClass.php new file mode 100644 index 0000000..88f1dc4 --- /dev/null +++ b/src/Request/UserRequestClass.php @@ -0,0 +1,27 @@ + diff --git a/src/RequestManagerClass.php b/src/RequestManagerClass.php index 353b7f8..c4f2291 100644 --- a/src/RequestManagerClass.php +++ b/src/RequestManagerClass.php @@ -82,6 +82,8 @@ Class RequestManagerClass return new TTRequestClass($user, $userHost); case FunctionTypeEnumClass::PARAMINFO : return new ParamInfoRequestClass($user, $userHost); + case FunctionTypeEnumClass::USERWSINIT : + return new UserRequestClass($user, $userHost); default : throw new Exception('Request '.$function.' not implemented.'); } -- libgit2 0.21.2