getRemoteDDBaseProxies.php
2.63 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
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
<?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")) {
if (!is_dir(DATAPATH."/RemoteData")) mkdir(DATAPATH."/RemoteData", 0775, true);
chmod(DATAPATH."/RemoteData",0775);
echo 'No Bases.xml file : Will use Bases.xml from DDBase'.PHP_EOL;
$basesDom = new DomDocument("1.0");
if (!@$basesDom->load(DDSERVICE."/BASE/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 = DDSERVICE."/BASE/INFO/bases/$baseId";
if (!is_dir($baseDir)) mkdir($baseDir, 0775, true);
chmod($baseDir,0775);
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(DDSERVICE."/BASE/INFO/Bases.xml"))
exit("No Bases.xml file at DDBase/INFO ? IMPEX only".PHP_EOL);
$basesRemote = $basesDomRemote->getElementsByTagName("dataCenter");
foreach ($basesRemote as $baseRemote) {
$baseId = $baseRemote->getAttribute("xml:id");
$baseDir = DATAPATH."/RemoteData/$baseId";
$baseDirRemote = DDSERVICE."/BASE/INFO/bases/$baseId";
// add remote base if it doesn't exist
if (!$basesDom->getElementById($baseId)) {
if (!is_dir($baseDir)) mkdir($baseDir, 0775, true);
chmod($baseDir,0775);
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();
}
}
}// 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;
}
}
}
}
$basesDom->save(DATAPATH."/RemoteData/Bases.xml");
?>