Blame view

update_amda/makeTree.php 4.1 KB
4c77b9b1   Elena.Budnik   final update
1
2
3
4
<?php
 
 /*
 *  make local data tree from list of missions 
329f027c   Elena.Budnik   updateAmda error-...
5
 */ 
4c77b9b1   Elena.Budnik   final update
6
 
329f027c   Elena.Budnik   updateAmda error-...
7
   error_reporting(E_ERROR);
4c77b9b1   Elena.Budnik   final update
8
	
f8315d1b   Elena.Budnik   modif env vars ac...
9
	if (getenv("AMDA_SPASE_INTERFACE") === false) 
4c77b9b1   Elena.Budnik   final update
10
11
		require_once("./config.php");
	else
f8315d1b   Elena.Budnik   modif env vars ac...
12
13
14
15
		require_once(getenv("AMDA_SPASE_INTERFACE")."/config.php");

	if (getenv("DATAPATH") !== false && file_exists(getenv("DATAPATH")."rank.json")) 
		$cmpArr = json_decode(file_get_contents(getenv("DATAPATH")."rank.json"), true);
4c77b9b1   Elena.Budnik   final update
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
	else 
		$cmpArr = null;
                               
	$ddMission = new DomDocument("1.0");
	
	$localDom  = new DomDocument("1.0");
	$localDom->formatOutput = true;

	$BASE = $localDom->createElement('dataRoot'); 
	$BASE->setAttribute('xml:id', 'DATAROOT');
	$Amda = $localDom->createElement('dataCenter');
	$Amda->setAttribute('name', 'AMDA');
	$Amda->setAttribute('desc', 'AMDA_Internal_Data_Base');          
	$Amda->setAttribute('xml:id', 'myLocalData-treeRootNode');

	foreach ( glob(AMDATREEDIR.'DD_*.xml') as $xml ) 
	{              													
		$ddMission->load($xml);
		$missions = $ddMission->getElementsByTagName("mission");
		foreach ($missions as $mission) 
		{
			if ($mission->getAttribute('xml:id') == '') continue;
			$nodeNew = $localDom->importNode($mission,true);
                     
			if (is_array($cmpArr)) 
			{
4d810571   Elena.Budnik   add rank for Ephe...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
				if ($mission->getAttribute('xml:id') == 'Ephemerides') { // Planets and Moons
                    $datasets = $nodeNew->getElementsByTagName('dataset');
                    foreach ($datasets as $ds ) {
                        $target = $ds->getAttribute('target');
                        $index = $cmpArr[$target];
                        if ($index) { 
                            if ( $ds->parentNode->tagName == 'datasetGroup' ) {
                                 if (!$ds->parentNode->hasAttribute('rank')) {
                                    $ds->parentNode->setAttribute('rank',$index);
                                 }
                            } else {
                                $ds->setAttribute('rank',$index);
                            }
                        }
                    }
4c77b9b1   Elena.Budnik   final update
57
				}
4d810571   Elena.Budnik   add rank for Ephe...
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
86
87
				else if ($mission->getAttribute('xml:id') == 'PlanetsProperties') { 
                    $instruments = $nodeNew->getElementsByTagName('instrument');
                    foreach ($instruments as $ins ) {
                        $target = $ins->getAttribute('name');
                        $index = $cmpArr[$target];
                        if ($index)  
                            $ins->setAttribute('rank',$index);
                    }
				}
 
                $targetMis = $mission->getAttribute('target');
                $index = $cmpArr[$targetMis];
                if ($index)  
                        $nodeNew->setAttribute('rank',$index);
                else $nodeNew->setAttribute('rank', 999);
                
                $observatories = $nodeNew->getElementsByTagName('observatory');
                if ($observatories->length > 0)
                {
                    foreach ($observatories as $obs)
                    {
                        if ($obs->hasAttribute('target'))
                        {
                            $target = $obs->getAttribute('target');
                            $index = $cmpArr[$target];
                            if ($index  &&  $target != $targetMis)
                                    $obs->setAttribute('rank',$index);											
                        }
                    }
                }
4c77b9b1   Elena.Budnik   final update
88
89
			}
			//TODO set propre restriction 
4c77b9b1   Elena.Budnik   final update
90
91
92
93
94
95
96
97
98
			$Amda->appendChild($nodeNew); 
		} 
	}                  
                                    
	if ($Amda->hasChildNodes()) $BASE->appendChild($Amda);             
	$localDom->appendChild($BASE);

	// check ID duplication                        
	$allIds = array();
5656c46b   Nathanael Jourdane   Check for id on e...
99
	/** @var DOMElement $element */
df396235   Elena.Budnik   remove obsolete test
100
	foreach($localDom->getElementsByTagName('*') as $element)
5656c46b   Nathanael Jourdane   Check for id on e...
101
102
103
104
105
106
	{
		$id = $element->getAttribute('xml:id');
		$allIds[] = $id;
		if (!$id) {
			echo 'No id in node ' . $element->tagName . PHP_EOL;
		}
4c77b9b1   Elena.Budnik   final update
107
108
109
	}
	$arr = array_count_values($allIds);

5656c46b   Nathanael Jourdane   Check for id on e...
110
111
112
	foreach ($arr as $key => $value) {
		if ($value > 1) print_r("id '$key' is duplicated $value times." . PHP_EOL);
	}
df396235   Elena.Budnik   remove obsolete test
113
          
4c77b9b1   Elena.Budnik   final update
114
115
	$localDom->save('LocalParams.xml');  
?>