getRemoteDDBaseProxies.php 2.04 KB
<?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");	
		
		foreach ($basesRemote as $baseRemote) {
			$baseId = $baseRemote->getAttribute("xml:id");
			// add remote base if it doesn't exist
			if (!$basesDom->getElementById($baseId)) {
				$baseClone = $basesDom->importNode($baseRemote);
				$basesDom->documentElement->appendChild($baseClone);
				$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;	
			}
		}
	}
	
	$basesDom->save(DATAPATH."/RemoteData/Bases.xml");
	
?>