Blame view

php/classes/UserWsTransfer.php 19.7 KB
16035364   Benjamin Renard   First commit
1
2
3
<?php
/**
 * @class UserWsTransfer
16035364   Benjamin Renard   First commit
4
5
 */

d95e8421   Elena.Budnik   ws transfer : ini...
6
class UserWsTransfer {  
16035364   Benjamin Renard   First commit
7

d95e8421   Elena.Budnik   ws transfer : ini...
8
9
	private $oldWs, $newWs, $Mgr;
	private $oldWsDir, $newWsDir;
7b514636   Elena.Budnik   add migration pos...
10
	private $ws_deleted, $wsd_deleted, $pairs, $specParams, $postPairs;
16035364   Benjamin Renard   First commit
11
   
d95e8421   Elena.Budnik   ws transfer : ini...
12
13
14
15
	function __construct($user) 
	{  
	   define('OLDUSERPATH', 'http://cdpp1.irap.omp.eu/AMDA-NG/data/');
	  // define('OLDUSERPATH', 'http://amda-dev.irap.omp.eu/~budnik/AMDA-NG4/trunk/data/');
08a89462   Elena.Budnik   convert old user ws
16
		define('NEWUSERPATH', USERPATH);
d95e8421   Elena.Budnik   ws transfer : ini...
17
		define('TRANSFERUSER', $user);
08a89462   Elena.Budnik   convert old user ws
18
	   define('CONVERSIONDIR',  DATAPATH."migration/");
d95e8421   Elena.Budnik   ws transfer : ini...
19
20
21
22
23
24
25
26
27
28
29
30
31
		
		$this->oldWs = new DomDocument("1.0");
		$this->newWs = new DomDocument("1.0");
		
		$this->oldWsDir = OLDUSERPATH.TRANSFERUSER.'/WS/';
		$this->newWsDir = NEWUSERPATH.TRANSFERUSER.'/WS/';
		
		if (!is_dir(NEWUSERPATH.TRANSFERUSER.'/WS'))
			mkdir(NEWUSERPATH.TRANSFERUSER.'/WS', 0775);
			
		$this->ws_deleted = array();
		$this->wsd_deleted = array();
		$this->getModified();
7b514636   Elena.Budnik   add migration pos...
32
		$this->getReprocessed();
57c64695   Nathanaël Jourdane   add spectra
33
		$this->getSpectra();
d95e8421   Elena.Budnik   ws transfer : ini...
34
35
36
37
38
39
40
41
42
	}
	
	private function getObsolete() {
	
		$deletedXML = new DomDocument("1.0");
		$deletedXML->load(CONVERSIONDIR."Deleted.xml"); 
		$deletedNodes = $deletedXML->getElementsByTagName('deleted');
		
		$deleted = array();
981cd087   Elena.Budnik   ws transfer modifs
43
		foreach ($deletedNodes as $node) 
d95e8421   Elena.Budnik   ws transfer : ini...
44
			$deleted[] = $node->getAttribute('xml:id');
981cd087   Elena.Budnik   ws transfer modifs
45

d95e8421   Elena.Budnik   ws transfer : ini...
46
47
		return $deleted;
	}
cdf22cdd   Elena.Budnik   message window co...
48
49
50
51
52
53
54
55
56
57
	
	private function getNotreadyFunctions() {
	
		$deletedXML = new DomDocument("1.0");
		$deletedXML->load(CONVERSIONDIR."Functions.xml"); 
		$deletedNodes = $deletedXML->getElementsByTagName('deleted');
		
		$notready = array();
		foreach ($deletedNodes as $node)
			$notready[] = $node->getAttribute('xml:id');
d95e8421   Elena.Budnik   ws transfer : ini...
58
		
cdf22cdd   Elena.Budnik   message window co...
59
60
61
		return $notready;
	}
	
d95e8421   Elena.Budnik   ws transfer : ini...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
	private function getNotready() {
	
		$deletedXML = new DomDocument("1.0");
		$deletedXML->load(CONVERSIONDIR."NotReady.xml"); 
		$deletedNodes = $deletedXML->getElementsByTagName('deleted');
		
		$notready = array();
		foreach ($deletedNodes as $node)
			$notready[] = $node->getAttribute('xml:id');
		
		return $notready;
	}
	
	private function deleteParam($exp, $deleted) 
	{
		$toDelete = false;
981cd087   Elena.Budnik   ws transfer modifs
78
79
80
81
82
83
84
		 
		if (count($deleted)  > 0)
			foreach ($deleted as $item) {
				if (strpos($exp, $item) !== false)  {
					$toDelete = true;
					break;
				}
d95e8421   Elena.Budnik   ws transfer : ini...
85
			}
d95e8421   Elena.Budnik   ws transfer : ini...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

		return $toDelete;
	}
	
	private function getWs($exp) 
	{	
		$ws = array();
		
		if (strpos($exp, 'ws_') !== false)  {
			 $arr = $this->delimitIt($exp);
			 foreach ($arr as $item) {
				if (strpos($item, 'ws_') !== false)
						$ws[] = substr($item,3);
			 }
			 return $ws;
		}
		return false;
	}
	
	private function delimitIt($chain) {
16035364   Benjamin Renard   First commit
106
       
d95e8421   Elena.Budnik   ws transfer : ini...
107
108
109
       $delimiter = '[]+,/*()^<>&|=[-]+';    
       $array = split($delimiter,$chain);
       if (trim(end($array)) == "") array_pop($array);
16035364   Benjamin Renard   First commit
110

d95e8421   Elena.Budnik   ws transfer : ini...
111
112
       return $array;
   }
16035364   Benjamin Renard   First commit
113
   
d95e8421   Elena.Budnik   ws transfer : ini...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
	private function getModified() 
	{
		$convertXML = new DomDocument("1.0");
		$modifiedFile = CONVERSIONDIR.'Modified.xml';
			
		if (!$convertXML->load($modifiedFile)) 
							error_log('ERROR loading '.$modifiedFile,1,email);
		$convertedNodes = $convertXML->getElementsByTagName('param_convert');

		foreach ($convertedNodes as $item) {   
			$pairs[$item->getAttribute('oldid')] = $item->getAttribute('xml:id');
		}    
		krsort($pairs, SORT_NATURAL);
		
		$this->pairs = $pairs;
	}
981cd087   Elena.Budnik   ws transfer modifs
130
	
7b514636   Elena.Budnik   add migration pos...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
	private function getReprocessed() 
	{
		$convertXML = new DomDocument("1.0");
		$modifiedFile = CONVERSIONDIR.'PostProcess.xml';
			
		if (!$convertXML->load($modifiedFile)) 
							error_log('ERROR loading '.$modifiedFile,1,email);
		$convertedNodes = $convertXML->getElementsByTagName('param_convert');

		foreach ($convertedNodes as $item) {   
			$pairs[$item->getAttribute('oldid')] = $item->getAttribute('xml:id');
		}    
		krsort($pairs, SORT_NATURAL);
		
		$this->postPairs = $pairs;
	}
	
981cd087   Elena.Budnik   ws transfer modifs
148
	private function getSpectra() 
57c64695   Nathanaël Jourdane   add spectra
149
150
151
	{
		$convertXML = new DomDocument("1.0");
		$modifiedFile = CONVERSIONDIR.'SpectraModifs.xml';
981cd087   Elena.Budnik   ws transfer modifs
152
153
			
		if (!$convertXML->load($modifiedFile)) 
57c64695   Nathanaël Jourdane   add spectra
154
155
156
							error_log('ERROR loading '.$modifiedFile,1,email);
		$convertedNodes = $convertXML->getElementsByTagName('deleted');

981cd087   Elena.Budnik   ws transfer modifs
157
		foreach ($convertedNodes as $item) {   
57c64695   Nathanaël Jourdane   add spectra
158
			$this->specParams[] = $item->getAttribute('xml:id');
981cd087   Elena.Budnik   ws transfer modifs
159
		}    
57c64695   Nathanaël Jourdane   add spectra
160
	}
981cd087   Elena.Budnik   ws transfer modifs
161
	
d95e8421   Elena.Budnik   ws transfer : ini...
162
163
164
	private function updateParams($expression)
	{
		$newExp = strtr($expression, $this->pairs);
7b514636   Elena.Budnik   add migration pos...
165
166
167
168
		if (!empty($this->postPairs))
			$expFinal = strtr($newExp, $this->postPairs);
		
		return $expFinal;
d95e8421   Elena.Budnik   ws transfer : ini...
169
	}
7b514636   Elena.Budnik   add migration pos...
170
171
	
	
d95e8421   Elena.Budnik   ws transfer : ini...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	protected function createDom() 
	{
		$types = array('param' => 'derived', 'mydata' => 'myData');

		$rootElement = $this->newWs->createElement('ws');
		foreach ($types as $key => $value)
		{
			$contentId = $value.'Param-treeRootNode';
			$contentTag = $key.'List';
			$typeElement = $this->newWs->createElement($contentTag);
			$typeElement->setAttribute('xml:id', $contentId);
			$rootElement->appendChild($typeElement);
		}
		
		$this->newWs->appendChild($rootElement);
981cd087   Elena.Budnik   ws transfer modifs
187
	   $this->newWs->save($this->newWsDir.'WsParams.xml');
d95e8421   Elena.Budnik   ws transfer : ini...
188
189
	}
	
5a647f75   Elena.Budnik   curl_init() chang...
190
	public function urlExists($url) 
d95e8421   Elena.Budnik   ws transfer : ini...
191
	{
5a647f75   Elena.Budnik   curl_init() chang...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
		$handle = curl_init($url);
		curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);

		$response = curl_exec($handle);
		$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
		curl_close($handle);

		if($httpCode >= 200 && $httpCode <= 400 || $httpCode == 403) {
			return true;
		} else {
			return false;
		}
	}
		
	public function checkWS() 
	{
		// old ws   
		if (!$this->urlExists(OLDUSERPATH.TRANSFERUSER)) {
d95e8421   Elena.Budnik   ws transfer : ini...
210
211
212
213
				error_log('no  '.TRANSFERUSER.' at old AMDA',1,email);
				return array('success' => false, 'error' => 'Sorry, it seems you have no account at old AMDA');
		}

5a647f75   Elena.Budnik   curl_init() chang...
214
		if (!$this->urlExists($this->oldWsDir)) {
d95e8421   Elena.Budnik   ws transfer : ini...
215
216
217
218
219
220
221
222
223
			error_log('no ws.xml for '.TRANSFERUSER,1,email);
			return array('success' => false, 'error' => 'Sorry, we failed to find your workspace at old AMDA');
		}
		
		return array('success' => true);
	}
	
	public function transferDerived() 
	{
adcf0710   Elena.Budnik   message for WS co...
224
		$msg = '<hr><br/><b><i>Derived Params:</i></b><br/><br/>';
6a449df8   Elena.Budnik   message format
225
		$msg .= '<i>Note</i> : Parameters made from Remote Base parameters are not copied <br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
226
227
		if (!$this->oldWs->load($this->oldWsDir.'WsParams.xml')) {
			error_log('cannot load WsParams.xml for '.TRANSFERUSER,1,email);
6a449df8   Elena.Budnik   message format
228
			return array('success' => false, 'error' => 'Sorry, we failed to get your Derived Params from old AMDA');
d95e8421   Elena.Budnik   ws transfer : ini...
229
230
231
232
233
234
235
236
		}

		if (!file_exists($this->newWsDir.'WsParams.xml'))
						$this->createDom();
		else 
			$this->newWs->load($this->newWsDir.'WsParams.xml');
		
		$deleted = $this->getObsolete();
981cd087   Elena.Budnik   ws transfer modifs
237
	
d95e8421   Elena.Budnik   ws transfer : ini...
238
		$notready = $this->getNotready();
cdf22cdd   Elena.Budnik   message window co...
239
		$notreadyFunctions = $this->getNotreadyFunctions();
d95e8421   Elena.Budnik   ws transfer : ini...
240
241
242
243
244
245
246
247
248
249
		
	   $wsParamNode = $this->newWs->getElementsByTagName('paramList')->item(0);
	   
		$wsParamsOld = $this->oldWs->getElementsByTagName('param');
		
		if ($wsParamsOld->length == 0) {
				return array('success' => true, 'msg' => 'No parameters');
		}
		
		$paramXml = new DomDocument("1.0");
adcf0710   Elena.Budnik   message for WS co...
250
	
de5d1909   Elena.Budnik   message corrected
251
		$msg .= 'Some expressions could have problems while being processed by new kernel <br/> - <b>Please send us feedback in this case.</b><br><br>Not copied derived parameters :<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
252
253
254
255
256
257
258
259
		
		foreach ($wsParamsOld as $param) {        
			$id = $param->getAttribute('xml:id');
			$name = $param->getAttribute('name');
			
			$expression = $param->getAttribute('buildchain');

			if ($this->deleteParam($expression,$deleted)) {
6a449df8   Elena.Budnik   message format
260
						$msg .= '<li><i>'.$name.'</i> : uses obsolete param<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
261
262
263
264
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
981cd087   Elena.Budnik   ws transfer modifs
265
			 
d95e8421   Elena.Budnik   ws transfer : ini...
266
			if ($this->deleteParam($expression,$notready)) {
6a449df8   Elena.Budnik   message format
267
						$msg .= '<li><i>'.$name.'</i> : uses param not ready yet <br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
268
269
270
271
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
981cd087   Elena.Budnik   ws transfer modifs
272
			 
cdf22cdd   Elena.Budnik   message window co...
273
			if ($this->deleteParam($expression,$notreadyFunctions)) {
6a449df8   Elena.Budnik   message format
274
						$msg .= '<li><i>'.$name.'</i> : uses function not ready yet <br/> '.$expression.'<br/>';
cdf22cdd   Elena.Budnik   message window co...
275
276
277
278
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
981cd087   Elena.Budnik   ws transfer modifs
279
			 
d95e8421   Elena.Budnik   ws transfer : ini...
280
281
			if (!empty($this->wsd_deleted))
					if ($this->deleteParam($expression,$this->wsd_deleted)) {
6a449df8   Elena.Budnik   message format
282
						$msg .= '<li><i>'.$name.'</i> : uses obsolete myData param<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
283
284
285
286
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
981cd087   Elena.Budnik   ws transfer modifs
287
			 
d95e8421   Elena.Budnik   ws transfer : ini...
288
			if ($this->deleteParam($expression,array("CDAWEB","MAPSKP","VEXGRAZ","IMPEX"))) {
6a449df8   Elena.Budnik   message format
289
						$msg .= '<li><i>'.$name.'</i> : uses remote params <br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
290
291
292
						$this->ws_deleted[] = $name;
						continue;
			}
981cd087   Elena.Budnik   ws transfer modifs
293
294
295
296
297
			
			if ($this->deleteParam($expression,$this->specParams)) {
						$msg .= '<li><i>'.$name.'</i> : too much difference <br/> '.$expression.'<br/>';
						$this->ws_deleted[] = $name;
						continue;
57c64695   Nathanaël Jourdane   add spectra
298
			}
981cd087   Elena.Budnik   ws transfer modifs
299
			 
d95e8421   Elena.Budnik   ws transfer : ini...
300
			$expressionUpdated = $this->updateParams($expression);
981cd087   Elena.Budnik   ws transfer modifs
301
  
d95e8421   Elena.Budnik   ws transfer : ini...
302
303
304
305
306
307
			$wsParamNode->appendChild($this->newWs->importNode($param));
			
			$paramXml->load($this->oldWsDir.$id.'.xml');
			$expressionNode = $paramXml->getElementsByTagName('buildchain')->item(0);
			$expressionNode->nodeValue = $expressionUpdated;
			$paramXml->save($this->newWsDir.$id.'.xml');
981cd087   Elena.Budnik   ws transfer modifs
308
309
310
311
312
			
			$nodeInWS = $this->newWs->getElementById($id);
			if ($nodeInWS) {
				$buildchain = $nodeInWS->getAttribute('buildchain');
				$buildchainUpdated = $this->updateParams($buildchain);
7b514636   Elena.Budnik   add migration pos...
313
				
981cd087   Elena.Budnik   ws transfer modifs
314
315
				$nodeInWS->setAttribute('buildchain',$buildchainUpdated);
			}
d95e8421   Elena.Budnik   ws transfer : ini...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
		}
		
		// check of 'ws bricks' were deleted
		$newParams = $this->newWs->getElementsByTagName('param');
		$xp = new domxpath($this->newWs); 
		$paramsToRemove = array();
		
		foreach ($newParams as $param) {
			$id = $param->getAttribute('xml:id');
			$name = $param->getAttribute('name');
			
			$expression = $param->getAttribute('buildchain');
			if ($wsParams = $this->getWs($expression)) {
				foreach ($wsParams as $wsParam) {
					$res = $xp->query("//param[@name='".trim($wsParam)."']");
					if ($res->length == 0) {
77237fff   Elena.Budnik   if ws param was a...
332
333
334
335
336
337
						if (file_exists($this->newWsDir.$id.'.xml')) { // Delete only once
							unlink($this->newWsDir.$id.'.xml');
							$paramsToRemove[] = $param; 
							$this->ws_deleted[] = $name;
							$msg .= '<li><i>'.$name.'</i> : uses obsolete / not ready ws param : <br/> '.$expression.'<br/>';
						}
d95e8421   Elena.Budnik   ws transfer : ini...
338
339
340
341
342
					}
				}
			}
		}
		
77237fff   Elena.Budnik   if ws param was a...
343
344
345
346
		if (count($paramsToRemove) > 0)
			foreach ($paramsToRemove as $paramToRemove) {
				$paramToRemove->parentNode->removeChild($paramToRemove);
			}
d95e8421   Elena.Budnik   ws transfer : ini...
347
348
349
350
		
		$this->newWs->save($this->newWsDir.'WsParams.xml');
		$copied = $newParams->length - count($paramsToRemove);
		
adcf0710   Elena.Budnik   message for WS co...
351
		$msg .= '<br/><i>Copied : </i>'.$copied.' derived parameters<br/><br/><hr>';
d95e8421   Elena.Budnik   ws transfer : ini...
352
353
354
355
356
		return array('success' => true, 'msg' => $msg);
	}

	public function transferTimeTables() 
	{    
6a449df8   Elena.Budnik   message format
357
		$msg = '<b><i>Time Tables:</i></b><br/><br/>'; 
d95e8421   Elena.Budnik   ws transfer : ini...
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
		
		// get old time tab list
		$this->newWs->load($this->oldWsDir.'Tt.xml');
		$timeTabs = $this->newWs->getElementsByTagName('timetab');
		if ($timeTabs->length == 0) {
			$msg .= 'No time tables';
			return array('success' => true, 'msg' => $msg);
		}
		
		$oldTtDir = OLDUSERPATH.TRANSFERUSER."/TT/";
		$newTtDir = NEWUSERPATH.TRANSFERUSER."/TT/";
		foreach ($timeTabs as $tab) {
			$id = $tab->getAttribute('xml:id');
			copy($oldTtDir.$id.'.xml', $newTtDir.$id.'.xml');
		}
		
		$this->newWs->save($this->newWsDir.'Tt.xml');
adcf0710   Elena.Budnik   message for WS co...
375
		$msg .= '<i>Copied : </i>'.$timeTabs->length.' time tables<br/><br/><hr>';
d95e8421   Elena.Budnik   ws transfer : ini...
376
377
		return array('success' => true, 'msg' => $msg);
	}
16035364   Benjamin Renard   First commit
378
 
d95e8421   Elena.Budnik   ws transfer : ini...
379
380
	public function transferConditions() 
	{
6a449df8   Elena.Budnik   message format
381
		$msg = '<b><i>Requests</i></b><br/><br/>';
311208da   Elena.Budnik   typo in msg
382
		$msg .= '<i>Note :</i> Plot requests are not copied : too much difference between new and old AMDA versions<br/<br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
383
384
385
		$oldRequestXml = new DomDocument("1.0");
		$newRequestXml = new DomDocument("1.0");
		
981cd087   Elena.Budnik   ws transfer modifs
386
		if (!@$oldRequestXml->load($this->oldWsDir.'Request.xml')){
6a449df8   Elena.Budnik   message format
387
			$msg .= ' No Requests File<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
388
389
390
391
392
393
394
395
			return array('success' => true, 'msg' => $msg);
		}
		
		$condNodes = $oldRequestXml->getElementsByTagName('condition');
		if ($condNodes->length == 0) {
			$msg .= ' no DataMining requests to copy<br/>';
			return array('success' => true, 'msg' => $msg);
		}
981cd087   Elena.Budnik   ws transfer modifs
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
		
		if (!file_exists($this->newWsDir.'Request.xml')) {
			$types = array('request', 'condition');

			$rootElement = $newRequestXml->createElement('ws');
			foreach ($types as $type)
			{
				$contentId = $type.'-treeRootNode';
				$contentTag = $type.'List';
				$typeElement = $newRequestXml->createElement($contentTag);
				$typeElement->setAttribute('xml:id', $contentId);
				$rootElement->appendChild($typeElement);
			}
			
			$newRequestXml->appendChild($rootElement);			 
		}				
		else 
			$newRequestXml->load($this->newWsDir.'Request.xml'); 
		
d95e8421   Elena.Budnik   ws transfer : ini...
415
416
417
418
419
420
		$conditionRoot = $newRequestXml->getElementsByTagName('conditionList')->item(0);
		
		$condDir = OLDUSERPATH.TRANSFERUSER."/REQ/";
		
		$deleted = $this->getObsolete();
		$notready = $this->getNotready();
39d0bf07   Elena.Budnik   typo msg
421
		$msg .= 'Some expressions could have problems while being processed by new kernel <br/> - <b>Please send us feedback in this case.</b><br/><br>
adcf0710   Elena.Budnik   message for WS co...
422
		 Not copied DataMining requests :<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
423
424
425
426
427
428
429
430
431
		
		foreach ($condNodes as $condNode) {
			$id = $condNode->getAttribute('xml:id');
			$name = $condNode->getAttribute('name');
			$cond = file($condDir.$id, FILE_IGNORE_NEW_LINES);

			$condObj = json_decode($cond[0]);
			$expression = $condObj->expression;
			if ($this->deleteParam($expression, $deleted)) {
de5d1909   Elena.Budnik   message corrected
432
						$msg .= '<li><i>'.$name.'</i> : uses obsolete parameters<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
433
434
435
436
437
						$cond_deleted[] = $name;
 						continue;
 			}
 			
 			if ($this->deleteParam($expression,$notready)) {
6a449df8   Elena.Budnik   message format
438
						$msg .= '<li><i>'.$name.'</i> : uses param not ready yet<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
439
440
441
442
443
444
445
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$cond_deleted[] = $name;
						continue;
			}
			
			if (!empty($this->wsd_deleted))
					if ($this->deleteParam($expression,$this->wsd_deleted)) {
de5d1909   Elena.Budnik   message corrected
446
						$msg .= '<li><i>'.$name.'</i> : uses obsolete myData parameters<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
447
448
449
450
451
452
453
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$cond_deleted[] = $name;
						continue;
			}
			
			if (!empty($this->ws_deleted))
					if ($this->deleteParam($expression,$this->ws_deleted)) {
de5d1909   Elena.Budnik   message corrected
454
						$msg .= '<li><i>'.$name.'</i> : uses obsolete derived parameters<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
455
456
457
458
459
460
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$cond_deleted[] = $name;
						continue;
			}
			
			if ($this->deleteParam($expression,array("CDAWEB","MAPSKP","VEXGRAZ","IMPEX"))) {
6a449df8   Elena.Budnik   message format
461
						$msg .= '<li><i>'.$name.'</i> : uses remote params <br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
462
463
464
						$cond_deleted[] = $name;
						continue;
			}
981cd087   Elena.Budnik   ws transfer modifs
465
			
57c64695   Nathanaël Jourdane   add spectra
466
			if ($this->deleteParam($expression,$this->specParams)) {
981cd087   Elena.Budnik   ws transfer modifs
467
468
469
						$msg .= '<li><i>'.$name.'</i> : too much difference <br/> '.$expression.'<br/>';
						$cond_deleted[] = $name;
						continue;
57c64695   Nathanaël Jourdane   add spectra
470
			}
d95e8421   Elena.Budnik   ws transfer : ini...
471
472
473
474
475
476
477
			$expressionUpdated = $this->updateParams($expression);
			$condObj->expression = $expressionUpdated;
			file_put_contents(NEWUSERPATH.TRANSFERUSER."/REQ/".$id, json_encode($condObj));
			$conditionRoot->appendChild($newRequestXml->importNode($condNode));
		}
		
		$newRequestXml->save($this->newWsDir.'Request.xml');
d95e8421   Elena.Budnik   ws transfer : ini...
478
479
480

		return array('success' => true, 'msg' => $msg);
	}
16035364   Benjamin Renard   First commit
481
  
d95e8421   Elena.Budnik   ws transfer : ini...
482
483
	public function transferMyData() 
	{
adcf0710   Elena.Budnik   message for WS co...
484
		$msg = '<hr><b><i>MyData Parameters / My Files:</i></b><br/><br/>';
6a449df8   Elena.Budnik   message format
485
		$msg.= '<i>Note :</i> CEF format is not implemented<br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
		
		if (!$this->oldWs->load($this->oldWsDir.'WsParams.xml')) {
			error_log('cannot load WsParams.xml for '.TRANSFERUSER,1,email);
			return array('success' => false, 'error' => 'Sorry, we failed to get your MyData Params from old AMDA');
		}

		if (!file_exists($this->newWsDir.'WsParams.xml'))
						$this->createDom();
		else 
			$this->newWs->load($this->newWsDir.'WsParams.xml');
			
		$BaseXml =  new DomDocument("1.0");
		$FilesXml = new DomDocument("1.0");
		
		// get old params 
		$wsdParamsOld = $this->oldWs->getElementsByTagName('mydata');

		if ($wsdParamsOld->length == 0) {
6a449df8   Elena.Budnik   message format
504
				return array('success' => true, 'msg' => 'You have no MyData parameters');
d95e8421   Elena.Budnik   ws transfer : ini...
505
506
507
508
509
510
511
512
513
514
515
516
		}
		
		if (!$BaseXml->load(OLDUSERPATH.TRANSFERUSER.'/DATA/base.xml')) {
			return array('success' => false, 'msg' => 'base description corrupted');
		}
		
		if (!$FilesXml->load($this->oldWsDir.'Files.xml')) {
			return array('success' => false, 'msg' => 'files description corrupted');
		}
		
		$this->newWs->load($this->newWsDir.'WsParams.xml');
		$paramDom = new DomDocument("1.0");
6a449df8   Elena.Budnik   message format
517
518
     
      $msg.= ' Not copied parameters : <br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
519
520
521
522
523
524
525
		foreach ($wsdParamsOld as $wsdParamOld) {
			$format = $wsdParamOld->getAttribute('format');
			$name = $wsdParamOld->getAttribute('name');
			$id = $wsdParamOld->getAttribute('xml:id');
			$mask = $wsdParamOld->getAttribute('mask');
			if ($format == 'cef') {
				$deletedVi[] = $mask;
6a449df8   Elena.Budnik   message format
526
				$msg .= '<li><i>'.$name.'</i><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
				$this->wsd_deleted[] = 'wsd_'.$name;
			}
			else {
				$desc = $wsdParamOld->getAttribute('desc');
				$start = substr($desc,0,16).':00';
				$stop = substr($desc,17).':00';
				$wsdParamOld->setAttribute('desc', $start.'-'.$stop);
				
				$this->newWs->getElementsByTagName('mydataList')->item(0)->appendChild($this->newWs->importNode($wsdParamOld));
				
				$paramDom->load($this->oldWsDir.$id.'.xml');
				$descNode = $paramDom->getElementsByTagName('desc')->item(0);
				$descNode->nodeValue = $start.'-'.$stop;
				$paramDom->save($this->newWsDir.$id.'.xml'); 
				
				$fileFormat[$mask] = $format === 'txt' ? 'ASCII' : strtoupper($format);
			}
		}
cdf22cdd   Elena.Budnik   message window co...
545

d95e8421   Elena.Budnik   ws transfer : ini...
546
547
548
549
		$this->newWs->save($this->newWsDir.'WsParams.xml');
		
		// First delete CEF files
		$xpBase = new domxpath($BaseXml);
de5d1909   Elena.Budnik   message corrected
550
551
552
553
554
555
556
557
558
		if (count($deletedVi) > 0)
			foreach ($deletedVi as $vi) {
				$maskNode = $xpBase->query("//mask[.='".$vi."']");
				if ( $maskNode->length == 0 )
					error_log('No '.$vi.' in '.TRANSFERUSER.'/DATA/base.xml',1,email);
				else {
					$viNode = $maskNode->item(0)->parentNode;
					$viNode->parentNode->removeChild($viNode);
				}
d95e8421   Elena.Budnik   ws transfer : ini...
559
			}
d95e8421   Elena.Budnik   ws transfer : ini...
560
561
562
563
564
565
566
567
		// Then modify base.xml : xml:id => id
		$viNodes = $BaseXml->getElementsByTagName('vi');
		foreach ($viNodes as $viNode) {
			$id = $viNode->getAttribute('xml:id');
			$viNode->removeAttribute('xml:id');
			$viNode->setAttribute('id',$id);
			$mask = $viNode->getElementsByTagName('mask')->item(0)->nodeValue;
			$viNode->setAttribute('format', $fileFormat[$mask]);
d95e8421   Elena.Budnik   ws transfer : ini...
568
569
570
		}
		
		$BaseXml->save(NEWUSERPATH.TRANSFERUSER.'/DATA/base.xml');
de5d1909   Elena.Budnik   message corrected
571
572
573
		
		$msg .= 'Not copied files :<br/>';
		
d95e8421   Elena.Budnik   ws transfer : ini...
574
575
576
		$filesNodes = $FilesXml->getElementsByTagName('file');
		foreach ($filesNodes as $file) {
			$fileName = $file->getAttribute('name');
cdf22cdd   Elena.Budnik   message window co...
577
578
579
580
581
			$format = $file->getAttribute('format');
			if ($format == 'cef') {
				$deletedFiles[] = $file->getAttribute('xml:id');
			}
			else {
de5d1909   Elena.Budnik   message corrected
582
583
				if (!@copy(OLDUSERPATH.TRANSFERUSER.'/DATA/'.$fileName,NEWUSERPATH.TRANSFERUSER.'/DATA/'.$fileName))
					$msg .= $fileName.'<br/>'; 
d95e8421   Elena.Budnik   ws transfer : ini...
584
585
			}
		}
77237fff   Elena.Budnik   if ws param was a...
586
		
de5d1909   Elena.Budnik   message corrected
587
		if (count($deletedVi) > 0) 
77237fff   Elena.Budnik   if ws param was a...
588
			foreach ($deletedVi as $vi) {
fa5e7074   Elena.Budnik   bug in files tran...
589
590
				$node = $BaseXml->getElementById($vi);
				if ($node) {
77237fff   Elena.Budnik   if ws param was a...
591
					$node->parentNode->removeChild($node);
fa5e7074   Elena.Budnik   bug in files tran...
592
				}
77237fff   Elena.Budnik   if ws param was a...
593
			}
de5d1909   Elena.Budnik   message corrected
594
		 
77237fff   Elena.Budnik   if ws param was a...
595
596
597
598
599
600
601
602
      
		if (count($deletedFiles) > 0)
			foreach ($deletedFiles as $vi) {
				$node = $FilesXml->getElementById($vi);
				if ($node) {
					$msg .= '<li><i>'.$vi.'</i> <br/>';
					$node->parentNode->removeChild($node);
				}
cdf22cdd   Elena.Budnik   message window co...
603
			}
cdf22cdd   Elena.Budnik   message window co...
604

d95e8421   Elena.Budnik   ws transfer : ini...
605
		$FilesXml->save($this->newWsDir.'Files.xml');
d95e8421   Elena.Budnik   ws transfer : ini...
606
607
608
609
610
611

		return array('success' => true, 'msg' => $msg);
	} 
	
	public function transferFilters() 
	{
adcf0710   Elena.Budnik   message for WS co...
612
		$msg = '<hr><br/><br/><b><i>Filters:</i></b><br/><br/>'; 
d95e8421   Elena.Budnik   ws transfer : ini...
613
614
615
616
617
618
619
620
621
622
623
		
		if (!curl_init($this->oldWsDir.'Filters.xml')) {
				return array('success' => true, 'msg' => 'No filters at old AMDA');
		}
		
		$filterXml = new DomDocument("1.0");
		if (!$filterXml->load($this->oldWsDir.'Filters.xml')) {
			return array('success' => false, 'error' => 'Cannot load filters from old AMDA');
		}
	    
	   $filterXml->save($this->newWsDir.'Filters.xml');
6a449df8   Elena.Budnik   message format
624
625
	   $msg .= 'Filters have been copied</br>';
		return array('success' => true, 'msg' => $msg);
d95e8421   Elena.Budnik   ws transfer : ini...
626
	}
bcb4c408   Elena.Budnik   send mail for cop...
627
628
629
630
631
632
633
634
	
	function sendMail($email, $msg)
	{
		$subject = 'Your workspace has been copied to new AMDA';
		
		$headers = "From: amda@irap.omp.eu " . "\r\n".
						"Reply-To: amda@irap.omp.eu " . "\r\n".
						"Content-type: text/html\r\n";
c66fd5de   Elena.Budnik   typo
635
	   $msg = "<html><b>Your Workspace has been copied to new AMDA</b><br/><br/>".$msg."</html>";
bcb4c408   Elena.Budnik   send mail for cop...
636
637
		mail($email, $subject, $msg, $headers);
	}
16035364   Benjamin Renard   First commit
638
}
981cd087   Elena.Budnik   ws transfer modifs
639
?>