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