Blame view

php/RemoteDataCenter/getRemoteDDBaseProxies.php 2.68 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
<?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")) {
05961422   Elena.Budnik   permissions on dirs
19
			if (!is_dir(DATAPATH."/RemoteData")) mkdir(DATAPATH."/RemoteData", 0775, true);
d444ba30   Elena.Budnik   mkdir...,0775 doe...
20
			chmod(DATAPATH."/RemoteData",0775);
fd2b603f   Elena.Budnik   Bases.xml are in ...
21
22
23
			echo 'No Bases.xml file : Will use Bases.xml from DDBase'.PHP_EOL;
			$basesDom = new DomDocument("1.0");
			
b7741da9   Benjamin Renard   Define DDService ...
24
			if (!@$basesDom->load(DDSERVICE."/BASE/INFO/Bases.xml"))
fd2b603f   Elena.Budnik   Bases.xml are in ...
25
26
27
28
29
30
31
					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";
b7741da9   Benjamin Renard   Define DDService ...
32
				$baseDirRemote = DDSERVICE."/BASE/INFO/bases/$baseId";
05961422   Elena.Budnik   permissions on dirs
33
				if (!is_dir($baseDir)) mkdir($baseDir, 0775, true);
d444ba30   Elena.Budnik   mkdir...,0775 doe...
34
				chmod($baseDir,0775);
fd2b603f   Elena.Budnik   Bases.xml are in ...
35
36
37
38
39
40
41
42
43
44
				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");
b7741da9   Benjamin Renard   Define DDService ...
45
		if (!@$basesDomRemote->load(DDSERVICE."/BASE/INFO/Bases.xml"))
fd2b603f   Elena.Budnik   Bases.xml are in ...
46
47
48
					exit("No Bases.xml file at DDBase/INFO ? IMPEX only".PHP_EOL);
					
		$basesRemote = $basesDomRemote->getElementsByTagName("dataCenter");	
fd2b603f   Elena.Budnik   Bases.xml are in ...
49
		foreach ($basesRemote as $baseRemote) {
41fbf0bd   Elena.Budnik   copy base.xml, up...
50
		
fd2b603f   Elena.Budnik   Bases.xml are in ...
51
			$baseId = $baseRemote->getAttribute("xml:id");
41fbf0bd   Elena.Budnik   copy base.xml, up...
52
53
54
			$baseDir = DATAPATH."/RemoteData/$baseId";
			$baseDirRemote = DDSERVICE."/BASE/INFO/bases/$baseId";
			
fd2b603f   Elena.Budnik   Bases.xml are in ...
55
56
			// add remote base if it doesn't exist
			if (!$basesDom->getElementById($baseId)) {
78b305f1   Furkan   For now
57
				echo $baseDir;
05961422   Elena.Budnik   permissions on dirs
58
				if (!is_dir($baseDir)) mkdir($baseDir, 0775, true);
d444ba30   Elena.Budnik   mkdir...,0775 doe...
59
				chmod($baseDir,0775);
c6c2f576   Elena.Budnik   Update Remote Bases
60
61
62
63
64
65
66
				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;
78b305f1   Furkan   For now
67
68
					if ($baseId == "THEMIS"  || $baseId == "SPEASY_CDAWEB") {
						$center = new $baseId();
c6c2f576   Elena.Budnik   Update Remote Bases
69
70
71
						$center->makeAllParams();
					}
				}
41fbf0bd   Elena.Budnik   copy base.xml, up...
72
73
74
75
76
77
78
79
			}// just copy base xml
			else {
				if (!copy("$baseDirRemote/base.xml", "$baseDir/base.xml")) {
						echo "Cannot copy base.xml for $baseId".PHP_EOL;
				}
				else {
						echo "Copied base.xml for $baseId".PHP_EOL;
				}
fd2b603f   Elena.Budnik   Bases.xml are in ...
80
81
82
83
84
85
			}
		}
	}
	
	$basesDom->save(DATAPATH."/RemoteData/Bases.xml");
	
b7741da9   Benjamin Renard   Define DDService ...
86
?>