Commit 20fe3f49cfa228505e0de2c4522b85c871a45d30
1 parent
9fcffec7
Exists in
plot-request
Mecanism for user WS update
Showing
3 changed files
with
140 additions
and
41 deletions
Show diff stats
src/InputOutput/IHMImpl/Config/IHMConfigClass.php
@@ -10,17 +10,17 @@ class IHMConfigClass | @@ -10,17 +10,17 @@ class IHMConfigClass | ||
10 | private static $genericDataDir = "generic_data/"; | 10 | private static $genericDataDir = "generic_data/"; |
11 | 11 | ||
12 | private static $functionsDir = "Functions/"; | 12 | private static $functionsDir = "Functions/"; |
13 | - | 13 | + |
14 | private static $constantsFile = "constants.xml"; | 14 | private static $constantsFile = "constants.xml"; |
15 | 15 | ||
16 | private static $functionsFile = "functions.xml"; | 16 | private static $functionsFile = "functions.xml"; |
17 | - | 17 | + |
18 | private static $paramTemplateDir = "LocalData/ParamTemplate/"; | 18 | private static $paramTemplateDir = "LocalData/ParamTemplate/"; |
19 | 19 | ||
20 | private static $paramTemplateFile = "ParamTemplateList.xml"; | 20 | private static $paramTemplateFile = "ParamTemplateList.xml"; |
21 | - | 21 | + |
22 | private static $paramTemplateGenerateDir = "generateTemplateParams"; | 22 | private static $paramTemplateGenerateDir = "generateTemplateParams"; |
23 | - | 23 | + |
24 | private static $dataDir = "data/"; | 24 | private static $dataDir = "data/"; |
25 | 25 | ||
26 | private static $compilationDir = "compilation/"; | 26 | private static $compilationDir = "compilation/"; |
@@ -28,33 +28,35 @@ class IHMConfigClass | @@ -28,33 +28,35 @@ class IHMConfigClass | ||
28 | private static $requestDir = "RES/"; | 28 | private static $requestDir = "RES/"; |
29 | 29 | ||
30 | private static $sharedDir = "shared_data/"; | 30 | private static $sharedDir = "shared_data/"; |
31 | - | 31 | + |
32 | private static $sharedTreeFile = "SharedObjectTree.xml"; | 32 | private static $sharedTreeFile = "SharedObjectTree.xml"; |
33 | 33 | ||
34 | private static $ttDir = "TT/"; | 34 | private static $ttDir = "TT/"; |
35 | 35 | ||
36 | private static $wsDir = "WS/"; | 36 | private static $wsDir = "WS/"; |
37 | - | 37 | + |
38 | private static $downloadTmp = "DOWNLOAD.TEMP/"; | 38 | private static $downloadTmp = "DOWNLOAD.TEMP/"; |
39 | 39 | ||
40 | private static $jobsDir = "JOBS/"; | 40 | private static $jobsDir = "JOBS/"; |
41 | - | 41 | + |
42 | private static $localBaseDir = "DATA/"; | 42 | private static $localBaseDir = "DATA/"; |
43 | 43 | ||
44 | private static $aliasesFile = "Alias.xml"; | 44 | private static $aliasesFile = "Alias.xml"; |
45 | 45 | ||
46 | + private static $infoFile = "info.json"; | ||
47 | + | ||
46 | private static $processMgrFile = "processManager.xml"; | 48 | private static $processMgrFile = "processManager.xml"; |
47 | 49 | ||
48 | private static $jobsMgrFile = "jobs.xml"; | 50 | private static $jobsMgrFile = "jobs.xml"; |
49 | - | 51 | + |
50 | private static $userParamMgrFile = "WsParams.xml"; | 52 | private static $userParamMgrFile = "WsParams.xml"; |
51 | 53 | ||
52 | private static $userName; | 54 | private static $userName; |
53 | - | 55 | + |
54 | private static $userHost; | 56 | private static $userHost; |
55 | - | 57 | + |
56 | public static $remoteDataDir = "RemoteData/"; | 58 | public static $remoteDataDir = "RemoteData/"; |
57 | - | 59 | + |
58 | public static function setUserName($userName) | 60 | public static function setUserName($userName) |
59 | { | 61 | { |
60 | self::$userName = $userName; | 62 | self::$userName = $userName; |
@@ -64,7 +66,7 @@ class IHMConfigClass | @@ -64,7 +66,7 @@ class IHMConfigClass | ||
64 | { | 66 | { |
65 | return self::$userName; | 67 | return self::$userName; |
66 | } | 68 | } |
67 | - | 69 | + |
68 | public static function setUserHost($userHost) | 70 | public static function setUserHost($userHost) |
69 | { | 71 | { |
70 | self::$userHost = $userHost; | 72 | self::$userHost = $userHost; |
@@ -74,39 +76,44 @@ class IHMConfigClass | @@ -74,39 +76,44 @@ class IHMConfigClass | ||
74 | { | 76 | { |
75 | return self::$userHost; | 77 | return self::$userHost; |
76 | } | 78 | } |
77 | - | 79 | + |
78 | public static function getDataDir() | 80 | public static function getDataDir() |
79 | { | 81 | { |
80 | return IHM_SRC_DIR."/".self::$dataDir.'/'; | 82 | return IHM_SRC_DIR."/".self::$dataDir.'/'; |
81 | } | 83 | } |
82 | - | 84 | + |
83 | public static function getRelativeResultPath() | 85 | public static function getRelativeResultPath() |
84 | { | 86 | { |
85 | $userPath = self::$dataDir."/".self::$userName.'/'.self::$requestDir; | 87 | $userPath = self::$dataDir."/".self::$userName.'/'.self::$requestDir; |
86 | - | 88 | + |
87 | return $userPath; | 89 | return $userPath; |
88 | } | 90 | } |
89 | - | 91 | + |
90 | public static function getUserPath() | 92 | public static function getUserPath() |
91 | { | 93 | { |
92 | $userPath = self::getDataDir().self::$userName.'/'; | 94 | $userPath = self::getDataDir().self::$userName.'/'; |
93 | 95 | ||
94 | if (!is_dir($userPath)) | 96 | if (!is_dir($userPath)) |
95 | mkdir($userPath); | 97 | mkdir($userPath); |
96 | - | 98 | + |
97 | return $userPath; | 99 | return $userPath; |
98 | } | 100 | } |
99 | 101 | ||
102 | + public static function getUserWSInfoFilePath() | ||
103 | + { | ||
104 | + return self::getUserPath().self::$infoFile; | ||
105 | + } | ||
106 | + | ||
100 | public static function getProcessManagerFilePath() | 107 | public static function getProcessManagerFilePath() |
101 | { | 108 | { |
102 | return self::getDataDir().self::$processMgrFile; | 109 | return self::getDataDir().self::$processMgrFile; |
103 | } | 110 | } |
104 | - | 111 | + |
105 | public static function getGenericDataPath() | 112 | public static function getGenericDataPath() |
106 | { | 113 | { |
107 | return IHM_SRC_DIR."/".self::$genericDataDir."/"; | 114 | return IHM_SRC_DIR."/".self::$genericDataDir."/"; |
108 | } | 115 | } |
109 | - | 116 | + |
110 | public static function getConstantsFilePath() | 117 | public static function getConstantsFilePath() |
111 | { | 118 | { |
112 | return self::getGenericDataPath().self::$functionsDir.self::$constantsFile; | 119 | return self::getGenericDataPath().self::$functionsDir.self::$constantsFile; |
@@ -116,37 +123,37 @@ class IHMConfigClass | @@ -116,37 +123,37 @@ class IHMConfigClass | ||
116 | { | 123 | { |
117 | return self::getGenericDataPath().self::$functionsDir.self::$functionsFile; | 124 | return self::getGenericDataPath().self::$functionsDir.self::$functionsFile; |
118 | } | 125 | } |
119 | - | 126 | + |
120 | public static function getParamTemplateFilePath($fileName) | 127 | public static function getParamTemplateFilePath($fileName) |
121 | { | 128 | { |
122 | return self::getGenericDataPath().self::$paramTemplateDir.$fileName.".xml"; | 129 | return self::getGenericDataPath().self::$paramTemplateDir.$fileName.".xml"; |
123 | } | 130 | } |
124 | - | 131 | + |
125 | public static function getTemplateParamGeneratePath() | 132 | public static function getTemplateParamGeneratePath() |
126 | { | 133 | { |
127 | return self::getUserPath().self::$paramTemplateGenerateDir; | 134 | return self::getUserPath().self::$paramTemplateGenerateDir; |
128 | } | 135 | } |
129 | - | 136 | + |
130 | public static function getDownloadTmpPath() | 137 | public static function getDownloadTmpPath() |
131 | { | 138 | { |
132 | return self::getUserPath().self::$downloadTmp; | 139 | return self::getUserPath().self::$downloadTmp; |
133 | } | 140 | } |
134 | - | 141 | + |
135 | public static function getParamTemplateListFilePath() | 142 | public static function getParamTemplateListFilePath() |
136 | { | 143 | { |
137 | return self::getGenericDataPath().self::$paramTemplateDir.self::$paramTemplateFile; | 144 | return self::getGenericDataPath().self::$paramTemplateDir.self::$paramTemplateFile; |
138 | } | 145 | } |
139 | - | 146 | + |
140 | public static function getUserParamManagerFilePath() | 147 | public static function getUserParamManagerFilePath() |
141 | { | 148 | { |
142 | return self::getUserWSPath().self::$userParamMgrFile; | 149 | return self::getUserWSPath().self::$userParamMgrFile; |
143 | } | 150 | } |
144 | - | 151 | + |
145 | public static function getUserDerivedParamFilePath($paramId) | 152 | public static function getUserDerivedParamFilePath($paramId) |
146 | { | 153 | { |
147 | return self::getUserWSPath().$paramId.".xml"; | 154 | return self::getUserWSPath().$paramId.".xml"; |
148 | } | 155 | } |
149 | - | 156 | + |
150 | public static function getUserUploadedParamFilePath($paramId) | 157 | public static function getUserUploadedParamFilePath($paramId) |
151 | { | 158 | { |
152 | return self::getUserWSPath().$paramId.".xml"; | 159 | return self::getUserWSPath().$paramId.".xml"; |
@@ -156,7 +163,7 @@ class IHMConfigClass | @@ -156,7 +163,7 @@ class IHMConfigClass | ||
156 | { | 163 | { |
157 | return PARAMS_LOCALDB_DIR; | 164 | return PARAMS_LOCALDB_DIR; |
158 | } | 165 | } |
159 | - | 166 | + |
160 | public static function getLocalParamInfoPath() | 167 | public static function getLocalParamInfoPath() |
161 | { | 168 | { |
162 | return PARAMS_LOCALINFO_DIR; | 169 | return PARAMS_LOCALINFO_DIR; |
@@ -166,7 +173,7 @@ class IHMConfigClass | @@ -166,7 +173,7 @@ class IHMConfigClass | ||
166 | { | 173 | { |
167 | return IHM_SRC_DIR.'/'.self::$sharedDir; | 174 | return IHM_SRC_DIR.'/'.self::$sharedDir; |
168 | } | 175 | } |
169 | - | 176 | + |
170 | public static function getSharedTreeFilePath() | 177 | public static function getSharedTreeFilePath() |
171 | { | 178 | { |
172 | return self::getSharedPath().self::$sharedTreeFile; | 179 | return self::getSharedPath().self::$sharedTreeFile; |
@@ -215,44 +222,44 @@ class IHMConfigClass | @@ -215,44 +222,44 @@ class IHMConfigClass | ||
215 | mkdir($compilationPath."lib/"); | 222 | mkdir($compilationPath."lib/"); |
216 | } | 223 | } |
217 | } | 224 | } |
218 | - | 225 | + |
219 | return $compilationPath; | 226 | return $compilationPath; |
220 | } | 227 | } |
221 | 228 | ||
222 | public static function getLocalBasePath() | 229 | public static function getLocalBasePath() |
223 | { | 230 | { |
224 | $localBasePath = self::getUserPath().self::$localBaseDir; | 231 | $localBasePath = self::getUserPath().self::$localBaseDir; |
225 | - | 232 | + |
226 | if (!is_dir($localBasePath)) | 233 | if (!is_dir($localBasePath)) |
227 | mkdir($localBasePath); | 234 | mkdir($localBasePath); |
228 | - | 235 | + |
229 | return $localBasePath; | 236 | return $localBasePath; |
230 | } | 237 | } |
231 | - | 238 | + |
232 | public static function getRemoteParamsFile() | 239 | public static function getRemoteParamsFile() |
233 | { | 240 | { |
234 | $remoteBasePath = self::getUserPath().self::$wsDir; | 241 | $remoteBasePath = self::getUserPath().self::$wsDir; |
235 | - | 242 | + |
236 | return $remoteBasePath.'RemoteParams.xml'; | 243 | return $remoteBasePath.'RemoteParams.xml'; |
237 | } | 244 | } |
238 | - | 245 | + |
239 | public static function getRequestPath() | 246 | public static function getRequestPath() |
240 | { | 247 | { |
241 | $requestPath = self::getUserPath().self::$requestDir; | 248 | $requestPath = self::getUserPath().self::$requestDir; |
242 | 249 | ||
243 | if (!is_dir($requestPath)) | 250 | if (!is_dir($requestPath)) |
244 | mkdir($requestPath); | 251 | mkdir($requestPath); |
245 | - | 252 | + |
246 | return $requestPath; | 253 | return $requestPath; |
247 | } | 254 | } |
248 | - | 255 | + |
249 | public static function getRemoteDataPath() | 256 | public static function getRemoteDataPath() |
250 | { | 257 | { |
251 | $remoteDataPath = self::getGenericDataPath().self::$remoteDataDir; | 258 | $remoteDataPath = self::getGenericDataPath().self::$remoteDataDir; |
252 | - | 259 | + |
253 | return $remoteDataPath; | 260 | return $remoteDataPath; |
254 | } | 261 | } |
255 | - | 262 | + |
256 | } | 263 | } |
257 | 264 | ||
258 | ?> | 265 | ?> |
src/InputOutput/IHMImpl/IHMInputOutputClass.php
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | class IHMInputOutputClass implements InputOutputInterface | 8 | class IHMInputOutputClass implements InputOutputInterface |
9 | { | 9 | { |
10 | protected $inputOutput = null; | 10 | protected $inputOutput = null; |
11 | + protected $userWSMgr = null; | ||
11 | 12 | ||
12 | /* | 13 | /* |
13 | * @brief Constructor | 14 | * @brief Constructor |
@@ -16,6 +17,7 @@ class IHMInputOutputClass implements InputOutputInterface | @@ -16,6 +17,7 @@ class IHMInputOutputClass implements InputOutputInterface | ||
16 | { | 17 | { |
17 | IHMConfigClass::setUserName($userName); | 18 | IHMConfigClass::setUserName($userName); |
18 | IHMConfigClass::setUserHost($userHost); | 19 | IHMConfigClass::setUserHost($userHost); |
20 | + $this->userWSMgr = new IHMUserWSManagerClass(); | ||
19 | } | 21 | } |
20 | 22 | ||
21 | /* | 23 | /* |
@@ -23,9 +25,8 @@ class IHMInputOutputClass implements InputOutputInterface | @@ -23,9 +25,8 @@ class IHMInputOutputClass implements InputOutputInterface | ||
23 | */ | 25 | */ |
24 | public function getInputData($input,$function,$requestId = "") | 26 | public function getInputData($input,$function,$requestId = "") |
25 | { | 27 | { |
26 | - //check user workspace | ||
27 | - if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath())) | ||
28 | - throw new Exception('Cannot find user workspace.'); | 28 | + //check user workspace |
29 | + $this->userWSMgr->init(); | ||
29 | 30 | ||
30 | switch ($function) | 31 | switch ($function) |
31 | { | 32 | { |
src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php
0 โ 100644
@@ -0,0 +1,91 @@ | @@ -0,0 +1,91 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * @class IHMUserWSManagerClass | ||
5 | + * @brief Manager for IHM user workspace | ||
6 | + * @details | ||
7 | + */ | ||
8 | +class IHMUserWSManagerClass | ||
9 | +{ | ||
10 | + private static $version = 1; | ||
11 | + | ||
12 | + protected $wsInfo = null; | ||
13 | + | ||
14 | + public function init() | ||
15 | + { | ||
16 | + //check user workspace | ||
17 | + if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath())) | ||
18 | + throw new Exception('Cannot find user workspace.'); | ||
19 | + | ||
20 | + //Load info about WS | ||
21 | + if (!$this->loadWSInfoFile()) | ||
22 | + throw new Exception('Error to load workspace info file.'); | ||
23 | + | ||
24 | + //Update WS if need | ||
25 | + if (!$this->update()) | ||
26 | + throw new Exception('Error during user workspace conversion.'); | ||
27 | + } | ||
28 | + | ||
29 | + public function update() | ||
30 | + { | ||
31 | + error_log(print_r($this->wsInfo,TRUE)); | ||
32 | + error_log('BRE - update - '.$this->wsInfo['version']); | ||
33 | + //while (IHMUserWSManagerClass::$version > $this->wsInfo['version']) { | ||
34 | + $updateMethod = "updateFromVersion".$this->wsInfo['version']; | ||
35 | + error_log('BRE - '.$updateMethod); | ||
36 | + if (method_exists($this,$updateMethod)) { | ||
37 | + if (!$this->{$updateMethod}()) { | ||
38 | + return FALSE; | ||
39 | + } | ||
40 | + } | ||
41 | + ++$this->wsInfo['version']; | ||
42 | + error_log('BRE - saveWSInfoFile'); | ||
43 | + $this->saveWSInfoFile(); | ||
44 | + //} | ||
45 | + return $this->saveWSInfoFile(); | ||
46 | + } | ||
47 | + | ||
48 | + private function loadWSInfoFile() | ||
49 | + { | ||
50 | + if (file_exists(IHMConfigClass::getUserWSInfoFilePath())) { | ||
51 | + $infoContent = file_get_contents(IHMConfigClass::getUserWSInfoFilePath()); | ||
52 | + if (empty($infoContent)) { | ||
53 | + return FALSE; | ||
54 | + } | ||
55 | + $this->wsInfo = json_decode($infoContent); | ||
56 | + if (empty($this->wsInfo)) { | ||
57 | + return FALSE; | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | + //Init info file | ||
62 | + $this->wsInfo = array( | ||
63 | + "version" => 0, | ||
64 | + ); | ||
65 | + | ||
66 | + return $this->saveWSInfoFile(); | ||
67 | + } | ||
68 | + | ||
69 | + private function saveWSInfoFile() | ||
70 | + { | ||
71 | + error_log('BRE - saveWSInfoFile'); | ||
72 | + if (empty($this->wsInfo)) { | ||
73 | + return FALSE; | ||
74 | + } | ||
75 | + | ||
76 | + $json_data = json_encode($this->wsInfo); | ||
77 | + | ||
78 | + if ($json_data === FALSE) { | ||
79 | + return FALSE; | ||
80 | + } | ||
81 | + | ||
82 | + error_log(IHMConfigClass::getUserWSInfoFilePath()); | ||
83 | + | ||
84 | + return file_put_contents(IHMConfigClass::getUserWSInfoFilePath(),$json_data); | ||
85 | + } | ||
86 | + | ||
87 | + private function updateFromVersion0() { | ||
88 | + error_log('BRE - updateFromVersion0 call'); | ||
89 | + return TRUE; | ||
90 | + } | ||
91 | +} |