Blame view

php/RemoteDataCenter/getRemoteDDBaseProxies.php 2.21 KB
fd2b603f   Elena.Budnik   Bases.xml are in ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
46
47
<?php
/*
*  Executable to get Remote Bases description from DDBase 
*  and Merge with AMDA side Bases
*/

	if (!function_exists('__autoload')) {
		function __autoload($class_name) {
					require_once $class_name . '.php';
		}
	}
	
	$AMDA_IHM = getenv('AMDA_IHM');
     
	require_once $AMDA_IHM."/php/config.php"; 
	
	// only "DDBASE" Bases.xml
	if (!file_exists(DATAPATH."/RemoteData/Bases.xml")) {
			echo 'No Bases.xml file : Will use Bases.xml from DDBase'.PHP_EOL;
			$basesDom = new DomDocument("1.0");
			
			if (!@$basesDom->load(INFOSITE."INFO/Bases.xml"))
					exit("No Bases.xml file at DDBase/INFO ? no Remote bases at all".PHP_EOL);
					
			$bases = $basesDom->getElementsByTagName("dataCenter");		
			foreach ($bases as $base) {
				$baseId = $base->getAttribute("xml:id");
				
				$baseDir = DATAPATH."/RemoteData/$baseId";
				$baseDirRemote = INFOSITE."INFO/bases/$baseId";
				
				if (!is_dir($baseDir)) mkdir($baseDir);
				
				if (!copy("$baseDirRemote/base.xml", "$baseDir/base.xml"))
					echo "Cannot copy base.xml for $baseId".PHP_EOL;
			}
	}
	// Merge with existing Bases.xml
	else { 
		$basesDom = new DomDocument("1.0");
		$basesDom->load(DATAPATH."/RemoteData/Bases.xml");
		
		$basesDomRemote =  new DomDocument("1.0");
		if (!@$basesDomRemote->load(INFOSITE."INFO/Bases.xml"))
					exit("No Bases.xml file at DDBase/INFO ? IMPEX only".PHP_EOL);
					
		$basesRemote = $basesDomRemote->getElementsByTagName("dataCenter");	
c6c2f576   Elena.Budnik   Update Remote Bases
48
		echo INFOSITE.PHP_EOL;
fd2b603f   Elena.Budnik   Bases.xml are in ...
49
50
		foreach ($basesRemote as $baseRemote) {
			$baseId = $baseRemote->getAttribute("xml:id");
c6c2f576   Elena.Budnik   Update Remote Bases
51

fd2b603f   Elena.Budnik   Bases.xml are in ...
52
53
			// add remote base if it doesn't exist
			if (!$basesDom->getElementById($baseId)) {
fd2b603f   Elena.Budnik   Bases.xml are in ...
54
55
56
				$baseDir = DATAPATH."/RemoteData/$baseId";
				$baseDirRemote = INFOSITE."INFO/bases/$baseId";
				if (!is_dir($baseDir)) mkdir($baseDir);
c6c2f576   Elena.Budnik   Update Remote Bases
57
58
59
60
61
62
63
64
65
66
67
68
				if (!copy("$baseDirRemote/base.xml", "$baseDir/base.xml")) {
						echo "Cannot copy base.xml for $baseId".PHP_EOL;
				}
				else {
					$baseClone = $basesDom->importNode($baseRemote);
					$basesDom->documentElement->appendChild($baseClone);
					echo "Added $baseId".PHP_EOL;
					if ($baseId == "THEMIS") {
						$center = new THEMIS();
						$center->makeAllParams();
					}
				}
fd2b603f   Elena.Budnik   Bases.xml are in ...
69
70
71
72
73
74
75
			}
		}
	}
	
	$basesDom->save(DATAPATH."/RemoteData/Bases.xml");
	
?>