Blame view

php/classes/UserWsTransfer.php 16.6 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
10
	private $oldWs, $newWs, $Mgr;
	private $oldWsDir, $newWsDir;
	private $ws_deleted, $wsd_deleted, $pairs;
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
		
		$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();
	}
	
	private function getObsolete() {
	
		$deletedXML = new DomDocument("1.0");
		$deletedXML->load(CONVERSIONDIR."Deleted.xml"); 
		$deletedNodes = $deletedXML->getElementsByTagName('deleted');
		
		$deleted = array();
		foreach ($deletedNodes as $node)
			$deleted[] = $node->getAttribute('xml:id');
		
		return $deleted;
	}
cdf22cdd   Elena.Budnik   message window co...
46
47
48
49
50
51
52
53
54
55
	
	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...
56
		
cdf22cdd   Elena.Budnik   message window co...
57
58
59
		return $notready;
	}
	
d95e8421   Elena.Budnik   ws transfer : ini...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	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;
						
		foreach ($deleted as $item) {
			if (strpos($exp, $item) !== false)  {
				$toDelete = true;
				break;
			}
		}

		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
103
       
d95e8421   Elena.Budnik   ws transfer : ini...
104
105
106
       $delimiter = '[]+,/*()^<>&|=[-]+';    
       $array = split($delimiter,$chain);
       if (trim(end($array)) == "") array_pop($array);
16035364   Benjamin Renard   First commit
107

d95e8421   Elena.Budnik   ws transfer : ini...
108
109
       return $array;
   }
16035364   Benjamin Renard   First commit
110
   
d95e8421   Elena.Budnik   ws transfer : ini...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	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;
	}
	
	private function updateParams($expression)
	{
		$newExp = strtr($expression, $this->pairs);
		$expression = $newExp;

		return $expression;
	}
	
	//duplication of FilesMgr method
	public function getSampling($fileName, $format) {

		if ($format === 'cdf') {
				copy($fileName, "temp.cdf");         
				exec('cdfsamplingfromdata ', $result); 
				unlink("temp.cdf");
				$minSamp = $result[count($result)-1]; 
			}
		else if ($format === 'cef') {
				exec('cefsampling '.$fileName, $result); 
				$minSamp = $result[count($result)-1];
			}
			else $minSamp = null;
	//TODO if min & max                           
				return $minSamp;
	}

	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);
	//	$this->newWs->save($this->newWsDir.'WsParams.xml');
	}
	
		public function checkWS() 
	{
		// old ws        
		if (!curl_init(OLDUSERPATH.TRANSFERUSER)) {
				error_log('no  '.TRANSFERUSER.' at old AMDA',1,email);
				return array('success' => false, 'error' => 'Sorry, it seems you have no account at old AMDA');
		}

		if (!curl_init($this->oldWsDir)) {
			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() 
	{
6a449df8   Elena.Budnik   message format
190
191
		$msg = '<br/><b><i>Derived Params:</i></b><br/><br/>';
		$msg .= '<i>Note</i> : Parameters made from Remote Base parameters are not copied <br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
192
193
		if (!$this->oldWs->load($this->oldWsDir.'WsParams.xml')) {
			error_log('cannot load WsParams.xml for '.TRANSFERUSER,1,email);
6a449df8   Elena.Budnik   message format
194
			return array('success' => false, 'error' => 'Sorry, we failed to get your Derived Params from old AMDA');
d95e8421   Elena.Budnik   ws transfer : ini...
195
196
197
198
199
200
201
202
203
		}

		if (!file_exists($this->newWsDir.'WsParams.xml'))
						$this->createDom();
		else 
			$this->newWs->load($this->newWsDir.'WsParams.xml');
		
		$deleted = $this->getObsolete();
		$notready = $this->getNotready();
cdf22cdd   Elena.Budnik   message window co...
204
		$notreadyFunctions = $this->getNotreadyFunctions();
d95e8421   Elena.Budnik   ws transfer : ini...
205
206
207
208
209
210
211
212
213
214
		
	   $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");
6a449df8   Elena.Budnik   message format
215
		$msg .= 'Not copied derived parameters :<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
216
217
218
219
220
221
222
223
		
		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
224
						$msg .= '<li><i>'.$name.'</i> : uses obsolete param<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
225
226
227
228
229
230
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
			
			if ($this->deleteParam($expression,$notready)) {
6a449df8   Elena.Budnik   message format
231
						$msg .= '<li><i>'.$name.'</i> : uses param not ready yet <br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
232
233
234
235
236
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
			
cdf22cdd   Elena.Budnik   message window co...
237
			if ($this->deleteParam($expression,$notreadyFunctions)) {
6a449df8   Elena.Budnik   message format
238
						$msg .= '<li><i>'.$name.'</i> : uses function not ready yet <br/> '.$expression.'<br/>';
cdf22cdd   Elena.Budnik   message window co...
239
240
241
242
243
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
			
d95e8421   Elena.Budnik   ws transfer : ini...
244
245
			if (!empty($this->wsd_deleted))
					if ($this->deleteParam($expression,$this->wsd_deleted)) {
6a449df8   Elena.Budnik   message format
246
						$msg .= '<li><i>'.$name.'</i> : uses obsolete myData param<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
247
248
249
250
251
252
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$this->ws_deleted[] = $name;
						continue;
			}
			
			if ($this->deleteParam($expression,array("CDAWEB","MAPSKP","VEXGRAZ","IMPEX"))) {
6a449df8   Elena.Budnik   message format
253
						$msg .= '<li><i>'.$name.'</i> : uses remote params <br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
						$this->ws_deleted[] = $name;
						continue;
			}
			
			$expressionUpdated = $this->updateParams($expression);
			$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');
		}
		
		// 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) {
						unlink($this->newWsDir.$id.'.xml');
						$paramsToRemove[] = $param; 
						$this->ws_deleted[] = $name;
6a449df8   Elena.Budnik   message format
284
						$msg .= '<li><i>'.$name.'</i> : uses obsolete / not ready ws param : <br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
285
286
287
288
289
290
291
292
293
294
295
296
					}
				}
			}
		}
		
		foreach ($paramsToRemove as $paramToRemove) {
			$paramToRemove->parentNode->removeChild($paramToRemove);
		}
		
		$this->newWs->save($this->newWsDir.'WsParams.xml');
		$copied = $newParams->length - count($paramsToRemove);
		
6a449df8   Elena.Budnik   message format
297
		$msg .= '<br/><i>Copied : </i>'.$copied.' derived parameters<br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
298
299
300
301
302
		return array('success' => true, 'msg' => $msg);
	}

	public function transferTimeTables() 
	{    
6a449df8   Elena.Budnik   message format
303
		$msg = '<b><i>Time Tables:</i></b><br/><br/>'; 
d95e8421   Elena.Budnik   ws transfer : ini...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
		
		// 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');
6a449df8   Elena.Budnik   message format
321
		$msg .= '<i>Copied : </i>'.$timeTabs->length.' time tables<br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
322
323
		return array('success' => true, 'msg' => $msg);
	}
16035364   Benjamin Renard   First commit
324
 
d95e8421   Elena.Budnik   ws transfer : ini...
325
326
	public function transferConditions() 
	{
6a449df8   Elena.Budnik   message format
327
328
		$msg = '<b><i>Requests</i></b><br/><br/>';
		$msg .= '<i>Note :</i> Plot requests are not copied : too much difference new-old AMDA<br/<br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
329
330
331
332
		$oldRequestXml = new DomDocument("1.0");
		$newRequestXml = new DomDocument("1.0");
		
		if (!$oldRequestXml->load($this->oldWsDir.'Request.xml')){
6a449df8   Elena.Budnik   message format
333
			$msg .= ' No Requests File<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
			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);
		}
		$newRequestXml->load($this->newWsDir.'Request.xml');
		$conditionRoot = $newRequestXml->getElementsByTagName('conditionList')->item(0);
		
		$condDir = OLDUSERPATH.TRANSFERUSER."/REQ/";
		
		$deleted = $this->getObsolete();
		$notready = $this->getNotready();
6a449df8   Elena.Budnik   message format
349
		$msg .= 'Not copied DataMining requests :<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
350
351
352
353
354
355
356
357
358
		
		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)) {
6a449df8   Elena.Budnik   message format
359
						$msg .= '<li><i>'.$name.'</i> : uses obsolete param<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
360
361
362
363
364
						$cond_deleted[] = $name;
 						continue;
 			}
 			
 			if ($this->deleteParam($expression,$notready)) {
6a449df8   Elena.Budnik   message format
365
						$msg .= '<li><i>'.$name.'</i> : uses param not ready yet<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
366
367
368
369
370
371
372
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$cond_deleted[] = $name;
						continue;
			}
			
			if (!empty($this->wsd_deleted))
					if ($this->deleteParam($expression,$this->wsd_deleted)) {
6a449df8   Elena.Budnik   message format
373
						$msg .= '<li><i>'.$name.'</i> : uses obsolete myData param<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
374
375
376
377
378
379
380
					// error_log( 'For INFO : DELETED '.$expression,1,email);
						$cond_deleted[] = $name;
						continue;
			}
			
			if (!empty($this->ws_deleted))
					if ($this->deleteParam($expression,$this->ws_deleted)) {
6a449df8   Elena.Budnik   message format
381
						$msg .= '<li><i>'.$name.'</i> : uses obsolete drived param<br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
382
383
384
385
386
387
					// 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
388
						$msg .= '<li><i>'.$name.'</i> : uses remote params <br/> '.$expression.'<br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
389
390
391
392
393
394
395
396
397
398
399
						$cond_deleted[] = $name;
						continue;
			}
			
			$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...
400
401
402

		return array('success' => true, 'msg' => $msg);
	}
16035364   Benjamin Renard   First commit
403
  
d95e8421   Elena.Budnik   ws transfer : ini...
404
405
	public function transferMyData() 
	{
6a449df8   Elena.Budnik   message format
406
407
		$msg = '<b><i>MyData Parameters / My Files:</i></b><br/><br/>';
		$msg.= '<i>Note :</i> CEF format is not implemented<br/><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
		
		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
426
				return array('success' => true, 'msg' => 'You have no MyData parameters');
d95e8421   Elena.Budnik   ws transfer : ini...
427
428
429
430
431
432
433
434
435
436
437
438
		}
		
		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
439
440
     
      $msg.= ' Not copied parameters : <br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
441
442
443
444
445
446
447
		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
448
				$msg .= '<li><i>'.$name.'</i><br/>';
d95e8421   Elena.Budnik   ws transfer : ini...
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
				$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...
467

d95e8421   Elena.Budnik   ws transfer : ini...
468
469
470
471
472
473
474
475
476
477
		$this->newWs->save($this->newWsDir.'WsParams.xml');
		
		// First delete CEF files
		$xpBase = new domxpath($BaseXml);
		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;
d95e8421   Elena.Budnik   ws transfer : ini...
478
479
480
481
482
483
484
485
486
487
488
				$viNode->parentNode->removeChild($viNode);
			}
		}
		// 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...
489
490
491
		}
		
		$BaseXml->save(NEWUSERPATH.TRANSFERUSER.'/DATA/base.xml');
cdf22cdd   Elena.Budnik   message window co...
492

d95e8421   Elena.Budnik   ws transfer : ini...
493
494
495
		$filesNodes = $FilesXml->getElementsByTagName('file');
		foreach ($filesNodes as $file) {
			$fileName = $file->getAttribute('name');
cdf22cdd   Elena.Budnik   message window co...
496
497
498
499
500
			$format = $file->getAttribute('format');
			if ($format == 'cef') {
				$deletedFiles[] = $file->getAttribute('xml:id');
			}
			else {
d95e8421   Elena.Budnik   ws transfer : ini...
501
502
503
504
505
506
507
508
509
				copy(OLDUSERPATH.TRANSFERUSER.'/DATA/'.$fileName,NEWUSERPATH.TRANSFERUSER.'/DATA/'.$fileName);
			}
		}
		 
		foreach ($deletedVi as $vi) {
			$node = $FilesXml->getElementById($vi);
			if ($node)
				$node->parentNode->removeChild($node);
		}
6a449df8   Elena.Budnik   message format
510
      $msg .= 'Not copied files :<br/>';
cdf22cdd   Elena.Budnik   message window co...
511
512
513
		foreach ($deletedFiles as $vi) {
			$node = $FilesXml->getElementById($vi);
			if ($node) {
6a449df8   Elena.Budnik   message format
514
				$msg .= '<li><i>'.$vi.'</i> <br/>';
cdf22cdd   Elena.Budnik   message window co...
515
516
517
518
				$node->parentNode->removeChild($node);
			}
		}

d95e8421   Elena.Budnik   ws transfer : ini...
519
		$FilesXml->save($this->newWsDir.'Files.xml');
d95e8421   Elena.Budnik   ws transfer : ini...
520
521
522
523
524
525

		return array('success' => true, 'msg' => $msg);
	} 
	
	public function transferFilters() 
	{
6a449df8   Elena.Budnik   message format
526
		$msg = '<br/><br/><b><i>Filters:</i></b><br/><br/>'; 
d95e8421   Elena.Budnik   ws transfer : ini...
527
528
529
530
531
532
533
534
535
536
537
		
		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
538
539
	   $msg .= 'Filters have been copied</br>';
		return array('success' => true, 'msg' => $msg);
d95e8421   Elena.Budnik   ws transfer : ini...
540
	}
16035364   Benjamin Renard   First commit
541
542
}
?>